Module Asm_ast


module Asm_ast: sig  end
Abstract syntax tree with an assembly looking-like structure.
Author(s): Samuel Mimram, Julien Cristau

val assocp : 'a -> ('a * 'b) list -> 'b
Just like List.assoc but with physical equlity as test.

type value =
| Integer of int
| Boolean of bool
Pseudo-typed values for assembly.

type variable_def = {
   vd_pos : int; (*position, in bytes, relative to the frame pointer position*)
   vd_size : int; (*size, in bytes*)
   mutable vd_value : value option; (*for constants*)
   vd_by_ref : bool; (*is the value passed by reference?*)
   vd_on_the_stack : bool; (*should some space be allocated on the stack for the variable by default? (should be false for booleans and integers by default)*)
}
A variable definition.

type variable = {
   mutable var_reg : int option; (*number of its register*)
   mutable var_def : variable_def; (*position of the variable on the stack*)
   mutable var_spilled : bool; (*the variable should be fetched in memory*)
   mutable var_to_spill : bool; (*the variable should be spilled ater having been used*)
}
A variable.

type procedure = {
   proc_name : string;
   proc_vars : variable_def list;
   proc_value : base_block;
}
type meta_instr =
| If of (variable * base_block * base_block
* base_block)
| While of (variable * base_block * base_block)
| End
A meta instruction (has several base blocks as argument).

type instr =
| Addi of (variable * variable * variable) (*x1 <- x2 + x3 where the xi are integers (replaces x2!)*)
| Movi of (variable * variable) (*x1 <- x2 where the xi are integers*)
| Movb of (variable * variable) (*x1 <- x2 where the xi are booleans*)
| Call of (string * variable list) (*a procedure call, the list of arguments is in reverse order*)
| ExtCall of (string * variable list) (*an hardcoded (/ external ?) procedure call*)
| Nop
An assembly instruction. For operators of arity three, the third operand should be allocated in the same register as the first one when it's possible.

type base_block = {
   mutable bb_block : instr list;
   bb_link : meta_instr;
}
A base block.
val allocate_registers : base_block -> unit
Do the registers allocation (simple version).

type var_gen = {
   vg_const : bool; (*generate constant values*)
   vg_stack : bool; (*generate stack addresses*)
}
val generate_code : string -> procedure list -> string
Generate the target asm.