@@ -51,18 +51,18 @@ enum OpCode {
51
51
enum OperandKind {
52
52
Constant = 0 ,
53
53
LocalVariable,
54
- String ,
54
+ UnimplementedOperand = 255 ,
55
55
};
56
56
57
57
enum TypeKind {
58
58
Integer = 0 ,
59
59
UnimplementedType = 255 , // YKFIXME: Will eventually be deleted.
60
60
};
61
61
62
- string valueToString (Value *V ) {
62
+ template < class T > string toString (T *X ) {
63
63
string S;
64
64
raw_string_ostream SS (S);
65
- V ->print (SS);
65
+ X ->print (SS);
66
66
return S;
67
67
}
68
68
@@ -153,17 +153,16 @@ class YkIRWriter {
153
153
}
154
154
155
155
void serialiseStringOperand (const char *S) {
156
- OutStreamer.emitInt8 (OperandKind::String );
156
+ OutStreamer.emitInt8 (OperandKind::UnimplementedOperand );
157
157
serialiseString (S);
158
158
}
159
159
160
160
// YKFIXME: This allows programs which we haven't yet defined a
161
161
// lowering for to compile. For now We just emit a string operand containing
162
162
// the unhandled LLVM operand in textual form.
163
163
void serialiseUnimplementedOperand (Value *V) {
164
- OutStreamer.emitInt8 (OperandKind::String);
165
- OutStreamer.emitInt8 (' ?' );
166
- serialiseString (valueToString (V));
164
+ OutStreamer.emitInt8 (OperandKind::UnimplementedOperand);
165
+ serialiseString (toString (V));
167
166
}
168
167
169
168
void serialiseOperand (Instruction *Parent, Value *V) {
@@ -180,6 +179,7 @@ class YkIRWriter {
180
179
// / Does a naiave serialisation of an LLVM instruction by iterating over its
181
180
// / operands and serialising them in turn.
182
181
void serialiseInstGeneric (Instruction *I, OpCode Opc) {
182
+ OutStreamer.emitSizeT (typeIndex (I->getType ()));
183
183
serialiseOpcode (Opc);
184
184
OutStreamer.emitInt32 (I->getNumOperands ());
185
185
for (Value *O : I->operands ()) {
@@ -203,13 +203,15 @@ class YkIRWriter {
203
203
serialiseUnimplementedInstruction (I);
204
204
}
205
205
206
+ // An unimplemented instruction is lowered to an instruction with one
207
+ // unimplemented operand containing the textual LLVM IR we couldn't handle.
206
208
void serialiseUnimplementedInstruction (Instruction *I) {
207
209
// opcode:
208
210
serialiseOpcode (UnimplementedInstruction);
209
211
// num_operands:
210
212
OutStreamer.emitInt32 (1 );
211
213
// problem instruction:
212
- serialiseStringOperand ( valueToString (I). data () );
214
+ serialiseUnimplementedOperand (I );
213
215
}
214
216
215
217
void serialiseBlock (BasicBlock &BB) {
@@ -238,11 +240,11 @@ class YkIRWriter {
238
240
OutStreamer.emitInt32 (ITy->getBitWidth ());
239
241
} else {
240
242
OutStreamer.emitInt8 (TypeKind::UnimplementedType);
243
+ serialiseString (toString (Ty));
241
244
}
242
245
}
243
246
244
247
void serialiseConstantInt (ConstantInt *CI) {
245
- // OutStreamer.emitInt8(OperandKind::Constant);
246
248
OutStreamer.emitSizeT (typeIndex (CI->getType ()));
247
249
OutStreamer.emitSizeT (CI->getBitWidth () / 8 );
248
250
for (size_t I = 0 ; I < CI->getBitWidth (); I += 8 ) {
0 commit comments