-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEmitter.Mod
More file actions
74 lines (63 loc) · 1.57 KB
/
Emitter.Mod
File metadata and controls
74 lines (63 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
MODULE Emitter;
IMPORT Out, Machine, Errors := MocErrors, Table, Tree, G := Generator;
CONST
(** Item.mode values for ARM64 **)
Abs* = 20;
TYPE
Item* = RECORD
mode*: INTEGER; (** Object.class values + Item.mode values *)
type*: Table.Type;
node*: Tree.Node;
address*, offset*, index*: INTEGER
END;
PROCEDURE Print*(x: Item);
BEGIN
Out.String('address='); Out.Int(x.address, 0);
Out.String(' mode='); Out.Int(x.mode, 0);
Out.String(' type='); Table.PrintType(x.type);
Out.String(' node='); Tree.Print(x.node, 0)
END Print;
PROCEDURE Assign*(VAR z, x: Item);
BEGIN
IF z.type.form # Table.Int THEN
Machine.NotImplemented('assignment to a non-INTEGER')
ELSIF x.mode # Table.Const THEN
Machine.NotImplemented('assignment of a non-constant value')
ELSE
G.MovHImm(0, x.address);
G.Adrp(1, 2);
IF z.address # 0 THEN
G.AddImm(1, 1, z.address)
END;
G.StrH(0, 1)
END
END Assign;
PROCEDURE Relation*(VAR x: Item);
BEGIN
END Relation;
PROCEDURE OutLn*;
BEGIN
G.MovImm( 0, 1); (* stdout *)
G.Adrp ( 1, 5); (* address of 0AX *)
G.AddImm( 1, 1, 0FFFH);
G.MovImm( 2, 1); (* length = 1 *)
G.MovImm(16, 4); (* write *)
G.Svc(0)
END OutLn;
PROCEDURE OutInt*(params: Tree.Node);
BEGIN
G.MovImm( 0, 1); (* stdout *)
G.Adrp ( 1, 2); (* address *)
G.AddImm( 1, 1, params.object.address);
G.MovImm( 2, 1); (* length = 1 *)
G.MovImm(16, 4); (* write *)
G.Svc(0)
END OutInt;
PROCEDURE Enter*;
BEGIN
END Enter;
PROCEDURE Exit*;
BEGIN
G.Exit
END Exit;
END Emitter.