comparison ppc/keiko.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 (* ppc/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
8 | BitAnd | BitOr | BitNot
9
10 val fOp : op -> Print.arg
11
12 (* |symbol| -- global symbols *)
13 type symbol = string
14
15 val nosym : symbol
16
17 val gensym : unit -> symbol
18
19 (* |codelab| -- type of code labels *)
20 type codelab
21
22 val nolab : codelab
23
24 (* |label| -- generate a code label *)
25 val label : unit -> codelab
26
27 val fLab : codelab -> Print.arg
28
29 (* |code| -- type of intermediate instructions *)
30 type code =
31 CONST of int (* Constant (value) *)
32 | GLOBAL of symbol (* Constant (symbol) *)
33 | LOCAL of int (* Local address (offset) *)
34 | LOAD of int (* Load (size) *)
35 | STORE of int (* Store (size) *)
36 | FIXCOPY (* Copy multiple values (size) *)
37 | PCALL of int * int (* Call procedure (nparams, rsize) *)
38 | RETURN of int (* Procedure result (rsize) *)
39 | MONOP of op (* Perform unary operation (op) *)
40 | BINOP of op (* Perform binary operation (op) *)
41 | OFFSET (* Add address and offset *)
42 | BOUND of int (* Array bound check (line) *)
43 | NCHECK of int (* Null pointer check (line) *)
44 | ERETURN of int (* Failure to return (line) *)
45 | LABEL of codelab (* Set code label *)
46 | JUMP of codelab (* Unconditional branch (dest) *)
47 | JUMPC of op * codelab (* Conditional branch (cond, dest) *)
48 | JCASE of codelab list (* Jump table *)
49 | LINE of int (* Line number *)
50
51 (* Compressed instructions *)
52 | LDL of int * int (* LDL (n, s) = LOCAL n / LOAD s *)
53 | STL of int * int (* STL (n, s) = LOCAL n / STORE s *)
54 | LDG of symbol * int (* LDG (x, s) = GLOBAL x / LOAD s *)
55 | STG of symbol * int (* STG (x, s) = GLOBAL x / STORE s *)
56 | LDNW of int (* LDNW n = CONST n / OFFSET / LOAD 4 *)
57 | STNW of int (* STNW n = CONST n / OFFSET / STORE 4 *)
58 | LDI of int (* LDI s = CONST s / TIMES / OFFSET / LOAD s *)
59 | STI of int (* STI s = CONST s / TIMES / OFFSET / STORE s *)
60 | JUMPCZ of op * codelab (* JUMPCZ (w, a) = CONST 0 / JUMPC (w, a) *)
61
62 | SEQ of code list (* Sequence of other instructions *)
63 | NOP (* Null operation *)
64
65 (* canon -- eliminate SEQ and NOP nodes and unneeded LINE's *)
66 val canon : code -> code
67
68 (* |fInst| -- printf format for instructions *)
69 val fInst : code -> Print.arg
70
71 (* |output| -- output code sequence *)
72 val output : code -> unit
73
74 (* |do_monop| -- evaluate unary operation *)
75 val do_monop : op -> int -> int
76
77 (* |do_binop| -- evaluate binary operation *)
78 val do_binop : op -> int -> int -> int
79
80 (* |negate| -- find opposite for comparison op *)
81 val negate : op -> op