2 (** This module defines the abstract syntax tree of [Cminor]. *)
4 (* This file describes the abstract syntax of the Cminor language.
5 Only types are: int8, int16, int32 and void. *)
7 type etype = AST.sig_type
9 type expression = Expr of expr_descr * etype
13 | Op1 of AST.op1 * expression
14 | Op2 of AST.op2 * expression * expression
15 | Mem of AST.quantity * expression (* Memory read *)
16 | Cond of expression * expression * expression (* Ternary expression *)
17 | Exp_cost of CostLabel.t * expression (* Labelled expression *)
21 | St_assign of AST.ident * expression
22 | St_store of AST.quantity * expression * expression
24 (* Function call. Parameters are an optional variable to store the
25 result of the function, the name of the function, the arguments,
26 and finally its signature. *)
27 | St_call of AST.ident option * expression * expression list * AST.signature
29 (* Tail call to a function, that is, a call to a function following
30 by a return statement. Parameters are the name of the function,
31 the arguments and its signature. *)
32 | St_tailcall of expression * expression list * AST.signature
34 | St_seq of statement * statement
35 | St_ifthenelse of expression * statement * statement
36 | St_loop of statement
37 | St_block of statement
40 (* Switch. Parameters are the expression whose value is switch, a
41 table of cases and their corresponding number of blocks to exit,
42 and the number of block to exit in the default case. *)
43 | St_switch of expression * (int*int) list * int
45 | St_return of expression option
46 | St_label of AST.ident * statement
48 | St_cost of CostLabel.t * statement
51 type internal_function =
52 { f_return : AST.type_return ;
53 f_params : (AST.ident * etype) list ;
54 f_vars : (AST.ident * etype) list ;
55 f_stacksize : AST.abstract_size ;
59 | F_int of internal_function
60 | F_ext of AST.external_function
62 (* A program is a list of global variables and their initialization
63 datas, a list of function names and their definition, and the name
64 of the main function. *)
67 { vars : (AST.ident * AST.abstract_size * AST.data list option) list ;
68 functs : (AST.ident * function_def) list ;
69 main : AST.ident option }