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