module Asm_ir: sig end
Abstract syntax tree with an assembly looking-like structure.
Author(s): Samuel Mimram
exception Asm_error of string
An error during the generation of the assembly.
type
value =
| |
Int of int |
| |
Bool of bool |
Pseudo-typed values for assembly.
type
var_type =
| |
Boolean |
| |
Integer |
| |
Pointer |
| |
Other of int |
| |
No_type |
Type of variables.
val sizeof : var_type -> int
Get the size in memory, in bytes, needed by a type.
type
xflag =
| |
Aflag |
| |
Bflag |
| |
Eflag |
| |
Zflag |
| |
Gflag |
| |
Lflag |
| |
Cflag |
| |
Oflag |
| |
Pflag |
| |
Sflag |
| |
Vflag of variable |
Kinds of flags.
type
flag = {
|
flag_not : bool ; |
|
flag_flag : xflag ; |
|
flag_eq : bool ; |
}
A flag.
type
register =
| |
Reg_int of int |
| |
Reg_flag of flag |
A register.
type
stack_pos =
| |
Pos_base of int |
| |
Pos_stack of int |
| |
Pos_label of string |
| |
Pos_arr of (variable * variable * int * int) |
| |
Pos_rec of (variable * int) |
| |
Pos_pointed of variable |
| |
Pos_none |
A position on the stack.
type
variable_def = {
|
mutable vd_ident : int ; |
|
mutable vd_pos : stack_pos Pervasives.ref ; |
|
mutable vd_type : var_type Pervasives.ref ; |
|
mutable vd_lex_depth : int Pervasives.ref ; |
|
mutable vd_value : value option ; |
|
mutable vd_on_the_stack : bool Pervasives.ref ; |
}
A variable definition.
The ref
are here because they should be shared between variable definitions.
type
variable = {
}
A variable.
val neg_flag : flag -> flag
Get the negated version of a flag.
val commute_flag : flag -> flag
Find the flag with arguments swapped (e.g. x < y ~ y > x).
val vd_counter : int Pervasives.ref
Fresh identifiers generator.
val new_var_def : var_type -> int -> variable_def
new_var_def type depth
generates a new variable definition.
val new_var : variable_def -> variable
Create a new variable.
val new_const_int_var : int -> int -> variable
new_const_int_var n depth
creates a new variable which is a constant integer equal to n
.
val copy_var_def : variable_def -> variable_def
Get a copy of a variable definition.
val copy_var : variable -> variable
Get a copy of a variable.
val get_var_reg : variable -> register
Get the register in which a variable is stored.
val set_var_reg : variable -> register -> unit
val get_vd_type : variable_def -> var_type
val get_var_type : variable -> var_type
val get_vd_lex : variable_def -> int
Get the lexical depth of a variable definition.
val get_var_lex : variable -> int
Get the lexical depth of a variable.
val get_vd_pos : variable_def -> stack_pos
Get the position of a variable definition on the stack.
val get_var_pos : variable -> stack_pos
Get the position of a variable on the stack.
val get_vd_ots : variable_def -> bool
Is a variable definition on the stack?
val get_var_ots : variable -> bool
Is a variable on the stack?
val set_vd_ots : variable_def -> unit
val set_var_ots : variable -> unit
val get_vd_value : variable_def -> value option
val get_var_value : variable -> value option
type
procedure = {
|
proc_name : string ; |
|
proc_args : variable_def list ; |
|
mutable proc_vars : variable_def list ; |
|
mutable proc_value : base_block ; |
|
mutable proc_lex_depth : int ; |
|
mutable proc_stack_size : int ; |
|
mutable proc_is_fun : bool ; |
}
A procedure.
type
program = {
|
mutable prog_source_name : string ; |
|
prog_procs : procedure list ; |
|
prog_max_depth : int ; |
}
A program.
type
meta_instr =
A meta instruction (an instruction which has several base blocks as argument).
type
instr =
An assembly instruction.
type
base_block = {
}
A base block.
val new_base_block : meta_instr -> base_block
Create a new base block.
val proc_stub : string -> variable_def list -> int -> procedure
Create a stub for a procedure, given its name, arguments and lexical depth.
val is_constant : variable -> bool
Is a variable a constant?
val commute_instr : instr -> instr
Use commutativity on an instruction.