annotate lab4/optree.mli @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
mike@0 1 (* lab4/keiko.mli *)
mike@0 2 (* Copyright (c) 2017 J. M. Spivey *)
mike@0 3
mike@0 4 (* |op| -- type of picoPascal operators *)
mike@0 5 type op = Plus | Minus | Times | Div | Mod | Eq
mike@0 6 | Uminus | Lt | Gt | Leq | Geq | Neq
mike@0 7 | And | Or | Not | Lsl | Lsr | Asr | BitAnd | BitOr | BitNot
mike@0 8
mike@0 9 val fOp : op -> Print.arg
mike@0 10
mike@0 11 (* |symbol| -- global symbols *)
mike@0 12 type symbol = string
mike@0 13
mike@0 14 val nosym : symbol
mike@0 15
mike@0 16 val gensym : unit -> symbol
mike@0 17
mike@0 18 (* |codelab| -- type of code labels *)
mike@0 19 type codelab
mike@0 20
mike@0 21 val nolab : codelab
mike@0 22
mike@0 23 (* |label| -- generate a code label *)
mike@0 24 val label : unit -> codelab
mike@0 25
mike@0 26 val fLab : codelab -> Print.arg
mike@0 27
mike@0 28 (* |inst| -- type of intermediate instructions *)
mike@0 29 type inst =
mike@0 30 CONST of int (* Constant (value) *)
mike@0 31 | GLOBAL of symbol (* Global address (symbol) *)
mike@0 32 | LOCAL of int (* Local address (offset) *)
mike@0 33 | REGVAR of int (* Register (index) *)
mike@0 34 | LOADC (* Load char *)
mike@0 35 | LOADW (* Load word *)
mike@0 36 | STOREC (* Store char *)
mike@0 37 | STOREW (* Store word *)
mike@0 38 | ARG of int (* Pass argument (index) *)
mike@0 39 | SLINK (* Pass static link *)
mike@0 40 | PCALL of int (* Call procedure (nparams) *)
mike@0 41 | RESULTW (* Procedure result *)
mike@0 42 | MONOP of op (* Perform unary operation (op) *)
mike@0 43 | BINOP of op (* Perform binary operation (op) *)
mike@0 44 | OFFSET (* Add address and offset *)
mike@0 45 | BOUND (* Array bound check *)
mike@0 46 | NCHECK (* Null pointer check *)
mike@0 47 | LABEL of codelab (* Set code label *)
mike@0 48 | JUMP of codelab (* Unconditional branch (dest) *)
mike@0 49 | JUMPC of op * codelab (* Conditional branch (cond, dest) *)
mike@0 50 | JCASE of codelab list * codelab (* Jump table *)
mike@0 51
mike@0 52 (* Extra instructions *)
mike@0 53 | LINE of int (* Line number *)
mike@0 54 | NOP
mike@0 55 | SEQ
mike@0 56 | AFTER (* Expression with side effect *)
mike@0 57 | DEFTMP of int
mike@0 58 | TEMP of int (* Temporary *)
mike@0 59
mike@0 60 (* |Inst| -- printf format for instructions *)
mike@0 61 val fInst : inst -> Print.arg
mike@0 62
mike@0 63 (* |do_monop| -- evaluate unary operation *)
mike@0 64 val do_monop : op -> int -> int
mike@0 65
mike@0 66 (* |do_binop| -- evaluate binary operation *)
mike@0 67 val do_binop : op -> int -> int -> int
mike@0 68
mike@0 69 (* |negate| -- find opposite for comparison op *)
mike@0 70 val negate : op -> op
mike@0 71
mike@0 72 (* Operator trees *)
mike@0 73
mike@0 74 (* |optree| -- type of operator trees *)
mike@0 75 type optree = Node of inst * optree list
mike@0 76
mike@0 77 (* |canon| -- eliminate SEQ, NOP, AFTER nodes *)
mike@0 78 val canon : optree -> optree list
mike@0 79
mike@0 80 (* |flatten| -- move args before calls *)
mike@0 81 val flatten : optree list -> optree list
mike@0 82
mike@0 83 (* |print_optree| -- output operator tree on stdout with line breaking *)
mike@0 84 val print_optree : string -> optree -> unit