@@ -52,6 +52,7 @@ enum OperandKind {
52
52
Constant = 0 ,
53
53
LocalVariable,
54
54
Type,
55
+ Function,
55
56
UnimplementedOperand = 255 ,
56
57
};
57
58
@@ -148,6 +149,12 @@ class YkIRWriter {
148
149
return Idx;
149
150
}
150
151
152
+ size_t functionIndex (llvm::Function *F) {
153
+ // FIXME: For now we assume that function indicies in LLVM IR and our IR
154
+ // are the same.
155
+ return getIndex (&M, F);
156
+ }
157
+
151
158
public:
152
159
YkIRWriter (Module &M, MCStreamer &OutStreamer)
153
160
: M(M), OutStreamer(OutStreamer) {}
@@ -177,6 +184,11 @@ class YkIRWriter {
177
184
serialiseString (S);
178
185
}
179
186
187
+ void serialiseFunctionOperand (llvm::Function *F) {
188
+ OutStreamer.emitInt8 (OperandKind::Function);
189
+ OutStreamer.emitSizeT (functionIndex (F));
190
+ }
191
+
180
192
// YKFIXME: This allows programs which we haven't yet defined a
181
193
// lowering for to compile. For now We just emit a string operand containing
182
194
// the unhandled LLVM operand in textual form.
@@ -187,7 +199,9 @@ class YkIRWriter {
187
199
188
200
void serialiseOperand (Instruction *Parent, ValueLoweringMap &VLMap,
189
201
Value *V) {
190
- if (llvm::Constant *C = dyn_cast<llvm::Constant>(V)) {
202
+ if (llvm::Function *F = dyn_cast<llvm::Function>(V)) {
203
+ serialiseFunctionOperand (F);
204
+ } else if (llvm::Constant *C = dyn_cast<llvm::Constant>(V)) {
191
205
serialiseConstantOperand (Parent, C);
192
206
} else if (Instruction *I = dyn_cast<Instruction>(V)) {
193
207
// If an instruction defines the operand, it's a local variable.
@@ -325,7 +339,7 @@ class YkIRWriter {
325
339
BBIdx++;
326
340
}
327
341
328
- void serialiseFunc (Function &F) {
342
+ void serialiseFunc (llvm:: Function &F) {
329
343
// name:
330
344
serialiseString (F.getName ());
331
345
// num_blocks:
@@ -385,7 +399,7 @@ class YkIRWriter {
385
399
// num_funcs:
386
400
OutStreamer.emitSizeT (M.size ());
387
401
// funcs:
388
- for (Function &F : M) {
402
+ for (llvm:: Function &F : M) {
389
403
serialiseFunc (F);
390
404
}
391
405
0 commit comments