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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
package org.shedlang.compiler.patio.instructions;
import org.shedlang.compiler.patio.*;
import org.shedlang.compiler.patio.operands.*;
import org.shedlang.compiler.patio.types.PatioDataLayout;
import org.shedlang.compiler.patio.types.PatioDataValue;
import org.shedlang.compiler.patio.types.PatioType;
import org.shedlang.compiler.patio.values.*;
import org.shedlang.compiler.sources.Sources;
import java.util.List;
import java.util.Optional;
public class Patio {
private Patio() {}
public static PatioBlock block(
List<PatioInstruction> body,
List<PatioOperand> results
) {
return new PatioBlock(body, results, Sources.NULL);
}
public static PatioOperand boolConst(boolean value) {
return new PatioBoolConst(value);
}
public static PatioInstruction boolToInt(PatioLocalRef destination, PatioOperand value) {
return new PatioBoolToInt(destination, value, Sources.NULL);
}
public static PatioOperand byteConst(byte value) {
return new PatioByteConst(value);
}
public static PatioInstruction call(
List<PatioLocalRef> destinations,
String name,
List<PatioOperand> args
) {
return new PatioCall(
destinations,
name,
args,
Sources.NULL
);
}
public static PatioInstruction call(
Optional<PatioLocalRef> destination,
String name,
List<PatioOperand> args
) {
return new PatioCall(
destination.stream().toList(),
name,
args,
Sources.NULL
);
}
public static PatioInstruction callPointer(
PatioLocalRef destination,
PatioOperand functionPointer,
List<PatioOperand> args
) {
return new PatioCallPointer(
List.of(destination),
functionPointer,
args,
Sources.NULL
);
}
public static PatioCatchClause catchClause(
String exceptionTypeName,
PatioLocalRef destination,
PatioBlock body
) {
return new PatioCatchClause(
exceptionTypeName,
destination,
body,
Sources.NULL
);
}
public static PatioCompilationUnit compilationUnit(
List<PatioCompilationUnitElement> elements
) {
return new PatioCompilationUnit(elements, Sources.NULL);
}
public static PatioDataElementImmutableDefinition dataElementImmutableDefinition(
String name,
PatioVisibility visibility,
PatioDataValue value
) {
return new PatioDataElementImmutableDefinition(
name,
visibility,
value,
Sources.NULL
);
}
public static PatioDataElementMutableDeclaration dataElementMutableDeclaration(
String name,
PatioDataLayout layout
) {
return new PatioDataElementMutableDeclaration(
name,
layout,
Sources.NULL
);
}
public static PatioDataElementMutableDefinition dataElementMutableDefinition(
String name,
PatioVisibility visibility,
PatioDataValue initialValue
) {
return new PatioDataElementMutableDefinition(
name,
visibility,
initialValue,
Sources.NULL
);
}
public static PatioOperand dataPtrConst(String name) {
return PatioDataPtrConst.dataElement(name);
}
public static PatioOperand dataPtrConst(PatioDataPtrValue value) {
return new PatioDataPtrConst(value);
}
public static PatioInstruction dataPtrToInt(PatioLocalRef destination, PatioOperand value) {
return new PatioDataPtrToInt(
destination,
value,
Sources.NULL
);
}
public static PatioDataPtrValue dataPtrValueDataElement(String value) {
return new PatioDataPtrValueDataElement(value);
}
public static PatioDataPtrValue dataPtrValueNull() {
return new PatioDataPtrValueNull();
}
public static PatioExceptionTypeDefinition exceptionTypeDefinition(String name, PatioType valueType) {
return new PatioExceptionTypeDefinition(name, valueType, Sources.NULL);
}
public static PatioOperand functionPtrConst(String name) {
return new PatioFunctionPtrConst(name);
}
public static PatioInstruction if_(
List<PatioLocalRef> destinations,
PatioOperand condition,
PatioBlock trueBody,
PatioBlock falseBody
) {
return new PatioIf(
destinations,
condition,
trueBody,
falseBody,
Sources.NULL
);
}
public static PatioOperand intConst(int value) {
return PatioIntConst.of(value);
}
public static PatioOperand intConst(PatioIntValue value) {
return new PatioIntConst(value);
}
public static PatioOperand int32Const(int value) {
return PatioInt32Const.of(value);
}
public static PatioInstruction intAdd(
PatioLocalRef destination,
PatioOperand left,
PatioOperand right
) {
return new PatioIntAdd(
destination,
left,
right,
Sources.NULL
);
}
public static PatioInstruction intEquals(
PatioLocalRef destination,
PatioOperand left,
PatioOperand right
) {
return new PatioIntEquals(destination, left, right, Sources.NULL);
}
public static PatioInstruction intNotEqual(
PatioLocalRef destination,
PatioOperand left,
PatioOperand right
) {
return new PatioIntNotEqual(destination, left, right, Sources.NULL);
}
public static PatioInstruction intSub(
PatioLocalRef destination,
PatioOperand left,
PatioOperand right
) {
return new PatioIntSub(destination, left, right, Sources.NULL);
}
public static PatioInstruction intToBool(PatioLocalRef destination, PatioOperand value) {
return new PatioIntToBool(destination, value, Sources.NULL);
}
public static PatioInstruction intToDataPtr(PatioLocalRef destination, PatioOperand value) {
return new PatioIntToDataPtr(
destination,
value,
Sources.NULL
);
}
public static PatioIntValue intValueByteOffsetOf(
PatioDataLayout layout,
List<Integer> offset
) {
return new PatioIntValueByteOffsetOf(layout, offset);
}
public static PatioIntValue intValueByteSizeOf(
PatioDataLayout layout
) {
return new PatioIntValueByteSizeOf(layout);
}
public static PatioIntValue intValueLiteral(int value) {
return new PatioIntValueLiteral(value);
}
public static PatioInstruction localStore(PatioLocalRef destination, PatioOperand value) {
return new PatioLocalStore(
destination,
value,
Sources.NULL
);
}
public static PatioLocalRef localRef(String name) {
return new PatioLocalRef(name);
}
public static PatioInstruction loop(List<PatioInstruction> body) {
return new PatioLoop(body, Sources.NULL);
}
public static PatioInstruction loopBreak() {
return new PatioLoopBreak(Sources.NULL);
}
public static PatioInstruction loopContinue() {
return new PatioLoopContinue(Sources.NULL);
}
public static PatioInstruction memoryLoad(
PatioLocalRef destination,
PatioOperand pointer,
PatioDataLayout layout,
List<Integer> offset
) {
return new PatioMemoryLoad(
destination,
pointer,
layout,
offset,
Sources.NULL
);
}
public static PatioInstruction memoryStore(
PatioOperand pointer,
PatioDataLayout layout,
List<Integer> offset,
PatioOperand value
) {
return new PatioMemoryStore(
pointer,
layout,
offset,
value,
Sources.NULL
);
}
public static PatioLocal param(String name, PatioType type) {
return new PatioLocal(name, type, PatioLocalType.PARAM);
}
public static PatioInstruction return_(List<PatioOperand> values) {
return new PatioReturn(values, Sources.NULL);
}
public static PatioInstruction return_(PatioOperand value) {
return new PatioReturn(List.of(value), Sources.NULL);
}
public static PatioInstruction returnVoid() {
return new PatioReturn(List.of(), Sources.NULL);
}
public static PatioInstruction switch_(
List<PatioLocalRef> destinations,
PatioOperand value,
List<PatioSwitchCase> cases,
PatioBlock defaultBody
) {
return new PatioSwitch(destinations, value, cases, defaultBody, Sources.NULL);
}
public static PatioSwitchCase switchCase(int value, PatioBlock body) {
return new PatioSwitchCase(value, body, Sources.NULL);
}
public static PatioInstruction throw_(String exceptionTypeName, PatioOperand value) {
return new PatioThrow(exceptionTypeName, value, Sources.NULL);
}
public static PatioTry try_(
List<PatioLocalRef> destinations,
List<PatioCatchClause> catchClauses,
PatioBlock body
) {
return new PatioTry(destinations, catchClauses, body, Sources.NULL);
}
public static PatioInstruction unreachable() {
return new PatioUnreachable(Sources.NULL);
}
public static PatioLocal val(String name, PatioType type) {
return new PatioLocal(name, type, PatioLocalType.VAL);
}
public static PatioLocal var(String name, PatioType type) {
return new PatioLocal(name, type, PatioLocalType.VAR);
}
public static PatioInstruction varLoad(PatioLocalRef destination, PatioLocalRef value) {
return new PatioVarLoad(
destination,
value,
Sources.NULL
);
}
public static PatioInstruction varStore(PatioLocalRef destination, PatioOperand value) {
return new PatioVarStore(
destination,
value,
Sources.NULL
);
}
}
|