Module Intermediate


module Intermediate: sig .. end
This module contains all the informations about types, structures and classes that are used almost anywhere along the code; other specific objects are declared only where needed

type label = int 
Labels are numeric to simplify things

Register is an index for temporary variables

type register = int 
Offsets is how far the variable is from the stack pointer
type offset = int 

type return =
| SRet of Syntaxtree.bType (*For non-void subroutines*)
| Void (*For void subroutines*)
The return type of subroutines

type sType =
| DInt
| DFloat
| DBool
The Semantic type, used for semantic analisys

type inst_type =
| CPY (*Assignment*)
| AGET (*Get from array*)
| ASET (*Set into array*)
| ADD (*Sum*)
| SUB (*Subtraction*)
| MUL (*Multiplication*)
| DIV (*Quotient*)
| AND (*Logical AND*)
| OR (*Logical OR*)
| NOT (*Logical NOT*)
| CNE (*Compare if Not Equals*)
| CG (*Compare if Greater*)
| CGE (*Compare if Greater or Equals*)
| JNE (*Jump if Not Equals*)
| GOTO (*Goto*)
| PARAM (*Parameter for subroutine*)
| CALL (*Subroutines Call*)
| RET (*Return for subroutines*)
| NOP (*No Operation*)
| HALT (*End of program*)
| OUT (*Write on standard Output*)
Instructions for intermediate code

type value =
| I of int
| F of float
Type of values

type element =
| Reg of register * sType (*Register (or temporary variable) with his index and his type*)
| Off of offset * sType * bool (*Offset with his gap value, his type and a bool which indicates if is a variable defined on a subroutine or the main*)
| Label of label (*Label for a code point*)
| Val of value (*Numerical value*)
| Subr of string (*Subroutine name*)
| Null (*Null element*)
Element of intermediate code instruction
type instruction = inst_type * element * element *
element
The instruction code, the first operand, the second operand, the destination element
class funUtils : object .. end
The class contains all the method and objects which differ from one subroutine and the other, or the main program
class intermediateCode : object .. end
This class is a over-structure for the funUtils class, and has methods for the manage of global variables, like registers, which are indipendent from the function (main or subroutines) that is processed
type dec_table = (Syntaxtree.ide, int * int * element) Hashtbl.t 
A dec_table binds an ide (variable name) with 3 elements: 2 integers (x and y coordinate) and the element associated with the variable

type proc_entry =
| Building of return * Syntaxtree.dec list
| Subroutine of return * Syntaxtree.dec list * dec_table
* funUtils
A proc_entry can be in Building phase (which has the parameter types of the call and the return type) or a Subroutines (which contains all the informations for that function/procedure, such as the local variables declaration and the funUtils class for that subroutine)
type proc_table = (Syntaxtree.ide, proc_entry) Hashtbl.t 
The proc_table binds the name of a subroutine with its proc_entry