diff options
author | Andrej Shadura <andrewsh@debian.org> | 2018-05-08 15:59:31 +0200 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2018-05-08 15:59:31 +0200 |
commit | 47aa8b00b2b11df13a100489e0f904a4947177ef (patch) | |
tree | b35c9acc778ea2f761f3c549f7bee2f4491b3144 /lib/compiler/assembler.tcl | |
parent | 5b8466f7fae0e071c0f4eda13051c93313910028 (diff) |
Import Upstream version 1.4.7
Diffstat (limited to 'lib/compiler/assembler.tcl')
-rw-r--r--[-rwxr-xr-x] | lib/compiler/assembler.tcl | 71 |
1 files changed, 45 insertions, 26 deletions
diff --git a/lib/compiler/assembler.tcl b/lib/compiler/assembler.tcl index 5c41a28..17e5244 100755..100644 --- a/lib/compiler/assembler.tcl +++ b/lib/compiler/assembler.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 _ASSEMBLER_TCL ] } { +set _ASSEMBLER_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Coverts precompiled source code to IHEX 8 format. @@ -43,7 +48,7 @@ # ... # hash - Hexadecimal MD5 hash of source code # file - Filename of source code -# filenum - File number (begining from 0) +# filenum - File number (beginning from 0) # line - Number of line in source code # address - Code address # code - Processor code @@ -78,7 +83,7 @@ namespace eval assembler { variable offset ;# Current address variable data_len ;# Data length (for creating IHEX records) variable data_field ;# Data field (for creating IHEX records) - variable address ;# Address of begining of IHEX data field + variable address ;# Address of beginning of IHEX data field variable operands ;# List of operand codes variable opcode ;# OP code of the current instruction variable bin_len ;# Lenght of binary data @@ -106,7 +111,7 @@ namespace eval assembler { variable lineNumber 0 ;# Number of line currently beeing parsed variable opcode ;# OP code of the current instruction variable operands ;# List of operand codes - variable address ;# Address of begining of IHEX data field + variable address ;# Address of beginning of IHEX data field variable opr_types ;# List of operand types variable offset 0 ;# Current address variable data_len 0 ;# Data length (for creating IHEX records) @@ -137,7 +142,7 @@ namespace eval assembler { foreach filename $included_files { if {[catch { append adf [::md5::md5 -hex -file $filename] - } result]} { + } result]} then { append adf 0 CompilationError [mc "File access error:\n%s" $result] } @@ -152,7 +157,9 @@ namespace eval assembler { foreach line $code { # Update GUI after each 25 iterations - if {[expr {$idx % 25}] == 0} ${Compiler::Settings::UPDATE_COMMAND} + if {[expr {$idx % 25}] == 0} { + ${::Compiler::Settings::UPDATE_COMMAND} + } if {${::Compiler::Settings::ABORT_VARIABLE}} { ${::Compiler::Settings::TEXT_OUPUT_COMMAND} [::Compiler::msgc {EN}][mc "Aborted"] free_resources @@ -179,6 +186,7 @@ namespace eval assembler { if {$opcode == { }} { set opcode 32 } + set opcode [format %X $opcode] set digits [string length $opcode] if {$digits < 2} { @@ -189,7 +197,7 @@ namespace eval assembler { } set nolist 1 - } { + } else { # Check for instruction existence if {[notAnInstruction $instruction]} {continue} @@ -206,7 +214,7 @@ namespace eval assembler { set offset $address } - # If data length overlaps 255 or adress is too high -> flush data buffer + # If data length overlaps 255 or address is too high -> flush data buffer if {($pointer < $address) || (($data_len + $len) > ${::Compiler::Settings::max_ihex_rec_length})} { write_bin write_hex @@ -214,7 +222,7 @@ namespace eval assembler { set offset $address set pointer $address - # Unexpected adress + # Unexpected address } elseif {$pointer > $address} { CompilationError [mc "Invalid address at %s" 0x[format %X $address]] set pointer $address @@ -231,7 +239,7 @@ namespace eval assembler { # Translate operands to 16|12|8-bit hex set operands [oprs2hex] - # Adjust inctruction OP code acording to the OP code mask and operands + # Adjust instruction OP code according to the OP code mask and operands if {$mask != 0} { # Determinate length of the first operand set mask_bin [hex2binlist $mask] @@ -259,12 +267,12 @@ namespace eval assembler { set operand0 [string range $operand0 $opr_len end] # Adjust OP code - set idx 0 + set op_idx 0 foreach mask_bit $mask_bin { if {$mask_bit} { - set opcode [lreplace $opcode $idx $idx [lindex $opcode_opr $idx]] + set opcode [lreplace $opcode $op_idx $op_idx [lindex $opcode_opr $op_idx]] } - incr idx + incr op_idx } # Finalize @@ -290,7 +298,7 @@ namespace eval assembler { append opcode [lindex $operands 1] append opcode [lindex $operands 0] # Other instructions - } { + } else { foreach opr $operands { append opcode $opr } @@ -308,12 +316,13 @@ namespace eval assembler { write_hex if {${::Compiler::Settings::OBJECT}} { append hex {:00000001FF} + append hex "\n" } # Return result if {$error_count} { return 0 - } { + } else { return 1 } } @@ -327,7 +336,8 @@ namespace eval assembler { data_field address operands opcode bin_len error_count fileNumber - } { + } \ + { set ::assembler::$var {} } } @@ -355,7 +365,7 @@ namespace eval assembler { variable adf ;# Output simulator data variable fileNumber ;# File number variable lineNumber ;# Number of line currently beeing parsed - variable address ;# Address of begining of IHEX data field + variable address ;# Address of beginning of IHEX data field variable opcode ;# OP code of the current instruction variable operands ;# List of operand codes @@ -370,12 +380,12 @@ namespace eval assembler { lappend new_code [expr "0x[lindex $operands 1]"] lappend new_code [expr "0x[lindex $operands 0]"] # Other instructions - } { + } else { foreach hex $operands { if {[string length $hex] == 4} { lappend new_code [expr "0x[string range $hex 0 1]"] lappend new_code [expr "0x[string range $hex 2 3]"] - } { + } else { lappend new_code [expr "0x$hex"] } } @@ -409,7 +419,7 @@ namespace eval assembler { # Write binary data for {set i 0; set j 1} {$i < $data_len} {incr i 2; incr j 2} { set hex [string range $data_field $i $j] - append bin [subst "\\x$hex"] + append bin [subst -nocommands "\\x$hex"] incr bin_len } } @@ -480,13 +490,18 @@ namespace eval assembler { # Check for validity of the given operand set opr [string trimleft $opr {#@/}] - if {![regexp {^\d+$} $opr]} { + if {![string is digit -strict $opr]} { CompilationError [mc "Invalid operand: '%s'" $opr] break } # Convert to hexadecimal string - set opr [format %X $opr] + set opr [string trimleft $opr 0] + if {$opr == {}} { + set opr 0 + } else { + set opr [format %X $opr] + } # Adjust length set opr_len [string length $opr] @@ -525,7 +540,7 @@ namespace eval assembler { variable opr_types ;# List of operand types # Iterate over operands definitions - foreach definition [lindex $CompilerConsts::InstructionDefinition($instruction) 1] { + foreach definition [lindex $::CompilerConsts::InstructionDefinition($instruction) 1] { # Determinate operand types set opr_list [lindex $definition 0] @@ -585,11 +600,15 @@ namespace eval assembler { if {${::Compiler::Settings::WARNING_LEVEL} < 3} { if {${::Compiler::Settings::NOCOLOR}} { ${::Compiler::Settings::TEXT_OUPUT_COMMAND} \ - [::Compiler::msgc {EL}][mc "Compilation error at line %s: %s" "${lineNumber}${filename}" $errorInfo] - } { + [::Compiler::msgc {EL}][mc "Compilation error at %s: %s" "${lineNumber}${filename}" $errorInfo] + } else { ${::Compiler::Settings::TEXT_OUPUT_COMMAND} \ - [mc "\033\[31;1mCompilation error at line \033\[31;1;4m%s\033\[m%s: %s" $lineNumber $filename $errorInfo] + [mc "\033\[31;1mCompilation error at \033\[31;1;4m%s\033\[m%s: %s" $lineNumber $filename $errorInfo] } } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard |