summaryrefslogtreecommitdiff
path: root/lib/cli.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cli.tcl')
-rw-r--r--[-rwxr-xr-x]lib/cli.tcl203
1 files changed, 139 insertions, 64 deletions
diff --git a/lib/cli.tcl b/lib/cli.tcl
index d423339..63b28e0 100755..100644
--- a/lib/cli.tcl
+++ b/lib/cli.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 _CLI_TCL ] } {
+set _CLI_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Handle options given by command line interface
@@ -30,17 +35,17 @@
# SET COMMMAND LINE OPTIONS TO DEFAULTS
# --------------------------------------
set CLI_OPTION(notranslation) 0 ;# Disable i18n
-set CLI_OPTION(quiet) 0 ;# Don't display status of initialization progress on startup
+set CLI_OPTION(quiet) 0 ;# Don't display status of initialization progress on start-up
set CLI_OPTION(nosplash) 0 ;# Don't show splash screen
set CLI_OPTION(nocolor) 0 ;# Disable color output
set CLI_OPTION(defaults) 0 ;# Start with default settings
set CLI_OPTION(minimalized) 0 ;# Start with minimalized window
set CLI_OPTION(ignore_last) 0 ;# Start with an empty session
-set CLI_OPTION(check_libraries) 0 ;# Check if all nessery Tcl libraries are avaible
+set CLI_OPTION(check_libraries) 0 ;# Check if all necessary Tcl libraries are available
set CLI_OPTION(reset_settings) 0 ;# Reset all user settings to defaults
set CLI_OPTION(help) 0 ;# Show help message and exit
set CLI_OPTION(convert) 0 ;# Convert one file to another format
-set CLI_OPTION(no_opt) 0 ;# Disable optimalizations
+set CLI_OPTION(no_opt) 0 ;# Disable optimization
set CLI_OPTION(comp_quiet) 0 ;# Suppress compiler console output
set CLI_OPTION(no_sim) 0 ;# Do not generate SIM file
set CLI_OPTION(no_bin) 0 ;# Do not generate binary object code
@@ -50,13 +55,14 @@ set CLI_OPTION(warning_level) 0 ;# Compiler warning level
set CLI_OPTION(input_output) {} ;# List of file to convert: [0] == input file; [1] == output file
set CLI_OPTION(compile) {} ;# Compile this asm file and exit
set CLI_OPTION(open_project) {} ;# Open only project specified by this var if any
-set CLI_OPTION(config_file) {} ;# Specify path to file containg user settings
+set CLI_OPTION(config_file) {} ;# Specify path to file containing user settings
set CLI_OPTION(autoindent) {} ;# Specify path to file to indent
set CLI_OPTION(iram-size) {} ;# Size of internal data memory
set CLI_OPTION(xram-size) {} ;# Size of external data memory
set CLI_OPTION(code-size) {} ;# Size of program memory
set CLI_OPTION(disassemble) {} ;# IHEX8 file to disassemble
-set CLI_OPTION(no-plugins) 0 ;# Disable plugins
+set CLI_OPTION(no-plugins) 0 ;# Disable plug-ins
+set CLI_OPTION(simulator) 0 ;# Start simulator only
# ------------------------------------------------------------------------------
@@ -65,6 +71,8 @@ set CLI_OPTION(no-plugins) 0 ;# Disable plugins
if {$::MICROSOFT_WINDOWS} {
# Windows has no terminal control codes (at least I am not aware of them)
set CLI_OPTION(nocolor) 1
+ # It's usually only annoying to have verbose output on Windows
+ set CLI_OPTION(quiet) 1
}
# ------------------------------------------------------------------------------
@@ -102,7 +110,7 @@ proc CLI_set_memory_limit {option value maximum_in_hex memtype} {
if {[string index $arg end] == {k}} {
set arg [string replace $arg end end]
set kilo 1
- } {
+ } else {
set kilo 0
}
if {![string is digit -strict $arg]} {
@@ -113,7 +121,7 @@ proc CLI_set_memory_limit {option value maximum_in_hex memtype} {
set arg [expr {$arg * 1024}]
}
if {$arg > $maximum_in_hex} {
- puts stderr "Maximum acceptable size of $memtype memory is $maximum_in_hex ([expr $maximum_in_hex])"
+ puts stderr "Maximum acceptable size of $memtype memory is $maximum_in_hex ([expr {$maximum_in_hex}])"
exit 1
}
set CLI_OPTION($option) $arg
@@ -158,12 +166,12 @@ proc CLI_convert {i type} {
set file [lindex $argv [expr {$i + 2}]]
if {[file exists $file]} {
if {
- [file isdirectory $file] ||
- ![file writable $file]
- } {
- puts "${::APPNAME}"
- puts stderr "\tERROR: Unable to write to file '$file'"
- exit 1
+ [file isdirectory $file] ||
+ ![file writable $file]
+ } then {
+ puts "${::APPNAME}"
+ puts stderr "\tERROR: Unable to write to file '$file'"
+ exit 1
}
}
}
@@ -190,26 +198,35 @@ proc CLI_next_arg {i option key} {
# Check if the specified file does exist
if {
- [file isdirectory $::CLI_OPTION($key)] ||
- ![file exists $::CLI_OPTION($key)] ||
- (!$::MICROSOFT_WINDOWS && ![file readable $::CLI_OPTION($key)])]
- } {
- puts "${::APPNAME}"
- puts stderr "\tERROR: Unable to read file '$::CLI_OPTION($key)'"
- exit 1
+ [file isdirectory $::CLI_OPTION($key)] ||
+ ![file exists $::CLI_OPTION($key)] ||
+ (!$::MICROSOFT_WINDOWS && ![file readable $::CLI_OPTION($key)])
+ } then {
+ puts "${::APPNAME}"
+ puts stderr "\tERROR: Unable to read file '$::CLI_OPTION($key)'"
+ exit 1
}
}
-# PARSE COMMAND LINE OPTIONS
-# --------------------------
+## Parse command line options
+ # @return void
+proc parse_cli_options {} {
+ global argc ;# Int: Arguments count
+ global argv ;# List: Arguments list
+ global CLI_OPTION ;# Array: Commmand line options
+
+ # Open project file, if it's the only argument given to the program
+ if {$argc == 1 && [regexp {^.+\.mcu8051ide$} [lindex $argv 0]]} {
+ set CLI_OPTION(open_project) [file normalize [lindex $argv 0]]
+ return
+ }
-if {$argc} {
# iterate over all given arguments
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
# decide what to do with each of them
- switch -- $arg {
+ switch -exact -- $arg {
{--help} { ;# Display help message only
set CLI_OPTION(help) 1
@@ -217,7 +234,7 @@ if {$argc} {
{-h} { ;# Display help message only
set CLI_OPTION(help) 1
}
- {--quiet} { ;# Don't display initialization progress on startup
+ {--quiet} { ;# Don't display initialization progress on start-up
set CLI_OPTION(quiet) 1
}
{--no-translation} { ;# Disable i18n
@@ -226,7 +243,7 @@ if {$argc} {
{--no-i18n} { ;# Disable i18n
set CLI_OPTION(notranslation) 1
}
- {-q} { ;# Don't display initialization progress on startup
+ {-q} { ;# Don't display initialization progress on start-up
set CLI_OPTION(quiet) 1
}
{--nosplash} { ;# Don't show splash screen
@@ -264,6 +281,7 @@ if {$argc} {
CLI_next_arg $i {--config-file} {config_file}
incr i
}
+ {--assemble} -
{--compile} { ;# Compile asm file and exit
CLI_next_arg $i {--compile} {compile}
incr i
@@ -307,7 +325,7 @@ if {$argc} {
incr i
CLI_set_memory_limit {code-size} [lindex $argv $i] 0x10000 {code}
}
- {--no-opt} { ;# Disable optimalizations
+ {--no-opt} { ;# Disable optimization
set CLI_OPTION(no_opt) 1
}
{--comp-quiet} { ;# Suppress compiler console output
@@ -341,12 +359,26 @@ if {$argc} {
{--no-plugins} { ;# Disable plugins
set CLI_OPTION(no-plugins) 1
}
+ {--simulator} { ;# Start simulator only
+ set CLI_OPTION(simulator) 1
+ }
default { ;# Unknown option -- terminate program
puts stderr "Unknown command line option: '$arg'"
exit 1
}
}
}
+
+ # discard CLI arguments
+ set argc 0
+ set argv [list]
+}
+
+# PARSE COMMAND LINE OPTIONS
+# --------------------------
+
+if {$argc} {
+ parse_cli_options
}
# HANDLE CLI OPTIONS WHICH REQUIRE INSTANT RESPONSE
@@ -361,15 +393,15 @@ if {$CLI_OPTION(help)} {
set clr_end {}
set clr_opt {}
set clr_arg {}
- } {
+ } else {
puts "\033\[1mOptions:\033\[m"
set clr_end "\033\[m"
set clr_opt "\033\[32m"
set clr_arg "\033\[33;1m"
}
- puts "\t${clr_opt}--no-translation${clr_end},\tDisplay program language translation\n\t${clr_opt}--no-i18n${clr_end}"
+ puts "\t${clr_opt}--no-translation${clr_end},\tDisable program language translation\n\t${clr_opt}--no-i18n${clr_end}"
puts "\t${clr_opt}--help${clr_end}, ${clr_opt}-h${clr_end}\t\tDisplay this message"
- puts "\t${clr_opt}--quiet${clr_end}, ${clr_opt}-q${clr_end}\t\tDon't display status of initialization progress on startup"
+ puts "\t${clr_opt}--quiet${clr_end}, ${clr_opt}-q${clr_end}\t\tDon't display status of initialization progress on start-up"
puts "\t${clr_opt}--no-plugins${clr_end}\t\tDisable plugins"
puts "\t${clr_opt}--nosplash${clr_end}\t\tDon't show splash screen"
puts "\t${clr_opt}--nocolor${clr_end}, ${clr_opt}-n${clr_end}\t\tDisable color output"
@@ -378,7 +410,7 @@ if {$CLI_OPTION(help)} {
puts "\t${clr_opt}--minimalized${clr_end}\t\tStart with minimalized window"
puts "\t${clr_opt}--config-file ${clr_arg}filename${clr_end}\tSpecify path to file containg user settings"
puts "\t${clr_opt}--check-libraries${clr_end}\tCheck if all nessesary Tcl libraries are avaible"
- puts "\t${clr_opt}--ignore-last-session${clr_end}\tStart with an empty session (no project will be opened at startup)"
+ puts "\t${clr_opt}--ignore-last-session${clr_end}\tStart with an empty session (no project will be opened at start-up)"
puts "\t${clr_opt}--open-project ${clr_arg}project${clr_end}\tOpen only this project"
puts "\t${clr_opt}--reset-user-settings${clr_end}\tReset all user settings to defaults"
puts ""
@@ -390,13 +422,14 @@ if {$CLI_OPTION(help)} {
puts "\t${clr_opt}--normalize-hex ${clr_arg}input${clr_end}\tNormalize IHEX8 file"
puts ""
puts "\t${clr_opt}--disassemble ${clr_arg}hex_file${clr_end}\tDisaseble IHEX8 code to ${clr_arg}hex_file.asm${clr_end}"
- puts "\t${clr_opt}--compile ${clr_arg}asm_file${clr_end}\tCompile asm file and exit"
+ puts "\t${clr_opt}--assemble ${clr_arg}asm_file${clr_end}\tCompile asm file and exit"
+ puts "\t${clr_opt}--compile ${clr_arg}asm_file${clr_end}\tThe same as ``--assemble''"
puts "\t${clr_opt}--iram-size ${clr_arg}size${clr_end}\tSet size of internal data memory\t(eg. 1K or 1024) (default: 0x100)"
puts "\t${clr_opt}--code-size ${clr_arg}size${clr_end}\tSet size of program memory\t\t(eg. 1K or 1024) (default: 0x10000)"
puts "\t${clr_opt}--xram-size ${clr_arg}size${clr_end}\tSet size of external data memory\t(eg. 1K or 1024) (default: 0x10000)"
- puts "\t${clr_opt}--no-opt${clr_end}\t\tDisable optimalizations"
+ puts "\t${clr_opt}--no-opt${clr_end}\t\tDisable optimization"
puts "\t${clr_opt}--comp-quiet${clr_end}\t\tSuppress compiler console output"
- puts "\t${clr_opt}--no-sim${clr_end}\t\tDo not generate SIM file (for MCU 8051 IDE simulator)"
+ puts "\t${clr_opt}--no-sim${clr_end}\t\tDo not generate ADF file (Asm. Debug File for MCU 8051 IDE simulator)"
puts "\t${clr_opt}--no-bin${clr_end}\t\tDo not generate binary object code"
puts "\t${clr_opt}--no-lst${clr_end}\t\tDo not generate code listing"
puts "\t${clr_opt}--no-hex${clr_end}\t\tDo not generate IHEX8 object code"
@@ -406,6 +439,7 @@ if {$CLI_OPTION(help)} {
puts "\t\t${clr_arg}1${clr_end} - Errors + Warnings"
puts "\t\t${clr_arg}0${clr_end} - All (Default)"
puts ""
+ puts "\t${clr_opt}--simulator${clr_end}\t\tStart simulator only, see manual for more details"
exit
}
@@ -431,7 +465,7 @@ if {$CLI_OPTION(convert)} {
# Open input and output file
set input [open $input {r}]
- set output [open $output {w} 420]
+ set output [open $output {w} 0640]
fconfigure $input -translation binary
fconfigure $output -translation binary
@@ -476,7 +510,7 @@ if {$CLI_OPTION(convert)} {
if {${::IHexTools::error_count}} {
puts "FAILED !"
puts ${::IHexTools::error_string}
- } {
+ } else {
puts "Successful"
}
@@ -502,7 +536,7 @@ if {$CLI_OPTION(autoindent) != {}} {
exit 1
}
}
- puts "Formating ..."
+ puts "Formatting ..."
# Load and reformat file content
set ::X::reformat_code_abort 0
@@ -512,7 +546,7 @@ if {$CLI_OPTION(autoindent) != {}} {
close $file
# Save file
- set file [open $CLI_OPTION(autoindent) w 420]
+ set file [open $CLI_OPTION(autoindent) w 0640]
puts -nonewline $file $data
close $file
@@ -534,8 +568,8 @@ if {$CLI_OPTION(disassemble) != {}} {
# Open source and destination files
if {[catch {
set src_file [open $CLI_OPTION(disassemble) {r}]
- set trg_file [open [file rootname $CLI_OPTION(disassemble)].asm w 420]
- }]} {
+ set trg_file [open [file rootname $CLI_OPTION(disassemble)].asm w 0640]
+ }]} then {
puts stderr "Unable to open either \"$CLI_OPTION(disassemble)\" or \"[file rootname $CLI_OPTION(disassemble)].asm\""
exit 1
}
@@ -551,15 +585,15 @@ if {$CLI_OPTION(disassemble) != {}} {
if {${::IHexTools::error_count}} {
puts ${::IHexTools::error_string}
if {$CLI_OPTION(nocolor)} {
- puts "Decompilation FAILED"
- } {
- puts "\033\[31;1mDecompilation FAILED\033\[m"
+ puts "Disassembly FAILED"
+ } else {
+ puts "\033\[31;1mDisassembly FAILED\033\[m"
}
}
if {$CLI_OPTION(nocolor)} {
puts "Result stored in \"[file rootname $CLI_OPTION(disassemble)].asm\"\n"
- } {
+ } else {
puts "Result stored in \"\033\[34;1m[file rootname $CLI_OPTION(disassemble)].asm\033\[m\"\n"
}
@@ -574,7 +608,7 @@ if {$CLI_OPTION(disassemble) != {}} {
if {$CLI_OPTION(compile) != {}} {
# Import required sources
package require md5 2.0.1
- source "${::LIB_DIRNAME}/lib/Math.tcl" ;# Special mathematical operations
+ source "${::LIB_DIRNAME}/lib/Math.tcl" ;# Special mathematical operations
source "${::LIB_DIRNAME}/compiler/compiler.tcl" ;# 8051 Assemly language compiler
source "${::LIB_DIRNAME}/lib/ihextools.tcl" ;# Tools for manipulating with IHEX8
@@ -594,7 +628,7 @@ if {$CLI_OPTION(compile) != {}} {
set Compiler::Settings::xram_size $CLI_OPTION(xram-size)
}
- # Enable / Disable optimalizations
+ # Enable / Disable optimization
if {$CLI_OPTION(no_opt)} {
set Compiler::Settings::optim_ena 0
}
@@ -620,7 +654,7 @@ if {$CLI_OPTION(compile) != {}} {
# Initialize compiler
set result [Compiler::compile $directory $directory $filename $extension]
- # Exit acording to compilation result
+ # Exit according to compilation result
exit [expr {!$result}]
}
@@ -628,24 +662,24 @@ if {$CLI_OPTION(compile) != {}} {
if {$CLI_OPTION(check_libraries)} {
# Local varibale
- set librariesToCheck [llength $LIBRARIES_TO_LOAD] ;# Number of libs to check
+ set librariesToCheck [llength $::LIBRARIES_TO_LOAD] ;# Number of libs to check
set failsVer 0 ;# Number of libraries which didn't pass version check
set failsLib 0 ;# Number of libraries which could not be found
set failsTotal 0 ;# Number of fails tottaly
- puts "$APPNAME\n"
+ puts "$::APPNAME\n"
puts "\tChecking libraries..."
# Iterate over list of needed libraries
for {set i 0} {$i < $librariesToCheck} {incr i} {
# Local variables
- set library [lindex $LIBRARIES_TO_LOAD "$i 0"] ;# Library name
- set version [lindex $LIBRARIES_TO_LOAD "$i 1"] ;# Library version
+ set library [lindex $::LIBRARIES_TO_LOAD [list $i 0]] ;# Library name
+ set version [lindex $::LIBRARIES_TO_LOAD [list $i 1]] ;# Library version
# Print what library is currently being checked
if {$CLI_OPTION(nocolor)} {
puts "\t\t[expr {$i + 1}]/$librariesToCheck Checking for library $library"
- } {
+ } else {
puts "\t\t\033\[33m[expr {$i + 1}]/$librariesToCheck\033\[m \033\[37mChecking for library\033\[m \033\[32m$library\033\[m"
}
@@ -655,14 +689,14 @@ if {$CLI_OPTION(check_libraries)} {
if {[catch {package require $library}]} {
if {$CLI_OPTION(nocolor)} {
puts "NO !"
- } {
+ } else {
puts "\033\[31;01mNO !\033\[m"
}
incr failsLib
- } {
+ } else {
if {$CLI_OPTION(nocolor)} {
puts "YES"
- } {
+ } else {
puts "\033\[32;01mYES\033\[m"
}
}
@@ -670,21 +704,21 @@ if {$CLI_OPTION(check_libraries)} {
# Perform version check and diplay result
if {$CLI_OPTION(nocolor)} {
puts -nonewline "\t\t\tVersion $version\t... "
- } {
+ } else {
puts -nonewline "\t\t\tVersion \033\[36m$version\033\[m\t... "
}
flush stdout
if {[catch {package require $library $version}]} {
if {$CLI_OPTION(nocolor)} {
puts "NO !"
- } {
+ } else {
puts "\033\[31;01mNO !\033\[m"
}
incr failsVer
- } {
+ } else {
if {$CLI_OPTION(nocolor)} {
puts "YES"
- } {
+ } else {
puts "\033\[32;01mYES\033\[m"
}
}
@@ -693,7 +727,7 @@ if {$CLI_OPTION(check_libraries)} {
# Determinate number of total fails
if {$failsVer > $failsLib} {
set failsTotal $failsVer
- } {
+ } else {
set failsTotal $failsLib
}
@@ -704,16 +738,16 @@ if {$CLI_OPTION(check_libraries)} {
if {$CLI_OPTION(nocolor)} {
puts "\t\tNumber of fails: $failsTotal"
puts "\t\tPROGRAM WILL NOT RUN, please install the missing libraries"
- } {
+ } else {
puts "\t\tNumber of fails: \033\[31m$failsTotal\033\[m"
puts "\t\t\033\[31;01mPROGRAM WILL NOT RUN\033\[m, please install the missing libraries"
}
- } {
+ } else {
# SUCCESSFUL
if {$CLI_OPTION(nocolor)} {
puts "\t\tNumber of fails: $failsTotal"
puts "\t\tEverything seems ok"
- } {
+ } else {
puts "\t\tNumber of fails: \033\[32;01m$failsTotal\033\[m"
puts "\t\t\033\[32mEverything seems ok\033\[m"
}
@@ -723,3 +757,44 @@ if {$CLI_OPTION(check_libraries)} {
# done ...
exit
}
+
+# Start simulator only
+if {$CLI_OPTION(simulator)} {
+ puts [list $::SHORTNAME {SIM-ENGINE} $::VERSION]
+
+ # Import required libraries
+ package require Itcl 3.4
+ package require tdom 0.8
+
+ # Configure environment
+ set ::GUI_AVAILABLE 0
+ namespace import -force ::itcl::*
+
+ # Tools for manipulating with IHEX8
+ source "${::LIB_DIRNAME}/lib/ihextools.tcl"
+ # Simulator engine
+ source "${::LIB_DIRNAME}/simulator/engine/engine_core.tcl"
+ # PALE
+ source "${::LIB_DIRNAME}/pale/pale.tcl"
+ # Simulator enginine CLI
+ source "${::LIB_DIRNAME}/simulator/engine/engine_text_based_interface.tcl"
+ # Database of supported MCUs
+ source "${::LIB_DIRNAME}/dialogues/selectmcu.tcl"
+ #
+ source "${::LIB_DIRNAME}/lib/Math.tcl"
+ #
+ source "${::LIB_DIRNAME}/compiler/assembler.tcl"
+ #
+ source "${::LIB_DIRNAME}/compiler/compilerconsts.tcl"
+
+
+ # Enter main loop of the sim. engine CLI
+ SimulatorEngineCLI::enter_main_loop
+
+ # done ...
+ exit
+}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard