| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- type loc = string * int * int * int * int
- let noloc = ("", 0, 0, 0, 0)
- type monop = Neg | Not
- type binop = Add | Sub | Mul | Div | Mod
- | Eq | Ne | Lt | Le | Gt | Ge
- | And | Or
- type ctype = Void | Bool | Int | Float
- | ArrayDec of ctype * string list
- | ArrayDef of ctype * node list
- and node =
- (* global *)
- | Program of node list * loc
- | Param of ctype * string * loc
- | FunDec of ctype * string * node list * loc
- | FunDef of bool * ctype * string * node list * node * loc
- | GlobalDec of ctype * string * loc
- | GlobalDef of bool * ctype * string * node option * loc
- (* statements *)
- | VarDec of ctype * string * node option * loc
- | Assign of string * node * loc
- | Return of node * loc
- | If of node * node * loc
- | IfElse of node * node * node * loc
- | While of node * node * loc
- | DoWhile of node * node * loc
- | For of string * node * node * node * node * loc
- | Allocate of string * node list * loc
- | Expr of node
- | Block of node list
- (* expressions *)
- | BoolConst of bool * loc
- | IntConst of int * loc
- | FloatConst of float * loc
- | ArrayConst of node list * loc
- | ArrayScalar of node * loc
- | Var of string * loc
- | VarUse of node * node ref * int
- | Deref of string * node list * loc
- | Monop of monop * node * loc
- | Binop of binop * node * node * loc
- | Cond of node * node * node * loc
- | TypeCast of ctype * node * loc
- | FunCall of string * node list * loc
- (* intermediate representations between phases *)
- type repr =
- | Inputfile of string option * int (* filename, verbose *)
- | Node of node * int (* ast, verbose *)
- | Assembly of string list * int (* instructions *)
- exception LocError of string * loc
- exception CompileError of string
- exception InvalidNode
- (*
- * Template for node matching follows below.
- *
- * let rec visit = function
- * | Program (decls, loc) ->
- * | Param (ctype, name, loc) ->
- * | FunDec (ret_type, name, params, loc) ->
- * | FunDef (export, ret_type, name, params, body, loc) ->
- * | GlobalDec (ctype, name, loc) ->
- * | GlobalDef (export, ctype, name, None, loc) ->
- * | GlobalDef (export, ctype, name, Some init, loc) ->
- *
- * | VarDec (ctype, name, None, loc) ->
- * | VarDec (ctype, name, Some init, loc) ->
- * | Assign (name, value, loc) ->
- * | Return (value, loc) ->
- * | If (cond, body, loc) ->
- * | IfElse (cond, true_body, false_body, loc) ->
- * | While (cond, body, loc) ->
- * | DoWhile (cond, body, loc) ->
- * | For (counter, start, stop, step, body, loc) ->
- * | Expr (value) ->
- *
- * | BoolConst (value, loc) ->
- * | IntConst (value, loc) ->
- * | FloatConst (value, loc) ->
- * | ArrayConst (dims, loc) ->
- * | ArrayScalar (value, loc) ->
- * | Var (name, loc) ->
- * | Deref (name, dims, loc) ->
- * | Monop (op, value, loc) ->
- * | Binop (op, left, right, loc) ->
- * | Cond (cond, true_expr, false_expr, loc) ->
- * | TypeCast (ctype, value, loc) ->
- * | FunCall (name, args, loc) ->
- *
- * | Statements (stats) ->
- *
- * | node -> transform visit node
- *
- *)
|