module Target: sig
.. end
Contains all the functions to generate the tagret code from the intermediate code instructions list
All this methods return unit, or the string which has to be printed out
Contains all the functions to generate the tagret code from the intermediate code instructions list
All this methods return unit, or the string which has to be printed out
val header : string
The header of the target code
val newstack_pointer : int -> string
Initialize a new stack-pointer
n
: The stack-pointer's initial value
val main_start : int -> string
The signature of the main function, with the first instructions for initialization
n
: The number of global variables, used to initialize the stack-pointer's value
val main_end : string
The end of the main
val getElementType : Intermediate.element -> string
Used to recover the type of data contained into an element (int or float)
Raises TYPE_ERROR
If the program is unable to retrive the type
e
: The element to check
val c_element : Intermediate.element -> string
If the element is a declared variable, then if the boolean stored into the element is true (which means that
is an element declared into a function/procedure) we have to calculate the offset from the basepointer,
otherwise we calculate it directly into the stack. Positive offsets are for variables, negative for parameters
Raises TYPE_ERROR
If the program is unable to find the type (e.g. the type is Bool, but into the memory there
are only int and float)
e
: The element to recover
val array_get : Intermediate.element -> Intermediate.element -> string
Used to calculate the offset for a vector, with the same controls used for normal elements
Raises CONFIRM_RULE
If this method is called for something that is not a vector (never occurs)
v
: The offset for the vector
x
: The offset from the vector to the selected element
val c_subroutine : Intermediate.element -> Intermediate.element -> string
If the c element is null, it means that the subroutine is void, so we have only to call it, otherwise c is the
temporary variable where the return value is stored
a
: The function call
c
: The (optional) return register
val push_single_param : Pervasives.out_channel -> Intermediate.element -> unit
Pushes a single parameter, incrementing the stackpointer and copying his value in the pointed location
out
: The output channel
p
: The element to push
val push_params : Intermediate.element ->
Intermediate.element list ->
Intermediate.proc_table -> Pervasives.out_channel -> unit
Pushes all the list of parameters retrieved for the procedures table
Raises CONFIRM_RULE
If the entry into the table is Building or the element isn't a subroutine (never occurs)
a
: The function call
pl
: The list of actual parameters
proct
: The subroutines table
out
: The output channel
val c_instruction : Intermediate.instruction ->
Pervasives.out_channel ->
Intermediate.element list ->
Intermediate.proc_table -> Intermediate.element list
Conver the intermediate code instructions into the target code instructions
Raises CONFIRM_RULE
If the OUT instruction is called with something that is not a variable (never occurs)
i
: The instruction to convert
out
: The output channel
pl
: The list of parameters to pass to a function call
proct
: The subroutines table
val c_generator : Intermediate.instruction list ->
Intermediate.intermediateCode ->
Pervasives.out_channel ->
int -> Intermediate.element list -> Intermediate.proc_table -> unit
Generates the target code for all the elements of the instructions list
il
: The list of instructions
ic
: The intermediateCode class instance
out
: The output channel
n
: The index of the next instruction, used to check the label table
pl
: The temporary parameter list
proct
: The subroutines table
val print_return : Intermediate.return -> string
Prints the return type of the subroutines
r
: The return type
val c_procedure : Pervasives.out_channel ->
Intermediate.intermediateCode ->
Intermediate.proc_table -> Syntaxtree.ide -> Intermediate.proc_entry -> unit
Generates the target code for the subroutines, using the stored funUtils instance
Raises CONFIRM_RULE
When the proc_entry is Building (never occurs)
out
: The output channel
ic
: The intermediateCode class instance
proct
: The subroutines table
p
: The entry binded with the subroutine name
val c_subroutines : Pervasives.out_channel ->
Intermediate.proc_table -> Intermediate.intermediateCode -> unit
Calls the c_procedure method for all the entries of the procedure table
out
: The output channel
proct
: The subroutines table
ic
: The intermediateCode class instance