english
version "1.0"
identify "xyz"

#: This module defines the basic PIC stuff.

module program


#: {program} routines:

procedure append@program
    takes
	program program
	comment string
    returns opcode

    #: This procedure will create a statement containing a newly created
    #, {opcode} and append it to {program}.  The new {opcode} is returned.
    #, The {opcode} is labeled with {comment}.


procedure create@program
    takes
	symbol_table symbol_table
	debug_stream out_stream
    returns program

    #: This procedure will `create' and return a new program object
    #, using {symbol_table}.


procedure address_equ@program
    takes
	program program
	constant_name expression
	constant_value expression
	comment string
    returns_nothing

    #: This procedure will create and return an EQU opcode for a constant.


procedure const_equ@program
    takes
	program program
	constant_name expression
	constant_value expression
	comment string
    returns_nothing

    #: This procedure will create and return an EQU opcode for a constant.


procedure get@program
    takes_nothing
    returns program

    #: This procedure will return the {program} object.


procedure opcode_append@program
    takes
	program program
	opcode opcode
	comment string
    returns_nothing

    #: This procedure will create a statement containing {opcode} and
    #, optionally {comment} append it to {program}.


procedure output@program
    takes
	program program
	out_stream out_stream
    returns_nothing

    #: This procedure will output {program} to {out_stream}.


procedure statement_append@program
    takes
	program program
	statement statement
    returns_nothing

    #: This procedure will append {statement} to {program}.


# Opcode routines:

procedure addwf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an ADDWF opcode.


procedure andlw@program
    takes
	program program
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an AnDLW opcode.


procedure andwf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an ANDWF opcode.


procedure bcf@program
    takes
	program program
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BCF opcode.


procedure bit_addr_equ@program
    takes
	program program
	bit_name expression
	register_name expression
	bit_number expression
	comment string
    returns_nothing

    #: This procedure will generate a bit DEFINE {bit_name} to be the
    #, {bit_number}'th bit of register {register_name}.


procedure bsf@program
    takes
	program program
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BSF opcode.


procedure btfsc@program
    takes
	program program
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BTFSC opcode.


procedure btfss@program
    takes
	program program
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BTFSS opcode.


procedure call@program
    takes
	program program
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an CALL opcode.


procedure clrf@program
    takes
	program program
	xregister expression
	comment string
    returns_nothing

    #: This procedure will generate an CLRF opcode.


procedure clrw@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate an CLRW opcode.


procedure clrwdt@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate an CLRWDT opcode.


procedure comf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an COMF opcode.


procedure configure@program
    takes
	program program
	oscillator oscillator
	watch_dog_timer_enable logical
	power_up_timer_enable logical
	code_protect logical
	mclr_enable logical
	brown_out_enable logical
	comment string
    returns_nothing

    #: This procedure will generate a CONFIGURE opcode


procedure decf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an DECF opcode.


procedure decfsz@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an DECFSZ opcode.


procedure goto@program
    takes
	program program
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an GOTO opcode.


procedure incf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an INCF opcode.


procedure incfsz@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an INCFSZ opcode.


procedure iorlw@program
    takes
	program program
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an IORLW opcode.


procedure iorwf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an IORWF opcode.


procedure movf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an MOVF opcode.


procedure movlw@program
    takes
	program program
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an MOVLW opcode.


procedure movwf@program
    takes
	program program
	xregister expression
	comment string
    returns_nothing

    #: This procedure will generate an MOVWF opcode.


procedure nop@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate an NOP opcode.


procedure option@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate an OPTION opcode.


procedure processor@program
    takes
	program program
	pic_type pic_type
        comment string
    returns_nothing

    #: This procedure will generate a PROCESSOR opcode.


procedure reg_equ@program
    takes
	program program
	register_name expression
	register_value expression
	comment string
    returns_nothing

    #: This procedure will create and return an EQU opcode for a register.


procedure retlw@program
    takes
	program program
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an RETLW opcode.


procedure rlf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an RLF opcode.


procedure rrf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an RRF opcode.


procedure sleep@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate an SLEEP opcode.


procedure subwf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an SUBWF opcode.


procedure swapf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an SWAPF opcode.


procedure tris@program
    takes
	program program
	xregister expression
	comment string
    returns_nothing

    #: This procedure will generate an TRIS opcode.


procedure xorlw@program
    takes
	program program
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an XORLW opcode.


procedure xorwf@program
    takes
	program program
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an XORWF opcode.


procedure bit_addr_equ
    takes
	bit_name string
	register_name expression
	bit_number expression
	comment string
    returns expression

    #: This procedure will define {bit_name} to be the {bit_number}'th
    #, bit of {register_name}.


procedure blank@program
    takes
	program program
    returns_nothing

    #: This procedure will generate a blank line.


procedure comment@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a full-line comment containing
    #, {comment}.


procedure address_equ
    takes
	constant_name string
	constant_value expression
	comment string
    returns expression

    #: This procedure will define {constant_name} to be equivalant
    #, to {constantr_value}.


procedure const_equ
    takes
	constant_name string
	constant_value expression
	comment string
    returns expression

    #: This procedure will define {constant_name} to be equivalant
    #, to {constantr_value}.


procedure end@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate an end pseudo append@(program, comment).


procedure xlabel@program
    takes
	program program
	label_name expression
	comment string
    returns_nothing

    #: This procedure will create a label named {label_name} in {program}.


procedure org@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will set the program counter origin.
    

procedure reg_equ
    takes
	register_name string
	register_value expression
	comment string
    returns expression

    #: This procedure will define {register_name} to be equivalant
    #, to {register_value}.


#: Global routines that implement opcode functionality:

procedure addwf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an ADDWF opcode.


procedure andlw
    takes
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an ANDLW opcode.


procedure andwf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an ANDWF opcode.


procedure bcf
    takes
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BCF opcode.


procedure bsf
    takes
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BSF opcode.


procedure btfsc
    takes
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BTFSC opcode.


procedure btfss
    takes
	register_bit expression
	comment string
    returns_nothing

    #: This procedure will generate BTFSS opcode.


procedure call
    takes
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an CALL opcode.


procedure clrf
    takes
	xregister expression
	comment string
    returns_nothing

    #: This procedure will generate an CLRF opcode.


procedure clrw
    takes
	comment string
    returns_nothing

    #: This procedure will generate an CLRW opcode.


procedure clrwdt
    takes
	comment string
    returns_nothing

    #: This procedure will generate an CLRWDT opcode.


procedure comf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an COMF opcode.


procedure configure
    takes
	oscillator oscillator
	watch_dog_timer_enable logical
	power_up_timer_enable logical
	code_protect logical
	mclr_enable logical
	brown_out_enable logical
	comment string
    returns_nothing

    #: This procedure will generate a CONFIGURE opcode


procedure decf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an DECF opcode.


procedure decfsz
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an DECFSZ opcode.


procedure goto
    takes
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an GOTO opcode.


procedure incf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an INCF opcode.


procedure incfsz
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an INCFSZ opcode.


procedure iorlw
    takes
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an IORLW opcode.


procedure iorwf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an IORWF opcode.


procedure movf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an MOVF opcode.


procedure movlw
    takes
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an MOVLW opcode.


procedure movwf
    takes
	xregister expression
	comment string
    returns_nothing

    #: This procedure will generate an MOVWF opcode.


procedure nop
    takes
	comment string
    returns_nothing

    #: This procedure will generate an NOP opcode.


procedure option
    takes
	comment string
    returns_nothing

    #: This procedure will generate an OPTION opcode.


procedure processor
    takes
	pic_type pic_type
	comment string
    returns_nothing

    #: This procedure will generate a PROCESS opcode.


procedure ret
    takes
	comment string
    returns_nothing

    #: This procedure will generate an RETLW 0 opcode.


procedure retlw
    takes
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an RETLW opcode.


procedure rlf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an RLF opcode.


procedure rrf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an RRF opcode.


procedure sleep
    takes
	comment string
    returns_nothing

    #: This procedure will generate an SLEEP opcode.


procedure subwf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an SUBWF opcode.


procedure swapf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an SWAPF opcode.


procedure tris
    takes
	xregister expression
	comment string
    returns_nothing

    #: This procedure will generate an TRIS opcode.


procedure xorlw
    takes
	immediate expression
	comment string
    returns_nothing

    #: This procedure will generate an XORLW opcode.


procedure xorwf
    takes
	source expression
	destination destination
	comment string
    returns_nothing

    #: This procedure will generate an XORWF opcode.


# Non-opcode based statements:

procedure blank
    takes_nothing
    returns_nothing

    #: This procedure will generate a blank line.


procedure comment
    takes
	comment string
    returns_nothing

    #: This procedure will generate a full-line comment containing
    #, {comment}.


procedure end
    takes
	comment string
    returns_nothing

    #: This procedure will generate an end pseudo 


procedure xlabel
    takes
	label_name expression
	comment string
    returns_nothing

    #: This procedure will generate a label definition line containing
    #, {label_name}.  {label_name} must be an {expression} of type {symbol}.


procedure org
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will set the program counter origin.
    

procedure system_defines
    takes
	pic_type pic_type
	comment string
    returns_nothing

    #: This procedure will generate an TRIS opcode.