annotate lab4/target.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
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* lab4/target.mli *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 (* Copyright (c) 2017 J. M. Spivey *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 open Optree
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 (* |reg| -- type of Risc86 registers *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 type reg = R of int | R_fp | R_sp | R_pc | R_ip | R_any | R_temp | R_none
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 (* |fReg| -- format register for printing *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 val fReg : reg -> Print.arg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 (* |volatile| -- list of caller-save registers *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 val volatile : reg list
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 (* |stable| -- list of callee-save registers *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 val stable : reg list
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 (* |operand| -- type of operands for assembly instructions *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 type operand = (* VALUE ASM SYNTAX *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 Const of int (* val #val *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 | Register of reg (* [reg] reg *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 | Index of reg * int (* [reg]+val [reg, #val] *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 | Index2 of reg * reg * int (* [r1]+[r2]<<n [r1, r2, LSL #n] *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 | Global of symbol (* lab lab *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 | Label of codelab (* lab lab *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 (* |fRand| -- format operand for printing *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 val fRand : operand -> Print.arg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 (* |reg_of| -- extract register (or R_none) from operand *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 val reg_of : operand -> reg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 (* |emit| -- emit an assembly language instruction *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 val emit : string -> operand list -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 (* |move_reg| -- emit a register-to-register move *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 val move_reg : reg -> reg -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 (* |emit_lab| -- place a label *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 val emit_lab : codelab -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 (* |emit_comment| -- insert a comment *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 val emit_comment : string -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 (* |emit_tree| -- Print an optree as a comment *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 val emit_tree : optree -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 (* |need_stack| -- ensure stack space *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 val need_stack : int -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 (* |preamble| -- emit first part of assembly language output *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 val preamble : unit -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 (* |postamble| -- emit last part of assembly language output *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 val postamble : unit -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 (* |start_proc| -- emit beginning of procedure *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 val start_proc : symbol -> int -> int -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 (* |end_proc| -- emit end of procedure *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 val end_proc : unit -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 (* |flush_proc| -- dump out code after failure *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 val flush_proc : unit -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 (* |emit_string| -- emit assembler code for string constant *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 val emit_string : symbol -> string -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 (* |emit_global| -- emit assembler code to define global variable *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 val emit_global : symbol -> int -> unit