| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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 * node list
- | ArrayDef of ctype * node list
- and node =
- (* global *)
- | Program of node list * loc
- | Param of ctype * string * loc
- | Dim of 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
- | 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
- (* additional types for convenience in traversals *)
- | VarUse of node * ctype * int
- | FunUse of node * ctype * int
- | Type of ctype
- | DimDec of node
- | Arg of node
- (* container for command-line arguments *)
- type args = {
- mutable infile : string option;
- mutable outfile : string option;
- mutable verbose : int;
- mutable cpp : bool;
- }
- (* intermediate representations between phases *)
- type intermediate =
- | Args of args
- | FileContent of string * string * args
- | Ast of node * args
- | Assembly of string list * args
- (* exceptions *)
- exception LocError of loc * string
- exception NodeError of node * string
- exception CompileError of string
- exception EmptyError
- exception InvalidNode
- exception InvalidInput of string
- (*
- * 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
- *
- *)
|