-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_llvm.cpp
More file actions
576 lines (541 loc) · 18.5 KB
/
Copy pathback_llvm.cpp
File metadata and controls
576 lines (541 loc) · 18.5 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
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
extern "C" {
/* clang-format off */
#define _Noreturn [[noreturn]] /* pointless C/C++ incompatibility %(/$)(/&$%/ */
/* clang-format on */
/*
* clang-format needs to be disabled here because it removes the whitespace
* between macro name and expansion.
*
*/
#include "prg.h"
}
#include <assert.h>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <stack>
#include <utility>
#include <llvm/ADT/APFloat.h>
#include <llvm/ADT/STLExtras.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/raw_ostream.h>
using namespace llvm;
using InsertPoint = std::pair<llvm::BasicBlock *, llvm::BasicBlock::iterator>;
struct Singleton {
LLVMContext C;
IRBuilder<> B;
std::unique_ptr<Module> M;
std::map<std::string, Value *> NamedValues;
std::stack<InsertPoint> InsertPoints;
Singleton() : B(C) { M = llvm::make_unique<Module>("test", C); }
};
static Singleton *llvmdata;
void initCodegen() { llvmdata = new Singleton; }
void finalizeCodegen() {
llvmdata->M->print(llvm::outs(), nullptr);
delete llvmdata;
}
static inline struct BExpr *toExpr(Value *v) { return (struct BExpr *)v; }
static inline Value *fromExpr(struct BExpr *v) { return (Value *)v; }
static inline struct BVar *toVar(Value *v) { return (struct BVar *)v; }
static inline Value *fromVar(struct BVar *v) { return (Value *)v; }
static inline struct BType *toType(Type *v) { return (struct BType *)v; }
static inline Type *fromType(struct BType *v) { return (Type *)v; }
static inline struct BFunction *toFunction(Function *v) {
return (struct BFunction *)v;
}
static inline Function *fromFunction(struct BFunction *v) {
return (Function *)v;
}
struct BStruct { /* NOT POD!!! */
StructType *Type;
const char *Name;
std::vector<llvm::Type *> Content;
};
struct BStruct *beginStruct(const char *name) {
struct BStruct *s = (BStruct *)getMem(sizeof(struct BStruct));
s->Name = name;
return s;
}
struct BStructMember *addToStruct(struct BStruct *st, const char *name,
struct BType *type) {
(void)name; /* in LLVM, struct members are not named */
st->Content.push_back(fromType(type));
return (struct BStructMember *)st->Content.size();
}
void endStruct(struct BStruct *st) {
st->Type = StructType::create(llvmdata->C, st->Content, st->Name);
}
struct BExpr *structMemb(struct BExpr *st, struct BStruct *type,
struct BStructMember *memb) {
unsigned n = (unsigned)(unsigned long long)memb;
Value *l = fromExpr(st);
if (isa<LoadInst>(l)) {
/* TODO: this is a terrible workaround, solve better */
// Value *old = l;
l = cast<LoadInst>(l)->getPointerOperand();
// static_cast<LoadInst *>(old)->eraseFromParent();
// TODO: SOLVE THIS BETTER! This creates an unnecessary `load`!
}
return derefPtr(toExpr(static_cast<Value *>(llvmdata->B.CreateStructGEP(
NULL, l, n - 1, "structmemb"))),
0);
}
struct BExpr *intLiteral(int val) {
return toExpr(ConstantInt::get(
static_cast<Type *>(Type::getInt32Ty(llvmdata->C)), val, true));
}
struct BExpr *floatLiteral(double val) {
return toExpr(ConstantFP::get(llvmdata->C, APFloat(val)));
}
struct BExpr *stringLiteral(const char *val) {
/* TODO: use CreateGlobalStringPtr */
Constant *str = ConstantDataArray::getString(llvmdata->C, val);
GlobalVariable *global = new GlobalVariable(
*llvmdata->M, str->getType(), true,
GlobalValue::LinkageTypes::PrivateLinkage, str, "strliteral");
global->setAlignment(1);
std::vector<Value *> idxlist;
idxlist.resize(2);
idxlist[0] = ConstantInt::get(
static_cast<Type *>(Type::getInt64Ty(llvmdata->C)), 0, true);
idxlist[1] = idxlist[0];
return toExpr(static_cast<Value *>(
llvmdata->B.CreateInBoundsGEP(global, idxlist, "strgep")));
}
struct BType *voidType() {
return toType(Type::getVoidTy(llvmdata->C));
}
struct BType *intType(int flags, int size) { /* size in bytes */
/* LLVM does not care about the flags */
switch (size) {
case 1:
return toType(static_cast<Type *>(Type::getInt8Ty(llvmdata->C)));
case 2:
return toType(static_cast<Type *>(Type::getInt16Ty(llvmdata->C)));
case 4:
return toType(static_cast<Type *>(Type::getInt32Ty(llvmdata->C)));
case 8:
return toType(static_cast<Type *>(Type::getInt64Ty(llvmdata->C)));
}
assert(0);
return NULL; /* never reached */
}
struct BType *floatType(int size) { /* size in bytes */
switch (size) {
case 4:
return toType(Type::getFloatTy(llvmdata->C));
case 8:
return toType(Type::getDoubleTy(llvmdata->C));
}
assert(0);
return NULL; /* never reached */
}
struct BType *structType(struct BStruct *st) {
return toType(st->Type);
}
void constType(struct BType *t) {
(void)t; /* LLVM does not care about constness */
}
struct BType *ptrType(struct BType *t, int isvolatile) {
(void)isvolatile;
if (fromType(t)->isVoidTy()) {
/* LLVM does not like void pointers */
return toType(static_cast<Type *>(PointerType::getUnqual(
static_cast<Type *>(Type::getInt8Ty(llvmdata->C)))));
}
return toType(static_cast<Type *>(PointerType::getUnqual(fromType(t))));
}
struct BType *fnPtrType(struct BType *rettype, int nparms,
struct BType **parms) {
std::vector<Type *> args(nparms);
int i;
for (i = 0; i < nparms; ++i) {
args[i] = fromType(parms[i]);
}
return toType(static_cast<Type *>(PointerType::getUnqual(
FunctionType::get(fromType(rettype), args, false))));
}
struct BType *arrayType(struct BType *t, int size) {
return toType(static_cast<Type *>(ArrayType::get(fromType(t), size)));
}
struct BExpr *pointerToArray(struct BExpr *r, struct BType *ptrtype) {
Value *l = fromExpr(r);
if (isa<LoadInst>(l)) {
/* TODO: this is a terrible workaround, solve better */
Value *old = l;
l = cast<LoadInst>(l)->getPointerOperand();
static_cast<LoadInst *>(old)->eraseFromParent();
}
return toExpr(llvmdata->B.CreateBitCast(l, fromType(ptrtype), "arraydecay"));
}
struct BExpr *derefPtr(struct BExpr *e, int isvolatileptr) {
return toExpr(llvmdata->B.CreateLoad(fromExpr(e), isvolatileptr, "loadtmp"));
}
struct BExpr *refof(struct BExpr *e) {
return e; /* not necessary in LLVM */
}
struct BExpr *castInt(struct BExpr *a, struct BType *t, int issigned) {
return toExpr(llvmdata->B.CreateIntCast(fromExpr(a), fromType(t), issigned));
}
struct BExpr *castFloat(struct BExpr *a, struct BType *t) {
return toExpr(llvmdata->B.CreateFPCast(fromExpr(a), fromType(t)));
}
struct BExpr *castIntToFloat(struct BExpr *a, struct BType *t, int issigned) {
if (issigned) {
return toExpr(llvmdata->B.CreateSIToFP(fromExpr(a), fromType(t)));
}
return toExpr(llvmdata->B.CreateUIToFP(fromExpr(a), fromType(t)));
}
struct BExpr *castFloatToInt(struct BExpr *a, struct BType *t, int issigned) {
if (issigned) {
return toExpr(llvmdata->B.CreateFPToSI(fromExpr(a), fromType(t)));
}
return toExpr(llvmdata->B.CreateFPToUI(fromExpr(a), fromType(t)));
}
struct BExpr *castPtr(struct BExpr *a, struct BType *t) {
return toExpr(llvmdata->B.CreatePointerCast(fromExpr(a), fromType(t)));
}
struct BExpr *castIntToPtr(struct BExpr *a, struct BType *t) {
return toExpr(llvmdata->B.CreateIntToPtr(fromExpr(a), fromType(t)));
}
struct BExpr *castPtrToInt(struct BExpr *a, struct BType *t) {
return toExpr(llvmdata->B.CreatePtrToInt(fromExpr(a), fromType(t)));
}
struct BExpr *arithmeticOp(const char *op, struct BExpr *a, struct BExpr *b,
int result_flags, int result_size, int ptr) {
(void)result_size;
(void)result_flags;
if (ptr && strcmp(op, "+") == 0) {
std::vector<Value *> idxlist;
idxlist.resize(1);
idxlist[0] = fromExpr(b);
return toExpr(static_cast<Value *>(
llvmdata->B.CreateInBoundsGEP(fromExpr(a), idxlist, "ptradd")));
}
#define OP(str, fun) \
if (strcmp(op, str) == 0) { \
return toExpr(llvmdata->B.fun(fromExpr(a), fromExpr(b), "armtmp")); \
}
OP("+", CreateAdd)
OP("-", CreateSub)
OP("*", CreateMul)
OP("/", CreateSDiv)
OP("&&", CreateAnd)
OP("||", CreateOr)
OP("<<", CreateShl)
OP(">>", CreateAShr)
OP("%", CreateSRem)
OP("==", CreateICmpEQ)
OP("!=", CreateICmpNE)
OP("<", CreateICmpSLT)
OP(">", CreateICmpSGT)
OP("<=", CreateICmpSLE)
OP(">=", CreateICmpSGE)
#undef OP
assert(!"arithmetic operation unknown to the LLVM backend");
return NULL; /* never reached, used to silence compiler warning */
}
struct BExpr *unaryOp(char op, struct BExpr *a, int result_flags,
int result_size) {
/* TODO: POINTERS! */
(void)result_size;
(void)result_flags;
switch (op) {
case '!':
return toExpr(llvmdata->B.CreateNot(fromExpr(a), "unarytmp"));
case '~':
return toExpr(llvmdata->B.CreateXor(fromExpr(a), -1, "unarytmp"));
}
assert(0);
return NULL; /* never reached */
}
struct BExpr *arithmeticFPOp(const char *op, struct BExpr *a, struct BExpr *b,
int floatsize) {
(void)floatsize;
#define OP(str, fun) \
if (strcmp(op, str) == 0) { \
return toExpr(llvmdata->B.fun(fromExpr(a), fromExpr(b), "armtmp")); \
}
OP("+", CreateFAdd)
OP("-", CreateFDiv)
OP("*", CreateFMul)
OP("/", CreateFDiv)
OP("%", CreateFRem)
OP("==", CreateFCmpOEQ)
OP("!=", CreateFCmpONE)
OP("<", CreateFCmpOLT)
OP(">", CreateFCmpOGT)
OP("<=", CreateFCmpOLE)
OP(">=", CreateFCmpOGE)
#undef OP
assert(0);
return NULL; /* never reached */
}
struct BExpr *fnRefof(struct BFunction *f) {
return toExpr(static_cast<Value *>(fromFunction(f)));
}
struct BIncompleteParm {
const char *Name;
Type *T;
};
struct BIncompleteFunction {
const char *Name;
struct BType *RetType;
int Flags;
struct BIncompleteParm *Parms;
int NParms;
Function *F;
struct BIncompleteFunction *Parent;
};
struct BIncompleteFunction *curfn;
void beginFnPrototype(const char *name, struct BType *rettype, int flags) {
struct BIncompleteFunction *a =
(struct BIncompleteFunction *)getMem(sizeof(BIncompleteFunction));
a->Name = name;
a->RetType = rettype;
a->Flags = flags;
a->Parent = curfn;
curfn = a;
}
struct BFunction *endFnPrototype(int addBody) {
std::vector<Type *> args(curfn->NParms);
int i;
for (i = 0; i < curfn->NParms; ++i) {
args[i] = curfn->Parms[i].T;
}
FunctionType *ft = FunctionType::get(fromType(curfn->RetType), args, false);
Function *f = Function::Create(ft, Function::ExternalLinkage, curfn->Name,
llvmdata->M.get());
/* TODO: Flags */
i = 0;
for (auto &arg : f->args()) {
arg.setName(curfn->Parms[i].Name);
++i;
}
curfn->F = f;
if (addBody) {
if (llvmdata->B.GetInsertBlock()) {
llvmdata->InsertPoints.push(InsertPoint{llvmdata->B.GetInsertBlock(),
llvmdata->B.GetInsertPoint()});
}
BasicBlock *block = BasicBlock::Create(llvmdata->C, "entry", curfn->F);
llvmdata->B.SetInsertPoint(block);
return toFunction(curfn->F);
} else {
struct BIncompleteFunction *f = curfn;
curfn = curfn->Parent;
return toFunction(f->F);
}
}
void endFnBody(struct BExpr *e) {
if (e) {
llvmdata->B.CreateRet(fromExpr(e));
} else {
llvmdata->B.CreateRetVoid();
}
verifyFunction(*curfn->F, &llvm::errs());
if (llvmdata->InsertPoints.size()) {
const auto &top = llvmdata->InsertPoints.top();
llvmdata->B.SetInsertPoint(top.first, top.second);
llvmdata->InsertPoints.pop();
} else {
llvmdata->B.ClearInsertionPoint();
}
curfn = curfn->Parent;
}
struct BVar *addVariable(const char *name, struct BType *type, int) {
IRBuilder<> b(&curfn->F->getEntryBlock(), curfn->F->getEntryBlock().begin());
return toVar(b.CreateAlloca(fromType(type), 0, name));
}
struct BVar *addParameter(const char *name, struct BType *type) {
curfn->Parms = (struct BIncompleteParm *)moreMem(
curfn->Parms, sizeof(struct BIncompleteParm) * curfn->NParms,
sizeof(struct BIncompleteParm));
curfn->Parms[curfn->NParms].Name = name;
curfn->Parms[curfn->NParms].T = fromType(type);
return (struct BVar *)curfn->NParms++;
}
struct BVar *updateParameter(struct BVar *v) {
Function::arg_iterator a = curfn->F->arg_begin();
std::advance(a, (unsigned long)v);
IRBuilder<> b(&curfn->F->getEntryBlock(), curfn->F->getEntryBlock().begin());
Value *p = b.CreateAlloca(a->getType(), 0, a->getName());
llvmdata->B.CreateStore(&(*a), p);
return toVar(p);
}
struct BVar *addGlobal(const char *name, struct BType *t, int flags) {
GlobalVariable *global = new GlobalVariable(
*llvmdata->M, fromType(t), false, /* TODO: const globals */
GlobalValue::LinkageTypes::ExternalLinkage, NULL, name);
(void)flags; /* TODO: flags */
return toVar(global); /* TODO: alignment */
}
struct BExpr *varUsage(struct BVar *p, int isvolatilevar) {
Value *v = fromVar(p);
if (isa<AllocaInst>(v) /* && !isa<ArrayType>(v->getType())*/) {
if (!isa<StructType>(static_cast<AllocaInst *>(v)->getAllocatedType())) {
return toExpr(llvmdata->B.CreateLoad(v, isvolatilevar, "varusage"));
}
}
return toExpr(v);
}
struct BExpr *setVar(struct BExpr *lhs, struct BExpr *rhs) {
Value *l = fromExpr(lhs);
int isvolatile = 0;
if (isa<LoadInst>(l)) {
/* TODO: this is a terrible workaround, solve better */
Value *old = l;
isvolatile = cast<LoadInst>(l)->isVolatile();
l = cast<LoadInst>(l)->getPointerOperand();
static_cast<LoadInst *>(old)->eraseFromParent();
}
llvmdata->B.CreateStore(fromExpr(rhs), l, isvolatile);
return lhs;
}
struct BTemporary *addTemporary(struct BExpr *e, struct BType *t) {
(void)t;
/* in LLVM, expressions can be reused, no need for temporaries! */
return (struct BTemporary *)e;
}
struct BExpr *tmpInstance(struct BTemporary *tmp) {
return (struct BExpr *)tmp;
}
struct BIncompleteFuncall { /* not POD!!! */
std::vector<Value *> Args;
struct BFunction *F;
struct BExpr *FunPtr;
};
struct BIncompleteFuncall *beginFuncall(struct BFunction *f) {
struct BIncompleteFuncall *r =
(struct BIncompleteFuncall *)getMem(sizeof(struct BIncompleteFuncall));
new (r) struct BIncompleteFuncall;
r->F = f;
return r;
}
struct BIncompleteFuncall *beginFunPtrCall(struct BExpr *e) {
struct BIncompleteFuncall *r =
(struct BIncompleteFuncall *)getMem(sizeof(struct BIncompleteFuncall));
new (r) struct BIncompleteFuncall;
r->FunPtr = e;
return r;
}
void addArg(struct BIncompleteFuncall *c, struct BExpr *val) {
c->Args.push_back(fromExpr(val));
}
struct BExpr *endFuncall(struct BIncompleteFuncall *c) {
struct BExpr *r;
if (c->F) {
r = toExpr(llvmdata->B.CreateCall(fromFunction(c->F), c->Args));
} else {
r = toExpr(llvmdata->B.CreateCall(fromExpr(c->FunPtr), c->Args));
}
return r;
}
static Value *toCond(Value *a) {
return llvmdata->B.CreateIntCast(
a, Type::getInt1Ty(llvmdata->C),
false /* for a condition, signedness does not matter; TODO: other
types as conditions (POINTERS!) */
,
"cond");
}
struct BIf {
BasicBlock *IfTrue, *IfFalse, *AfterIf;
struct BIf *Parent;
};
static struct BIf *lastif;
void beginIfStmt(struct BExpr *cond) {
struct BIf *cnt;
cnt = (struct BIf *)getMem(sizeof(struct BIf));
cnt->IfTrue = BasicBlock::Create(llvmdata->C, "iftrue", curfn->F);
cnt->AfterIf = BasicBlock::Create(llvmdata->C, "afterif", curfn->F);
llvmdata->B.CreateCondBr(toCond(fromExpr(cond)), cnt->IfTrue, cnt->AfterIf);
cnt->Parent = lastif;
lastif = cnt;
llvmdata->B.SetInsertPoint(cnt->IfTrue);
}
void endIfStmt(struct BExpr *r) {
llvmdata->B.CreateBr(lastif->AfterIf);
lastif->IfTrue = llvmdata->B.GetInsertBlock();
llvmdata->B.SetInsertPoint(lastif->AfterIf);
lastif = lastif->Parent;
}
void beginIfElseStmt(struct BExpr *cond) {
struct BIf *cnt;
cnt = (struct BIf *)getMem(sizeof(struct BIf));
cnt->IfTrue = BasicBlock::Create(llvmdata->C, "iftrue", curfn->F);
cnt->IfFalse = BasicBlock::Create(llvmdata->C, "iffalse", curfn->F);
cnt->AfterIf = BasicBlock::Create(llvmdata->C, "afterif", curfn->F);
llvmdata->B.CreateCondBr(toCond(fromExpr(cond)), cnt->IfTrue, cnt->IfFalse);
cnt->Parent = lastif;
lastif = cnt;
llvmdata->B.SetInsertPoint(cnt->IfTrue);
}
void *elseIfStmt(struct BExpr *r, struct BType *rettype) {
llvmdata->B.CreateBr(lastif->AfterIf);
lastif->IfTrue = llvmdata->B.GetInsertBlock();
llvmdata->B.SetInsertPoint(lastif->IfFalse);
(void)rettype; /* not necessary, Value is typed */
return (void *)fromExpr(r);
}
struct BExpr *endIfElseStmt(void *last, struct BExpr *r) {
llvmdata->B.CreateBr(lastif->AfterIf);
lastif->IfFalse = llvmdata->B.GetInsertBlock();
llvmdata->B.SetInsertPoint(lastif->AfterIf);
Value *a = (Value *)last;
if (a) {
Value *b = fromExpr(r);
PHINode *phi = llvmdata->B.CreatePHI(a->getType(), 2, "iftmp");
phi->addIncoming(a, lastif->IfTrue);
phi->addIncoming(b, lastif->IfFalse);
lastif = lastif->Parent;
return toExpr(phi);
}
lastif = lastif->Parent;
return NULL;
}
struct BWhile {
BasicBlock *Cond, *Body, *After;
struct BWhile *Parent;
};
struct BWhile *lastwhile;
void beginWhileLoopCond() {
struct BWhile *cnt;
cnt = (struct BWhile *)getMem(sizeof(struct BWhile));
cnt->Cond = BasicBlock::Create(llvmdata->C, "condloop", curfn->F);
cnt->Body = BasicBlock::Create(llvmdata->C, "loopbody", curfn->F);
cnt->After = BasicBlock::Create(llvmdata->C, "afterloop", curfn->F);
llvmdata->B.CreateBr(cnt->Cond);
cnt->Parent = lastwhile;
lastwhile = cnt;
llvmdata->B.SetInsertPoint(cnt->Cond);
}
void beginWhileLoopBody(struct BExpr *cond) {
llvmdata->B.CreateCondBr(toCond(fromExpr(cond)), lastwhile->Body,
lastwhile->After);
lastwhile->Cond = llvmdata->B.GetInsertBlock();
llvmdata->B.SetInsertPoint(lastwhile->Body);
}
void endWhileLoop() {
llvmdata->B.CreateBr(lastwhile->Cond);
lastwhile->Body = llvmdata->B.GetInsertBlock();
llvmdata->B.SetInsertPoint(lastwhile->After);
lastwhile = lastwhile->Parent;
}
void breakLoop() { llvmdata->B.CreateBr(lastwhile->After); }
void continueLoop() { llvmdata->B.CreateBr(lastwhile->Cond); }
void addEvaluation(struct BExpr *a) { (void)a; /* not necessary in LLVM */ }
struct BExpr *sizeofType(struct BType *t) {
return intLiteral(
llvm::DataLayout(llvmdata->M.get()).getTypeAllocSize(fromType(t)));
}