module Pascal_ir: sig end
Abstract syntax tree with a Pascal looking-like structure.
Author(s): Samuel Mimram
exception Parse_error of (string * (int * int))
A parsing error occured. The arguments are the column and line numbers.
type
pascal_type =
Types of values.
type
nature =
| |
Varb |
| |
Cst |
| |
Funct |
| |
Unknown_nature |
Nature.
type
variable = {
|
var_name : string ; |
|
mutable var_type : pascal_type ; |
|
mutable var_def : definition option ; |
|
mutable var_nature : nature ; |
|
var_pos : int * int ; |
}
A reference to an identifier. var_by_name
is only meaningful for procedures' and functions' arguments (yet) and should be set to false
else.
type
expression = {
}
A typed expression.
type
expr =
An expression.
type
stt =
A statement.
type
statement = {
}
A decorated statement.
type
environment = (string * definition) list
An environment (a list of names and their value).
type
block = {
}
A block (i.e. a list of statements in an environment).
type
func = {
}
A procedure or a function.
type
value =
What an identifier can be.
type
asm_value =
Definition in the assembly side.
type
definition = {
|
def_name : string ; |
|
mutable def_type : pascal_type ; |
|
def_nature : nature ; |
|
mutable def_value : value ; |
|
def_pos : int * int ; |
|
mutable def_coord : int list ; |
|
mutable def_asm : asm_value ; |
|
def_pass_by_ref : bool ; |
}
An identifier definition.
Operations on environments.
|
exception Already_defined
A variable is being redefined.
val create_environment : unit -> environment
Create a new empty environment.
val fold_env : (string -> definition -> 'a -> 'a) ->
'a -> environment -> 'a
Fold a function throughout an environment.
val iter_env : (string -> definition -> unit) -> environment -> unit
Iter a function on all elements of an environment.
val env_of_def_list : definition list -> (string * definition) list
Get the environment corresponding to a list of variable definitions.
val add_def : environment ->
string -> definition -> (string * definition) list
Add a definition to an environment.
Raises Already_defined
if a previous definition was already made with the same name.
val get_def : environment -> string -> definition
Get a the value associated to a name in an environment. Remark: don't forget that procedures and functions are binders and should therefore be added to the current environment.
Raises Not_found
if no definition was made for that name.
val concat_env : bool ->
environment -> environment -> environment
Concatenate two environments. The first argument determines whereas the function should check for duplicate definitions or not.
val new_function : string ->
definition list ->
pascal_type ->
block -> int * int -> bool -> definition
Create a new function.
val string_of_type : pascal_type -> string
Get a human readable representation of a type.
type
program = string * block
A program.
val is_some : 'a option -> bool
Is a value equal to Some _?
val get_some : 'a option -> 'a
Get the value v
in a value equal to Some v
.
val eval_expr_int : expression -> int
Compute the value of a constant integer expression.
val eval_expr_bool : expression -> bool
Compute the value of a constant boolean expression.
val eval_expr : expression -> Asm_ir.value
Compute the value of a constant expression.
exception Asm_error of string
An error occured during the pascal-to-asm conversion.
val sizeof : pascal_type -> int
Get the size needed by a type (in bytes).
val asm_type : pascal_type -> Asm_ir.var_type
Get the asm type corresponding to a pascal type.
val check_block : block ->
environment list -> pascal_type -> unit
Do several checks on a block:
- check that called variables
- check data types
Raises Parse_error
if an error was detected.
rettype
: the type of the returned value
val opt_useless : 'a * block -> unit
Mark def_used
of used procedures.
val define_glibb : 'a * block -> unit
Add the definitions of the our external glibb procedures.
val check : 'a * block -> unit
Check that the program is syntaxically and lexically correct.
val string_of_expression : expression -> string
Get a human readable representation of an expression.
val pretty_print : string * block -> string
Get a nice human-readable representation of a pascal ast.
val is_constant : expression -> bool
Is an expression a constant?
val asm_of_proc : string ->
func ->
pascal_type -> int list -> Asm_ir.procedure list * Asm_ir.procedure
Get an asm-like AST corresponding to a pascal-like AST.
Returns a list of procedures incidently defined and the Asm_ir.procedure
corresponding to the procedure.
val asm_of_prog : 'a * block -> Asm_ir.program
Get the asm IR of a program.