summaryrefslogtreecommitdiff
path: root/lib/compiler/codelisting.tcl
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
committerAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
commit47aa8b00b2b11df13a100489e0f904a4947177ef (patch)
treeb35c9acc778ea2f761f3c549f7bee2f4491b3144 /lib/compiler/codelisting.tcl
parent5b8466f7fae0e071c0f4eda13051c93313910028 (diff)
Import Upstream version 1.4.7
Diffstat (limited to 'lib/compiler/codelisting.tcl')
-rw-r--r--[-rwxr-xr-x]lib/compiler/codelisting.tcl210
1 files changed, 114 insertions, 96 deletions
diff --git a/lib/compiler/codelisting.tcl b/lib/compiler/codelisting.tcl
index 1940dc3..a760d4c 100755..100644
--- a/lib/compiler/codelisting.tcl
+++ b/lib/compiler/codelisting.tcl
@@ -2,7 +2,7 @@
# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
############################################################################
-# Copyright (C) 2007-2009 by Martin Ošmera #
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
@@ -21,6 +21,11 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _CODELISTING_TCL ] } {
+set _CODELISTING_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Hepler namespace to generate code listing.
@@ -68,42 +73,42 @@ namespace eval CodeListing {
set pageLines 0
# Validate compiler settings
- if {${Compiler::Settings::PAGELENGTH} < 5} {
+ if {${::Compiler::Settings::PAGELENGTH} < 5} {
set Compiler::Settings::PAGELENGTH 5
- } elseif {${Compiler::Settings::PAGELENGTH} == 0} {
+ } elseif {${::Compiler::Settings::PAGELENGTH} == 0} {
set Compiler::Settings::PAGING 0
}
- if {${Compiler::Settings::PAGEWIDTH} < 68} {
+ if {${::Compiler::Settings::PAGEWIDTH} < 68} {
set Compiler::Settings::PAGEWIDTH 68
- } elseif {${Compiler::Settings::PAGEWIDTH} == 0} {
+ } elseif {${::Compiler::Settings::PAGEWIDTH} == 0} {
set Compiler::Settings::PAGEWIDTH 116
}
# Create page header
- set header ${Compiler::Settings::INPUT_FILE_NAME}
- set len [string length ${Compiler::Settings::INPUT_FILE_NAME}]
+ set header ${::Compiler::Settings::INPUT_FILE_NAME}
+ set len [string length ${::Compiler::Settings::INPUT_FILE_NAME}]
if {$len < 15} {
append header [string repeat { } [expr {15 - $len}]]
}
- append header { } ${Compiler::Settings::TITLE}
+ append header { } ${::Compiler::Settings::TITLE}
set len [string length $header]
incr len 23
# Adjust page header width
- if {$len > ${Compiler::Settings::PAGEWIDTH}} {
- set header [string range $header 0 [expr {${Compiler::Settings::PAGEWIDTH} - 24}]]
+ if {$len > ${::Compiler::Settings::PAGEWIDTH}} {
+ set header [string range $header 0 [expr {${::Compiler::Settings::PAGEWIDTH} - 24}]]
append header {... }
- } elseif {$len < ${Compiler::Settings::PAGEWIDTH}} {
- set len [expr {${Compiler::Settings::PAGEWIDTH} - $len}]
+ } elseif {$len < ${::Compiler::Settings::PAGEWIDTH}} {
+ set len [expr {${::Compiler::Settings::PAGEWIDTH} - $len}]
append header [string repeat { } $len]
}
# Create date
- set len [string length ${Compiler::Settings::DATE}]
+ set len [string length ${::Compiler::Settings::DATE}]
if {$len > 10} {
- set Compiler::Settings::DATE [string range 0 7 ${Compiler::Settings::DATE}]
+ set Compiler::Settings::DATE [string range 0 7 ${::Compiler::Settings::DATE}]
append Compiler::Settings::DATE {...}
} elseif {$len < 10} {
@@ -111,11 +116,11 @@ namespace eval CodeListing {
append Compiler::Settings::DATE [string repeat { } $len]
}
- append header ${Compiler::Settings::DATE} { PAGE}
+ append header ${::Compiler::Settings::DATE} { PAGE}
# Create error summary and symbol table
create_error_summary
- if {${Compiler::Settings::SYMBOLS}} {
+ if {${::Compiler::Settings::SYMBOLS}} {
create_symbol_table
}
@@ -129,7 +134,7 @@ namespace eval CodeListing {
append lst ", 1 ERROR FOUND"
} elseif {$errors_count > 1} {
append lst ", $errors_count ERRORS FOUND"
- } {
+ } else {
append lst ", NO ERRORS FOUND"
}
@@ -137,7 +142,7 @@ namespace eval CodeListing {
append lst ", 1 WARNING"
} elseif {$warnings_count > 1} {
append lst ", $warnings_count WARNINGS"
- } {
+ } else {
append lst ", NO WARNINGS"
}
@@ -151,7 +156,7 @@ namespace eval CodeListing {
}
# Symbol table
- if {${Compiler::Settings::SYMBOLS}} {
+ if {${::Compiler::Settings::SYMBOLS}} {
append lst "\n\n"
append lst $symbol_table
}
@@ -168,14 +173,14 @@ namespace eval CodeListing {
## Directive LIST
# @access public
- # @parm Int idx - index where the directive occured
+ # @parm Int idx - index where the directive occurred
# @return void
proc directive_list {idx} {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
- if {${Compiler::Settings::_list} != 0} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
+ if {${::Compiler::Settings::_list} != 0} {return}
# Adjust code listing
set idx [getIdx $idx]
@@ -185,14 +190,14 @@ namespace eval CodeListing {
## Directive NOLIST
# @access public
- # @parm Int idx - index where the directive occured
+ # @parm Int idx - index where the directive occurred
# @return void
proc directive_nolist {idx} {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
- if {${Compiler::Settings::_list} != 0} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
+ if {${::Compiler::Settings::_list} != 0} {return}
# Adjust code listing
set idx [getIdx $idx]
@@ -224,7 +229,7 @@ namespace eval CodeListing {
# @return void
proc create_listing {data} {
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
variable lst ;# Resulting LST code
variable sync_map ;# Map of lines in code listing
@@ -255,8 +260,8 @@ namespace eval CodeListing {
variable symbol_table ;# Table of symbolic names
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
- if {!${Compiler::Settings::SYMBOLS}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::SYMBOLS}} {return}
# Iterate over definition ists and write them to the table
foreach def_list {
@@ -271,14 +276,14 @@ namespace eval CodeListing {
} char {
B C D I
X C N S
- } {
-
+ } \
+ {
# Get list of defined names
- set def_list [subst "\$PreProcessor::$def_list"]
+ set def_list [subst -nocommands "\$PreProcessor::$def_list"]
# Write defined names to the table
foreach var $def_list {
- set value [subst "\$PreProcessor::${val_array}($var)"]
+ set value [subst -nocommands "\$PreProcessor::${val_array}($var)"]
# Handle special constants
if {$char == {S}} {
@@ -290,7 +295,7 @@ namespace eval CodeListing {
1 0]
# Other constants ...
- } {
+ } else {
lappend symbol_table [list \
[string toupper $var] \
$char \
@@ -302,14 +307,14 @@ namespace eval CodeListing {
}
# Write defined variables (directive "SET")
- foreach var ${PreProcessor::defined_SET} {
- set value [lindex $PreProcessor::const_SET($var) {end 1}]
+ foreach var ${::PreProcessor::defined_SET} {
+ set value [lindex $::PreProcessor::const_SET($var) {end 1}]
lappend symbol_table [list [string toupper $var] { } NUMB [get_4hex $value] 1 1]
}
# Write defined special variables (directive "SET")
- foreach var ${PreProcessor::defined_SET_SPEC} {
- set value [lindex $PreProcessor::const_SET_SPEC($var) {end 1}]
+ foreach var ${::PreProcessor::defined_SET_SPEC} {
+ set value [lindex $::PreProcessor::const_SET_SPEC($var) {end 1}]
lappend symbol_table [list [string toupper $var] {S} SPEC [string toupper $value] 1 1]
}
@@ -317,7 +322,7 @@ namespace eval CodeListing {
set symbol_table [lsort -index 0 $symbol_table]
}
- ## Set flag used to 1 for symbol writen in table of symbols
+ ## Set flag used to 1 for symbol written in table of symbols
# @access public
# @parm String symbolic_name - Symbol name
# @parm String type - Symbol type
@@ -326,8 +331,8 @@ namespace eval CodeListing {
variable symbol_table ;# Table of symbolic names
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
- if {!${Compiler::Settings::SYMBOLS}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::SYMBOLS}} {return}
# Find the specified symbol in the table
set symbolic_name [string toupper $symbolic_name]
@@ -348,19 +353,19 @@ namespace eval CodeListing {
## Write error message to the code listing
# @access public
- # @parm Int idx - Index where the error occured
+ # @parm Int idx - Index where the error occurred
# @parm String info - Error message
# @return void
proc Error {idx info} {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Adjust index
set idx [getIdx $idx]
if {$idx == {}} {
- puts stderr "Compiler internal failure 0 -- code listing will not be complete"
+ puts stderr "Assembler internal failure 0 -- code listing will not be complete"
return
}
incr idx
@@ -372,19 +377,19 @@ namespace eval CodeListing {
## Write warning message to the code listing
# @access public
- # @parm Int idx - Index where the warning occured
+ # @parm Int idx - Index where the warning occurred
# @parm String info - Warning message
# @return void
proc Warning {idx info} {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Adjust index
set idx [getIdx $idx]
if {$idx == {}} {
- puts stderr "Compiler internal failure 4 -- code listing will not be complete"
+ puts stderr "Assembler internal failure 4 -- code listing will not be complete"
return
}
incr idx
@@ -402,12 +407,12 @@ namespace eval CodeListing {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Adjust index
set idx [getIdx $idx]
if {$idx == {}} {
- puts stderr "Compiler internal failure 5 -- code listing will not be complete"
+ puts stderr "Assembler internal failure 5 -- code listing will not be complete"
return
}
incr idx 2
@@ -426,13 +431,14 @@ namespace eval CodeListing {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Determinate original values
set sub_idx [getIdx $idx]
+
if {$sub_idx != {}} {
set new_values [lindex $lst [list $sub_idx 1]]
- } {
+ } else {
set new_values {}
}
@@ -468,7 +474,7 @@ namespace eval CodeListing {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Create empty space in code listing
insert_lines $idx [llength $macro_code]
@@ -479,10 +485,10 @@ namespace eval CodeListing {
set tmp_lst {}
# Adjust Macro expansion level and Inclusion level
- set IncLevel [lindex $lst "$idx 3"]
- set MacLevel [lindex $lst "$idx 4"]
+ set IncLevel [lindex $lst [list $idx 3]]
+ set MacLevel [lindex $lst [list $idx 4]]
if {![regexp {^\d+$} $MacLevel]} {
- puts stderr "Compiler internal failure 1 -- code listing will not be complete"
+ puts stderr "Assembler internal failure 1 -- code listing will not be complete"
return
}
incr MacLevel
@@ -493,7 +499,7 @@ namespace eval CodeListing {
}
# Set macro expansion level
- lset lst "$idx 4" $MacLevel
+ lset lst [list $idx 4] $MacLevel
# Insert code of macro to the current code listing
incr idx
@@ -515,7 +521,7 @@ namespace eval CodeListing {
variable new_sync_map ;# Tempotary Map of lines in code listing
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Reformat synchronization map
set new_sync_map {}
@@ -545,7 +551,7 @@ namespace eval CodeListing {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Adjust code listing
set idx [getIdx $idx]
@@ -554,7 +560,7 @@ namespace eval CodeListing {
if {[catch {
lset lst [list $idx 1] $opcode
}]} then {
- puts stderr "Compiler internal failure 2 -- code listing will not be complete"
+ puts stderr "Assembler internal failure 2 -- code listing will not be complete"
return
}
}
@@ -569,15 +575,15 @@ namespace eval CodeListing {
variable sync_map ;# Map of lines in code listing
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Adjust code listing
set idx [getIdx $idx]
if {$idx == {}} {return}
if {[catch {
- lset lst "$idx 0" [get_4hex $addr]
+ lset lst [list $idx 0] [get_4hex $addr]
}]} then {
- puts stderr "Compiler internal failure 3 -- code listing will not be complete"
+ puts stderr "Assembler internal failure 3 -- code listing will not be complete"
return
}
}
@@ -585,13 +591,14 @@ namespace eval CodeListing {
## Directive "END"
# @access public
# @parm Int idx - Source index
+ # @parm Bool preserve_current_line=false - Do not remove the `$idx' line from the sync. map
# @return void
- proc end_directive {idx} {
+ proc end_directive {idx {preserve_current_line 0}} {
variable sync_map ;# Map of lines in code listing
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Determinate target index
set lst_idx [getIdx $idx]
@@ -601,7 +608,12 @@ namespace eval CodeListing {
# Adjust code listing and synchronization map
set lst [lreplace $lst $lst_idx end]
- set sync_map [lreplace $sync_map $idx end]
+ if {$preserve_current_line} {
+ incr idx
+ }
+ if {$idx < [llength $sync_map]} {
+ set sync_map [lreplace $sync_map $idx end]
+ }
}
## Set value for symbol definition
@@ -613,14 +625,14 @@ namespace eval CodeListing {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Determinate target index
set idx [getIdx $idx]
if {$idx == {}} {return}
# Adjust code listing
- lset lst "$idx 2" [get_4hex $value]
+ lset lst [list $idx 2] [get_4hex $value]
}
## Set value for special symbol definition
@@ -642,7 +654,7 @@ namespace eval CodeListing {
variable lst ;# Resulting LST code
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Insert empty lines for the included code
insert_lines $idx [expr {[llength $data] - 1}]
@@ -651,8 +663,8 @@ namespace eval CodeListing {
set idx [getIdx $idx]
# Adjust macro expansion level and inclusion level
- set IncLevel [lindex $lst "$idx 3"]
- set MacLevel [lindex $lst "$idx 4"]
+ set IncLevel [lindex $lst [list $idx 3]]
+ set MacLevel [lindex $lst [list $idx 4]]
incr IncLevel
# Adjust the given source code
@@ -673,6 +685,12 @@ namespace eval CodeListing {
}
+ ## Get last index in the synchronization map
+ # @return Int - The index
+ proc get_last_index_in_sync_map {} {
+ return [expr {[llength ${::CodeListing::sync_map}] - 1}]
+ }
+
## Line removed -- adjust synchronization map
# @access public
# @parm Int idx - source index
@@ -681,24 +699,20 @@ namespace eval CodeListing {
variable sync_map ;# Map of lines in code listing
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
# Adjust synchronization map
- if {[catch {
- set sync_map [lreplace $sync_map $idx $idx]
- }]} {
- puts stderr "Still unresolved compiler bug. I am sorry for that, code listing will not be complete. (As far as I know there is only one bug of that kind)"
- }
+ set sync_map [lreplace $sync_map $idx $idx]
}
- ## Adjust synchronization map to create spece which cannot contain anything
+ ## Adjust synchronization map to create a space which cannot contain anything
# @access public
# @parm Int dest_idx - Target index
# @parm Int len - Number of lines
# @return void
proc insert_empty_lines {dest_idx len} {
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
variable sync_map ;# Map of lines in code listing
variable new_sync_map ;# Tempotary Map of lines in code listing
@@ -775,9 +789,9 @@ namespace eval CodeListing {
}
# Create new page if paging is enabled
- if {${Compiler::Settings::PAGING}} {
+ if {${::Compiler::Settings::PAGING}} {
incr pageLines
- if {$pageLines > ${Compiler::Settings::PAGELENGTH}} {
+ if {$pageLines > ${::Compiler::Settings::PAGELENGTH}} {
incr pageNum
set pageLines 1
append result "\n\f" $header { } $pageNum "\n\n"
@@ -798,7 +812,7 @@ namespace eval CodeListing {
incr lineNum -1
# Normal line
- } {
+ } else {
# Local variables
set addr [lindex $line 0] ;# Address field
set opcode [lindex $line 1] ;# Instruction OP code
@@ -810,7 +824,7 @@ namespace eval CodeListing {
# Adjust inclusion level
if {$IncLevel == 0} {
set IncLevel { }
- } {
+ } else {
set IncLevel "=$IncLevel"
if {[string length $IncLevel] == 2} {
append IncLevel { }
@@ -820,7 +834,7 @@ namespace eval CodeListing {
# Adjust macro expansion level
if {$MacLevel == 0} {
set MacLevel { }
- } {
+ } else {
set MacLevel "+$MacLevel"
if {[string length $MacLevel] == 2} {
append MacLevel { }
@@ -862,7 +876,7 @@ namespace eval CodeListing {
set line {}
append line $field0 { } $IncLevel { } $line_number
append line { } $MacLevel { } [tabs2spaces $code]
- append result [string range $line 0 [expr ${Compiler::Settings::PAGEWIDTH} - 1]] "\n"
+ append result [string range $line 0 [expr ${::Compiler::Settings::PAGEWIDTH} - 1]] "\n"
# Continue in unfinished opcode
if {$opcode_len > 10} {
@@ -887,7 +901,7 @@ namespace eval CodeListing {
# @return String - output data
proc tabs2spaces {data} {
set tmp {} ;# Auxiliary variable
- while 1 {
+ while {1} {
# Search for 1st tabulator
set idx [string first "\t" $data]
@@ -939,7 +953,7 @@ namespace eval CodeListing {
set error_summary {}
# Create new page
- if {${Compiler::Settings::PAGING}} {
+ if {${::Compiler::Settings::PAGING}} {
incr pageNum
set pageLines 0
append error_summary "\n\f" $header { } $pageNum "\n\n"
@@ -953,10 +967,10 @@ namespace eval CodeListing {
incr lineNum
# Create new page if nessesary
- if {${Compiler::Settings::PAGING}} {
+ if {${::Compiler::Settings::PAGING}} {
incr pageLines
- if {$pageLines > ${Compiler::Settings::PAGEWIDTH}} {
+ if {$pageLines > ${::Compiler::Settings::PAGEWIDTH}} {
incr pageNum
set pageLines 1
append error_summary "\n\f" $header { } $pageNum "\n\n"
@@ -968,7 +982,7 @@ namespace eval CodeListing {
if {[lindex $line {1 0}] == {ERROR:}} {
incr errors_count
- } {
+ } else {
incr warnings_count
}
@@ -992,7 +1006,7 @@ namespace eval CodeListing {
set result {}
# Create new page
- if {${Compiler::Settings::PAGING}} {
+ if {${::Compiler::Settings::PAGING}} {
incr pageNum
set pageLines 0
append result "\n\f" $header { } $pageNum "\n\n"
@@ -1006,10 +1020,10 @@ namespace eval CodeListing {
foreach var $symbol_table {
# Create new page if nessesary
- if {${Compiler::Settings::PAGING}} {
+ if {${::Compiler::Settings::PAGING}} {
incr pageLines
- if {$pageLines > ${Compiler::Settings::PAGEWIDTH}} {
+ if {$pageLines > ${::Compiler::Settings::PAGEWIDTH}} {
incr pageNum
set pageLines 1
append result "\n\f" $header { } $pageNum "\n\n"
@@ -1037,14 +1051,14 @@ namespace eval CodeListing {
# Adjust rd
if {$rd == 1} {
set rd {REDEFINABLE}
- } {
+ } else {
set rd {}
}
# Adjust nu
if {$nu == 1} {
set nu {NOT USED}
- } {
+ } else {
set nu { }
}
@@ -1056,7 +1070,7 @@ namespace eval CodeListing {
# Composite final line
if {$char != {S}} {
set h {H}
- } {
+ } else {
set nu { }
set h [string repeat { } [expr {5 - [string length $val]}]]
}
@@ -1105,7 +1119,7 @@ namespace eval CodeListing {
return $number
}
- ## Translate source index to target index acording to synchronization map
+ ## Translate source index to target index according to synchronization map
# @access private
# @parm Int idx - Source index
# @return Int - target index
@@ -1126,7 +1140,7 @@ namespace eval CodeListing {
# @return void
proc insert_lines {dest_idx len} {
# Check if code listing is enabled
- if {!${Compiler::Settings::PRINT}} {return}
+ if {!${::Compiler::Settings::PRINT}} {return}
if {$len == 0} {return}
variable sync_map ;# Map of lines in code listing
@@ -1167,3 +1181,7 @@ namespace eval CodeListing {
set sync_map $new_sync_map
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard