english
version "1.0"
identify "xyz"

#: This module implements the microcontroller assembler assembler types.

module types

define assembler			#: Assembler
    record
	buffer string			#: Listing buffer
	byte_count unsigned		#: Bytes for current instruction
	configure_address unsigned	#: Address for configuration word
	debug_stream out_stream		#: Debug stream
	errors errors			#: Error count
	error_buffer string		#: Error buffer
	error_stream out_stream		#: Error output stream
	listing_stream out_stream	#: Listing stream
	maximum_address unsigned	#: Maximum code address
	maximum_register unsigned	#: Maximum register number
	memory_image memory_image	#: Memory image
	next_program_counter unsigned	#: Next program counter
	out_stream out_stream		#: Output stream
	pass unsigned			#: Assembler pass (1 or 2)
	pic_type pic_type		#: Type of PIC processor
	program_counter unsigned	#: Current program counter
	standard_out out_stream		#: Standard output
	statement statement		#: Current statement
	word_size word_size		#: Intruction word size
    generate allocate, erase, print

define assembler1[type1]		#: Assembler error type
    record
	zilch unsigned			#: Filler
    generate allocate, erase, print

define assembler2[type1, type2]		#: Assembler error type
    record
	zilch unsigned			#: Filler
    generate allocate, erase, print

define assembler3[type1, type2, type3]	#: Assembler error type
    record
	zilch unsigned			#: Filler
    generate allocate, erase, print

define binary				#: Binary opcode
    record
	left expression			#: Left expression
	right expression		#: Right expression
    generate address_get, allocate, erase, identical, print

define binary_opcode			#: Binary opcode
    record
	source expression		#: Source expression
	destination destination		#: Destination
    generate address_get, allocate, erase, identical, print

define bit_address			#: Address of a single bit
    record
	bit_number unsigned		#: Bit number
	xregister unsigned		#: Register number
    generate address_get, allocate, erase, identical, print

define configure			#: Configuration word
    record
	brown_out_enable logical	#: BODEN
	code_protect logical		#: Code protect
	mclr_enable logical		#: MCLR enable
	oscillator oscillator		#: Oscillator
	power_up_timer_enable logical	#: Power up timer
	watch_dog_timer_enable logical	#: WDTE
    generate address_get, allocate, erase, identical, print

define destination			#: Result destination
    enumeration
	f				#: Register File
	w				#: W Register
    generate equal, print, unsigned_convert

define expression			#: Opcode expression argument 
    variant type expression_type	#: Expresion type
	add binary			#: Sum of two expressions
	bit_address binary		#: Bit address (aaa.b)
	character character		#: Character constant
	code_address unsigned		#: Code address
	decimal unsigned		#: Unsigned decimal number
	divide binary			#: Divide two expressions
	hexadecimal unsigned		#: Unsigned hexadecimal number
	multiply binary			#: Product of two expressions
	octal unsigned			#: Unsigned octal number
	string string			#: Quoted string
	subtract binary			#: Difference of two expressions
	symbol symbol			#: Symbolic value
	xregister unsigned		#: Register number
    generate address_get, allocate, erase, identical, print

define expression_type			#: Opcode expression type
    enumeration
	add				#: Sum of two expressions
	bit_address			#: Bit address (aaa.b)
	character			#: Character constant
	code_address			#: Code address
	decimal				#: Unsigned decimal number
	divide				#: Divide
	hexadecimal			#: Unsigned hexadecimal number
	multiply			#: Multiply
	octal				#: Unsigned octal number
	string				#: Quoted string
	subtract			#: Difference of two expressions
	symbol				#: Symbolic value
	xregister			#: Register number
    generate print

define memory_image			#: Memory image
    record
	bytes vector[unsigned]		#: Bytes of memory
	uninitialized unsigned		#: Uninitialized value
    generate address_get, allocate, erase, identical, print

define opcode				#: Opcode (or pseudo opcode)
    variant type opcode_type		#: Opcode type
	addlw expression		#: ADDWL k
	address_equate binary		#: name: EQU value
	addwf binary_opcode		#: ADDWF f,d
	andlw expression		#: ANDWL k
	andwf binary_opcode		#: ANDWF f,d
	bcf expression			#: BCF f,b
	bit_address_define trinary	#: #define name register, number
	blank bogus			#: BLANK
	bsf expression			#: BSF f,b
	btfsc expression		#: BTFSC f,b
	btfss expression		#: BTFSS f,b
	configure configure		#: CONFIG osc, wdte, pwrte, cp
	call expression			#: CALL k
	clrf expression			#: CLRF f
	clrw bogus			#: CLRW
	clrwdt bogus			#: CLRWDT
	comf binary_opcode		#: COMF f,d
	comment string			#: Comment
	constant_equate binary		#: name: EQU value
	decf binary_opcode		#: DECF f,d
	decfsz binary_opcode		#: DECFSZ f,d
	end bogus			#: END
	goto expression			#: GOTO k
	incf binary_opcode		#: INCF f,d
	incfsz binary_opcode		#: INCFSZ f,d
	iorlw expression		#: IORLW k
	iorwf binary_opcode		#: IORWF f,d
	label expression		#: label:
	movf binary_opcode		#: MOVF f,d
	movlw expression		#: MOVLW k
	movwf expression		#: MOVWF f
	nop bogus			#: NOP
	origin expression		#: ORG k
	option bogus			#: OPTION
	processor processor		#: PROCESSOR processor
	register_equate binary		#: name: EQU exp
	retfie bogus			#: RETFIE
	retlw expression		#: RETLW k
	xreturn bogus			#: RETURN
	rlf binary_opcode		#: RLF f,d
	rrf binary_opcode		#: RRF f,d
	sleep bogus			#: SLEEP
	sublw expression		#: SUBLW k
	subwf binary_opcode		#: SUBWF f,d
	swapf binary_opcode		#: SWAPF f,d
	tris expression			#: TRIS f (f=5,6,7)
	xorlw expression		#: XORLW k
	xorwf binary_opcode		#: XORWF f,d
    generate address_get, allocate, erase, identical, print

define oscillator			#: Oscillator type
    enumeration
	extrc				#: External Resistor/Capacitor
	intrc				#: Internal Resistor/Capacitor
	rc				#: Resistor/Capacitor
	hs				#: High Speed Crystal/Resonator
	xt				#: Crystal/Resonator
	lp				#: Low Power Crystal
    generate print

define pic_type				#: Pic processor type
    enumeration
	pic12c508
	pic12c509
	pic16c63a
	pic16c73b
	pic16f84
	pic16c5x
    generate print

define processor			#: Processor info
    record
	pic_type pic_type		#: Processor type
    generate address_get, allocate, erase, identical, print


define program				#: Program
    record
	debug_stream out_stream		#: Debugging stream
	statements vector[statement]	#: Program statements
	symbol_table symbol_table	#: Symbol table to use
    generate address_get, allocate, erase, identical, print

define reference			#: Symbol reference
    record
	address unsigned		#: Reference address
	line_number unsigned		#: Line number reference occurred on
	size unsigned			#: Number of bytes of reference
	offset unsigned			#: Reference offset
    generate allocate, erase, identical, print

define statement			#: One assembler statement
    record
	line_number unsigned		#: Statement line number
	opcode opcode			#: Opcode (never ??)
	comment string			#: Trailing comment (or ??)
    generate address_get, allocate, erase, identical, print

define trinary				#: Trinary opcode
    record
	left expression			#: Left expression
	middle expression		#: Middle expression
	right expression		#: Right expression
    generate address_get, allocate, erase, identical, print

define symbol				#: Assembler symbol
    record
	defined logical			#: {true}=>symbol defined
	line_number unsigned		#: line number where symbol is defined
	name string			#: Symbol name
	references vector[reference]	#: Symbol references
	value value			#: Symbol value (and type)
    generate address_get, allocate, erase, identical, print

define symbol_table			#: Symbol table
    record
	symbol symbol			#: Temporary symbol (for lookup)
	symbols vector[symbol]		#: List of all symbols
	table set[symbol]		#: Table
    generate address_get, allocate, erase, identical, print

define value				#: Expression value
    variant type value_type		#: Value type
	bit_address bit_address		#: Bit address
	constant unsigned		#: Constant
	code_address unsigned		#: Code address
	string string			#: String
	undefined bogus			#: Undefined (i.e. error)
	w bogus				#: W register
	xregister unsigned		#: Register
    generate address_get, allocate, erase, identical, print

define value_type			#: Expression value type
    enumeration
	bit_address			#: Bit address
	constant			#: Constant
	code_address			#: Code address
	string				#: String
	undefined			#: Undefined (i.e. error)
	w				#: W register
	xregister			#: Register
    generate print

define word_size			#: Instruction word size
    enumeration
	word12				#: 12-bit instructions
	word14				#: 14-bit instructions
    generate print