-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPrint.d
More file actions
73 lines (66 loc) · 1.67 KB
/
Print.d
File metadata and controls
73 lines (66 loc) · 1.67 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
import std.stdio : writeln;
import std.format : format;
import Node : Node;
import Expr : Expr, StringExpr;
class NewLine : Node {
override void codegen() {
writeln(" call void @print_newline()");
super.codegen();
}
}
class Comma : Node {
override void codegen() {
writeln(" call void @print_comma()");
super.codegen();
}
}
class SemiColon : Node {
override void codegen() {
writeln(" call void @print_semicolon()");
super.codegen();
}
}
class String : Node {
private int str;
this(int s) {
str = s;
}
override void codegen() {
auto r = reg;
writeln(format(" %%%d = bitcast [ %d x i8 ]* @_S%d to i8*", r, symtab.getStrLen(str) + 1, str));
writeln(format(" call void @print_string(i8* %%%d)", r));
super.codegen();
}
}
class PrintExpr : Node {
this(Expr e) {
left = e;
}
override void codegen() {
left.codegen();
writeln(format(" call void @print_number(double %%%d)", (cast(Expr)left).result));
super.codegen();
}
}
class PrintString : Node {
this(StringExpr e) {
left = e;
}
override void codegen() {
left.codegen();
writeln(format(" call void @print_string(i8* %%%d)", (cast(Expr)left).result));
super.codegen();
}
}
class PrintTab : Node {
this(Expr e) {
left = e;
}
override void codegen() {
left.codegen();
auto r = reg;
writeln(format(" %%%d = fptosi double %%%d to i32", r, (cast(Expr)left).result));
writeln(format(" call void @print_tab(i32 %%%d)", r));
super.codegen();
}
}