summaryrefslogtreecommitdiff
path: root/lib/compiler/compiler.tcl
blob: 1222a0f76b2b2c761a472f59e55d7015890df43a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#!/usr/bin/tclsh
# Part of MCU 8051 IDE ( http://http://www.moravia-microsystems.com/mcu8051ide )

############################################################################
#    Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin OŇ°mera     #
#    martin.osmera@gmail.com                                               #
#                                                                          #
#    Copyright (C) 2014 by Moravia Microsystems, s.r.o.                    #
#    martin.osmera@moravia-microsystems.com                                #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

# >>> File inclusion guard
if { ! [ info exists _COMPILER_TCL ] } {
set _COMPILER_TCL _
# <<< File inclusion guard

# --------------------------------------------------------------------------
# 8051 COMPILER - BASE NAMESPACE
# --------------------------------------------------------------------------

# Include other parts
source "${::LIB_DIRNAME}/compiler/codelisting.tcl"	;# Code listing creator
source "${::LIB_DIRNAME}/compiler/assembler.tcl"	;# Assembler
source "${::LIB_DIRNAME}/compiler/disassembler.tcl"	;# Disassembler
source "${::LIB_DIRNAME}/compiler/preprocessor.tcl"	;# Preprocessor
source "${::LIB_DIRNAME}/compiler/compilerconsts.tcl"	;# Compiler constant definitons
source "${::LIB_DIRNAME}/compiler/external_compiler.tcl";# External compiler interface

namespace eval Compiler {
	variable error_count	;# Number of errors occurred during compilation
	variable warning_count	;# Number of warning reported during compilation

	variable in_IDE	0	;# Bool: Running in IDE (I mean GUI)

	# Procedure which do nothing (for better portability)
	proc doNothing args {}

	## Initiate compilation
	 # @parm String project_dir			- Project directory
	 # @parm String current_dir			- Current working directory
	 # @parm String input_file_name			- Name of input source code
	 # @parm String input_file_extension={}		- Extension of input file
	 # @return Bool - result
	proc compile {project_dir current_dir input_file_name {input_file_extension {}}} {
		variable error_count	;# Number of errors occurred during compilation
		variable warning_count	;# Number of warning reported during compilation

		# Compiler settings to defaults
		Compiler::Settings::restoreDefaults

		# Adjust compiler settings
		if {${::Compiler::Settings::_print} == 2} {
			set ::Compiler::Settings::PRINT 0
		} else {
			set ::Compiler::Settings::PRINT 1
		}
		if {${::Compiler::Settings::_object} == 2} {
			set ::Compiler::Settings::OBJECT 0
		} else {
			set ::Compiler::Settings::OBJECT 1
		}

		# Reset errors and warnings counters
		set error_count 0
		set warning_count 0

		# Set input filename and determinate time of start of compilation
		set Settings::INPUT_FILE_NAME $input_file_name
		set sec [clock seconds]

		# Adjust input file extension
		if {$input_file_extension != {}} {
			set input_file_extension ".$input_file_extension"
		}

		# Check for usability of the given input file
		set file [file join $current_dir $input_file_name$input_file_extension]

		# Open and read contents of the input file
		if {[catch {
			set asm [open $file r]
			set asm_data [read $asm]
			close $asm
		}]} then {
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [::Compiler::msgc {EN}][mc "Unable to open the specified file. (%s)" $file]
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [::Compiler::msgc {EN}][mc "Compilation FAILED !"]
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [mc "Unable to open the specified file. (\033\[34;1m%s\033\[m)" $file]
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [mc "\033\[31;1mCompilation FAILED !\033\[m"]
			}
			return 0
		}

		# Initialize preprocessor
		if {!${::Compiler::Settings::QUIET}} {
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
					"\n\n[::Compiler::msgc {SN}][mc {Compiling file: %s}  $input_file_name$input_file_extension]"
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
					[mc "\n\nCompiling file: \033\[34;1m%s\033\[m" $input_file_name$input_file_extension]
			}
			${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
				[mc "Initializing pre-processor ..."]
		}
		set precompiledCode [PreProcessor::compile $current_dir $file $asm_data]
		set asm_data {}
		incr error_count ${::PreProcessor::error_count}
		incr warning_count ${::PreProcessor::warning_count}
		if {${::PreProcessor::error_count} > 0} {
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [::Compiler::msgc {EN}][mc "Pre-processing FAILED !"]
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [mc "\033\[31;1mPre-processing FAILED !\033\[m"]
			}
			report_status $current_dir $input_file_name
			return 0
		}

		if {${::Compiler::Settings::ABORT_VARIABLE}} {return 0}

		# Initialize Assembler
		if {!${::Compiler::Settings::QUIET}} {
			${::Compiler::Settings::TEXT_OUPUT_COMMAND} [mc "Compiling ..."]
		}
		assembler::compile					\
			[md5::md5 -hex -file $file]			\
			[clock format [clock seconds] -format "%D"]	\
			$project_dir					\
			[file join $current_dir $input_file_name$input_file_extension]	\
			${::PreProcessor::included_files}		\
			$precompiledCode
		set ::PreProcessor::included_files {}
		incr error_count ${::assembler::error_count}
		if {${::assembler::error_count} > 0} {
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [::Compiler::msgc {EN}][mc "Compilation FAILED !"]
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} [mc "\033\[31;1mCompilation FAILED !\033\[m"]
			}
			report_status $current_dir $input_file_name
			return 0
		}

		if {${::Compiler::Settings::ABORT_VARIABLE}} {return 0}

		# Write resulting object code
		if {${::Compiler::Settings::OBJECT}} {
			if {${::Compiler::Settings::OBJECT_FILE} != {}} {
				set object_file ${::Compiler::Settings::OBJECT_FILE}
			} else {
				set object_file $input_file_name
				append object_file {.hex}
			}
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
					[mc "Creating IHEX8 ...\t\t\t-> \"%s\"" $object_file]
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
				[mc "Creating IHEX8 ...\t\t\t-> \"\033\[34;1m%s\033\[m\"" $object_file]
			}
			makeBackupFile $current_dir $object_file
			if {[catch {
				set hex [open [file join $current_dir $object_file] w 0640]
			}]} then {
				if {${::Compiler::Settings::NOCOLOR}} {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Error: Unable to open file \"%s\" for writing" [file join $current_dir $object_file]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Compilation FAILED !"]
				} else {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "\033\[31;1mError\033\[m: Unable to open file \"\033\[34;1m%s\033\[m\" for writing" [file join $current_dir $object_file]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "\033\[31;1mCompilation FAILED !\033\[m"]
				}
				report_status $current_dir $input_file_name
				return 0
			} else {
				puts -nonewline $hex ${::assembler::hex}
				close $hex
			}
		}

		if {${::Compiler::Settings::ABORT_VARIABLE}} {return 0}

		# Write resulting binary object code
		if {${::Compiler::Settings::CREATE_BIN_FILE}} {
			if {!${::Compiler::Settings::QUIET}} {
				if {${::Compiler::Settings::NOCOLOR}} {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "Creating object file ...\t\t-> \"%s\"" "${input_file_name}.bin"]
				} else {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "Creating object file ...\t\t-> \"\033\[34;1m%s\033\[m\"" "${input_file_name}.bin"]
				}
			}

			makeBackupFile $current_dir "${input_file_name}.bin"
			if {[catch {
				set bin [open [file join $current_dir $input_file_name.bin] w 0640]
			}]} then {
				if {${::Compiler::Settings::NOCOLOR}} {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Error: Unable to open file \"%s\" for writing" [file join $current_dir $input_file_name.bin]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Compilation FAILED !"]
				} else {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "Error: Unable to open file \"\033\[34;1m%s\033\[m\" for writing" [file join $current_dir "${input_file_name}.bin"]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "\033\[31;1mCompilation FAILED !\033\[m"]
				}
				report_status $current_dir $input_file_name
				return 0
			} else {
				fconfigure $bin -translation binary
				puts -nonewline $bin ${::assembler::bin}
				close $bin
			}
			set bin_data {}
		}
		set hex_data {}

		if {${::Compiler::Settings::ABORT_VARIABLE}} {return 0}

		# Write simulator data file
		if {${::Compiler::Settings::CREATE_SIM_FILE}} {
			if {!${::Compiler::Settings::QUIET}} {
				if {${::Compiler::Settings::NOCOLOR}} {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "Creating assembler debug file ...\t-> \"%s\"" "${input_file_name}.adf"]
				} else {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "Creating simulator data file ...\t-> \"\033\[34;1m%s\033\[m\"" "${input_file_name}.adf"]
				}
			}
			makeBackupFile $current_dir "${input_file_name}.adf"
			if {[catch {
				set sim [open [file join $current_dir $input_file_name.adf] w 0640]
			}]} then {
				if {${::Compiler::Settings::NOCOLOR}} {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Error: Unable to open file \"%s]\" for writing" [file join $current_dir $input_file_name.adf]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Compilation FAILED !"]
				} else {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "\033\[31;1mError\033\[m: Unable to open file \"\033\[34;1m%s\033\[m\" for writing" [file join $current_dir $input_file_name.adf]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "\033\[31;1mCompilation FAILED !\033\[m"]
				}
				report_status $current_dir $input_file_name
				return 0
			} else {
				puts -nonewline $sim ${::assembler::adf}
				close $sim
			}
		}

		if {${::Compiler::Settings::ABORT_VARIABLE}} {return 0}

		# Report final status
		report_status $current_dir $input_file_name
		if {!${::Compiler::Settings::QUIET}} {
			if {${::Compiler::Settings::optim_ena}} {
				if {${::Compiler::Settings::NOCOLOR}} {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "Number of optimization performed: %s" ${::PreProcessor::optims}]
				} else {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[mc "Number of optimization performed: \033\[1m%s\033\[m" ${::PreProcessor::optims}]
				}
			}
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
					[::Compiler::msgc {SN}][mc "Compilation successful. (time: %s sec.)" [expr {[clock seconds] - $sec}]]
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
					[mc "\033\[32;1mCompilation successful.\033\[m (time: %s sec.)" [expr {[clock seconds] - $sec}]]
			}
		}

		# Successful
		return 1
	}

	## Free resureces reserved during compilation
	 # @return void
	proc free_resources {} {
		::assembler::free_resources
		::CodeListing::free_resources
		set ::PreProcessor::asm {}
		set ::PreProcessor::tmp_asm {}
	}

	## Report final status and write code listing file
	 # @parm String current_dir	- Working directory
	 # @parm String input_file_name	- Name of input file
	 # @return void
	proc report_status {current_dir input_file_name} {
		variable error_count	;# Number of errors occurred during compilation
		variable warning_count	;# Number of warning reported during compilation

		# Determinate name of code listing file
		if {${::Compiler::Settings::PRINT_FILE} != {}} {
			set print_file ${::Compiler::Settings::PRINT_FILE}
		} else {
			set print_file $input_file_name
			append print_file {.lst}
		}

		# Message "Creating code listing file"
		if {!${::Compiler::Settings::QUIET} && ${::Compiler::Settings::PRINT}} {
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
					[mc "Creating code listing file ...\t\t-> \"%s\"" $print_file]
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
					[mc "Creating code listing file ...\t\t-> \"\033\[34;1m%s\033\[m\"" $print_file]
			}
		}

		# Report number of errors and warning
		if {!${::Compiler::Settings::QUIET}} {
			if {$::TRANSLATION_LOADED} {
				set text [mc "%s errors, %s warnings" $error_count $warning_count]
			} else {
				set text "$error_count error"
				if {$error_count != 1} {
					append text "s"
				}
				append text ", $warning_count warning"
				if {$warning_count != 1} {
					append text "s"
				}
			}
			if {${::Compiler::Settings::NOCOLOR}} {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} $text
			} else {
				${::Compiler::Settings::TEXT_OUPUT_COMMAND} "\033\[1m$text\033\[m"
			}
		}

		# Write code listing file
		if {${::Compiler::Settings::PRINT}} {
			makeBackupFile $current_dir $print_file
			if {[catch {
				set lst [open [file join $current_dir $print_file] w 0640]
			}]} then {
				if {${::Compiler::Settings::NOCOLOR}} {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Error: Unable to open file \"%s\" for writing" [file join $current_dir $print_file]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND} [mc "Compilation FAILED !"]
				} else {
					${::Compiler::Settings::TEXT_OUPUT_COMMAND}	\
						[::Compiler::msgc {EN}][mc "Error: Unable to open file \"\033\[34;1m%s\033\[m\" for writing" [file join $current_dir $print_file]]
					${::Compiler::Settings::TEXT_OUPUT_COMMAND} [mc "\033\[31;1mCompilation FAILED !\033\[m"]
				}
				return 0
			} else {
				puts -nonewline $lst [CodeListing::getListing]
				close $lst
			}
		}
	}

	## Create backup copy of the specified file
	 # @parm String current_dir	- Working directory
	 # @parm String filename	- File name
	 # @parm String extension	- File extension
	 # @return void
	proc makeBackupFile {current_dir filename} {
		if {[file exists [file join $current_dir $filename]]} {
			catch {
				file rename -force	\
					[file join $current_dir $filename]	\
					"[file join $current_dir $filename]~"
			}
		}
	}

	## Namespace containing compiler settings
	namespace eval Settings {
		## Peephole optimization enable flag
		variable optim_ena		0	;# Bool: 0 == disabled; 1 == enabled

		## Memory limits
		variable iram_size		0x100	;# Internal data memory
		variable xram_size		0x10000	;# External data memory
		variable code_size 		0x10000	;# Overall program memory

		## Enable/Disable controls
		 # options:
		 #	0 - Controled by compiler
		 #	1 - Always
		 #	2 - Never
		variable _symbols		0	;# Control: $SYMBOLS
		variable _print			0	;# Control: $PRINT
		variable _object		0	;# Control: $OBJECT

		 # Options:
		 #	0 - use value defined in source code
		 #	1 - ignore
		variable _nomod			0	;# Control: $NOMOD
		variable _paging		0	;# Control: $PAGING
		variable _pagelength		0	;# Control: $PAGELENGTH(int)
		variable _pagewidth		0	;# Control: $PAGEWIDTH(int)
		variable _title			0	;# Control: $TITLE('string')
		variable _date			0	;# Control: $DATE('date')
		variable _list			0	;# Controls: $LIST $NOLIST; Directives: list nolist

		# Default values for some controls
		variable _object_file		{}	;# Location of IHEX8 object file
		variable _print_file		{}	;# Location of Code Listing file
		variable _title_value		{}	;# Title string for code listing
		variable _date_value		{}	;# Date string for code listing
		variable _nomod_value		0	;# Bool: use predefined SFR addresses
		variable _paging_value		0	;# Bool: Use Form Feeds in code listing
		variable _pagelength_value	0	;# Number of lines per page in code listing
		variable _pagewidth_value	132	;# Number of characters per line in code listing

		# Active settings
		variable SYMBOLS		{}	;# Bool: Include table of symbols to code listing
		variable NOMOD			{}	;# Bool: Do not use predefined SFR register addresses
		variable PAGING			{}	;# Bool: Use 'FF' in code listing
		variable PAGELENGTH		{}	;# Number of characters per line in code listing
		variable PAGEWIDTH		{}	;# Number of characters per line in code listing
		variable TITLE			{}	;# Title string for code listing
		variable DATE			{}	;# Date string for code listing
		variable OBJECT			{}	;# Bool: Generate IHEX8 object file
		variable OBJECT_FILE		{}	;# Location of IHEX8 object file
		variable PRINT			{}	;# Bool: Generate Code Listing file
		variable PRINT_FILE		{}	;# Location of Code Listing file
		variable INPUT_FILE_NAME	{}	;# Location of input file

		variable CREATE_SIM_FILE	1	;# Bool: Crete simulator data file
		variable CREATE_BIN_FILE	1	;# Bool: Create binary object code

		variable max_ihex_rec_length	16	;# Int: Maximum length of IHEX-8 record

		## Warning level
		 # 0 - all
		 # 1 - Errors + Warnings
		 # 2 - Errros only
		 # 3 - Nothing
		variable WARNING_LEVEL		0

		# Do not print what's going on
		variable QUIET			0
		# Update command (eg. 'update')
		variable UPDATE_COMMAND		{::Compiler::doNothing}
		# Bool: 1 == abort now
		variable ABORT_VARIABLE		0
		# Text output command (eg. 'puts')
		variable TEXT_OUPUT_COMMAND	{puts}
		# Disable color output
		variable NOCOLOR		1

		## Restore default settings
		 # @return void
		proc restoreDefaults {} {

			variable _symbols		;# Control: $SYMBOLS
			variable _print			;# Control: $PRINT
			variable _object		;# Control: $OBJECT

			variable SYMBOLS		;# Bool: Include table of symbols to code listing
			variable NOMOD			;# Bool: Do not use predefined SFR register addresses
			variable PAGING			;# Bool: Use 'FF' in code listing
			variable PAGELENGTH		;# Number of characters per line in code listing
			variable PAGEWIDTH		;# Number of characters per line in code listing
			variable TITLE			;# Title string for code listing
			variable DATE			;# Date string for code listing
			variable OBJECT			;# Bool: Generate IHEX8 object file
			variable OBJECT_FILE		;# Location of IHEX8 object file
			variable PRINT			;# Bool: Generate Code Listing file
			variable PRINT_FILE		;# Location of Code Listing file
			variable INPUT_FILE_NAME	;# Location of input file

			variable _object_file		;# Location of IHEX8 object file
			variable _print_file		;# Location of Code Listing file
			variable _title_value		;# Title string for code listing
			variable _date_value		;# Date string for code listing
			variable _nomod_value		;# Bool: use predefined SFR addresses
			variable _paging_value		;# Bool: Use Form Feeds in code listing
			variable _pagelength_value	;# Number of lines per page in code listing
			variable _pagewidth_value	;# Number of characters per line in code listing

			# Reset settings
			foreach	var {
					NOMOD		PAGING		PAGELENGTH		PAGEWIDTH
					TITLE		DATE		OBJECT_FILE		PRINT_FILE
				} default {
					_nomod_value	_paging_value	_pagelength_value	_pagewidth_value
					_title_value	_date_value	_object_file		_print_file
				} \
			{
				set $var [subst -nocommands "\$$default"]
			}

			# Finalize
			if {($_symbols == 1) || ($_symbols == 0)} {
				set SYMBOLS 1
			} elseif {$_symbols == 2} {
				set SYMBOLS 0
			}
			if {($_print == 1) || ($_print == 0)} {
				set PRINT 1
			} elseif {$_print == 2} {
				set PRINT 0
			}
			if {($_object == 1) || ($_object == 0)} {
				set OBJECT 1
			} elseif {$_object == 2} {
				set OBJECT 0
			}
		}
	}

	## Generate parser-friendly error code
	 # @parm String code - Basic message specification (e.g. EL means ERROR and LINE)
	 # @return Char - A special (unprintable) character represention the message
	proc msgc {code} {
		variable in_IDE		;# Bool: Running in IDE (I mean GUI)

		if {!$in_IDE} {
			return {}
		}

		switch -- $code {
			{EL} {	;# ERROR and LINE specification
				return "|EL|"
			}
			{EN}  {	;# Just ERROR
				return "|EN|"
			}
			{WL}  {	;# WARNING and LINE specification
				return "|WL|"
			}
			{WN}  {	;# Just WARNING
				return "|WN|"
			}
			{SN}  {	;# SUCCESS
				return "|SN|"
			}
		}
	}
}

# Compiler settings to defaults
Compiler::Settings::restoreDefaults

# >>> File inclusion guard
}
# <<< File inclusion guard