-
Notifications
You must be signed in to change notification settings - Fork 0
/
libalan.c
119 lines (105 loc) · 3.54 KB
/
libalan.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "symbol.h"
#include "llvm.h"
void init_ready_functions()
{
SymbolEntry *p;
/* writeInteger (n : int) : proc */
p = newFunction("writeInteger");
openScope();
newParameter("n", typeInteger, PASS_BY_VALUE, p);
endFunctionHeader(p, typeVoid);
llvm_createFunction(p, true);
closeScope();
/* writeByte (b : byte) : proc */
p = newFunction("writeByte");
openScope();
newParameter("b", typeChar, PASS_BY_VALUE,p);
endFunctionHeader(p,typeVoid);
llvm_createFunction(p, true);
closeScope();
/* writeChar (b : byte) : proc */
p = newFunction("writeChar");
openScope();
newParameter("b", typeChar, PASS_BY_VALUE, p);
endFunctionHeader(p, typeVoid);
llvm_createFunction(p, true);
closeScope();
/* writeString (s : reference byte []) : proc */
p = newFunction("writeString");
openScope();
newParameter("s", typeIArray(typeChar), PASS_BY_REFERENCE, p);
endFunctionHeader(p, typeVoid);
llvm_createFunction(p, true);
closeScope();
/* readInteger () : int */
p = newFunction("readInteger");
openScope();
endFunctionHeader(p, typeInteger);
llvm_createFunction(p, true);
closeScope();
/* readByte () : byte */
p = newFunction("readByte");
openScope();
endFunctionHeader(p, typeChar);
llvm_createFunction(p, true);
closeScope();
/* readChar () : byte */
p = newFunction("readChar");
openScope();
endFunctionHeader(p, typeChar);
llvm_createFunction(p, true);
closeScope();
/* readString (n : int, s : reference byte []) : proc */
p = newFunction("readString");
openScope();
newParameter("n",typeInteger,PASS_BY_VALUE,p);
newParameter("s",typeIArray(typeChar), PASS_BY_REFERENCE, p);
endFunctionHeader(p, typeVoid);
llvm_createFunction(p, true);
closeScope();
/* extend (b : byte) : int */
p = newFunction("extend");
openScope();
newParameter("b",typeChar,PASS_BY_VALUE,p);
endFunctionHeader(p, typeInteger);
llvm_createFunction(p, true);
closeScope();
/* shrink (i : int) : byte */
p = newFunction("shrink");
openScope();
newParameter("i",typeInteger,PASS_BY_VALUE,p);
endFunctionHeader(p, typeChar);
llvm_createFunction(p, true);
closeScope();
/* strlen (s : reference byte []) : int */
p = newFunction("strlen");
openScope();
newParameter("s",typeIArray(typeChar),PASS_BY_REFERENCE,p);
endFunctionHeader(p, typeInteger);
llvm_createFunction(p, true);
closeScope();
/* strcmp (s1 : reference byte [], s2 : reference byte []) : int */
p = newFunction("strcmp");
openScope();
newParameter("s1",typeIArray(typeChar),PASS_BY_REFERENCE,p);
newParameter("s2",typeIArray(typeChar),PASS_BY_REFERENCE,p);
endFunctionHeader(p, typeInteger);
llvm_createFunction(p, true);
closeScope();
/* strcpy (trg : reference byte [], src : reference byte []) : proc */
p = newFunction("strcpy");
openScope();
newParameter("trg",typeIArray(typeChar),PASS_BY_REFERENCE,p);
newParameter("src",typeIArray(typeChar),PASS_BY_REFERENCE,p);
endFunctionHeader(p, typeVoid);
llvm_createFunction(p, true);
closeScope();
/* strcat (trg : reference byte [], src : reference byte []) : proc */
p = newFunction("strcat");
openScope();
newParameter("trg",typeIArray(typeChar),PASS_BY_REFERENCE,p);
newParameter("src",typeIArray(typeChar),PASS_BY_REFERENCE,p);
endFunctionHeader(p, typeVoid);
llvm_createFunction(p, true);
closeScope();
}