Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created February 21, 2015 12:18
Show Gist options
  • Save rightfold/68ab2bb32b3d7d856dd3 to your computer and use it in GitHub Desktop.
Save rightfold/68ab2bb32b3d7d856dd3 to your computer and use it in GitHub Desktop.
struct Instruction {
template<typename V>
auto visit(V&& visitor) {
switch (tag) {
case 0: return visitor(noopInstruction);
case 1: return visitor(constInt8Instruction);
case 2: return visitor(constInt16Instruction);
case 3: return visitor(constInt32Instruction);
case 4: return visitor(constInt64Instruction);
case 5: return visitor(constUInt8Instruction);
case 6: return visitor(constUInt16Instruction);
case 7: return visitor(constUInt32Instruction);
case 8: return visitor(constUInt64Instruction);
case 9: return visitor(constBooleanInstruction);
case 10: return visitor(constRationalInstruction);
case 11: return visitor(constFloat32Instruction);
case 12: return visitor(constFloat64Instruction);
case 13: return visitor(constFloat128Instruction);
case 14: return visitor(moveInstruction);
case 15: return visitor(addInt8Instruction);
case 16: return visitor(addInt16Instruction);
case 17: return visitor(addInt32Instruction);
case 18: return visitor(addInt64Instruction);
case 19: return visitor(addUInt8Instruction);
case 20: return visitor(addUInt16Instruction);
case 21: return visitor(addUInt32Instruction);
case 22: return visitor(addUInt64Instruction);
case 23: return visitor(addRationalInstruction);
case 24: return visitor(addFloat32Instruction);
case 25: return visitor(addFloat64Instruction);
case 26: return visitor(addFloat128Instruction);
case 27: return visitor(subInt8Instruction);
case 28: return visitor(subInt16Instruction);
case 29: return visitor(subInt32Instruction);
case 30: return visitor(subInt64Instruction);
case 31: return visitor(subUInt8Instruction);
case 32: return visitor(subUInt16Instruction);
case 33: return visitor(subUInt32Instruction);
case 34: return visitor(subUInt64Instruction);
case 35: return visitor(subRationalInstruction);
case 36: return visitor(subFloat32Instruction);
case 37: return visitor(subFloat64Instruction);
case 38: return visitor(subFloat128Instruction);
case 39: return visitor(mulInt8Instruction);
case 40: return visitor(mulInt16Instruction);
case 41: return visitor(mulInt32Instruction);
case 42: return visitor(mulInt64Instruction);
case 43: return visitor(mulUInt8Instruction);
case 44: return visitor(mulUInt16Instruction);
case 45: return visitor(mulUInt32Instruction);
case 46: return visitor(mulUInt64Instruction);
case 47: return visitor(mulRationalInstruction);
case 48: return visitor(mulFloat32Instruction);
case 49: return visitor(mulFloat64Instruction);
case 50: return visitor(mulFloat128Instruction);
case 51: return visitor(divInt8Instruction);
case 52: return visitor(divInt16Instruction);
case 53: return visitor(divInt32Instruction);
case 54: return visitor(divInt64Instruction);
case 55: return visitor(divUInt8Instruction);
case 56: return visitor(divUInt16Instruction);
case 57: return visitor(divUInt32Instruction);
case 58: return visitor(divUInt64Instruction);
case 59: return visitor(divRationalInstruction);
case 60: return visitor(divFloat32Instruction);
case 61: return visitor(divFloat64Instruction);
case 62: return visitor(divFloat128Instruction);
case 63: return visitor(remInt8Instruction);
case 64: return visitor(remInt16Instruction);
case 65: return visitor(remInt32Instruction);
case 66: return visitor(remInt64Instruction);
case 67: return visitor(remUInt8Instruction);
case 68: return visitor(remUInt16Instruction);
case 69: return visitor(remUInt32Instruction);
case 70: return visitor(remUInt64Instruction);
case 71: return visitor(modInt8Instruction);
case 72: return visitor(modInt16Instruction);
case 73: return visitor(modInt32Instruction);
case 74: return visitor(modInt64Instruction);
case 75: return visitor(modUInt8Instruction);
case 76: return visitor(modUInt16Instruction);
case 77: return visitor(modUInt32Instruction);
case 78: return visitor(modUInt64Instruction);
case 79: return visitor(callWithArgumentsFromArrayInstruction);
case 80: return visitor(callWith0ArgumentsInstruction);
case 81: return visitor(callWith1ArgumentInstruction);
case 82: return visitor(callWith2ArgumentsInstruction);
case 83: return visitor(callWith3ArgumentsInstruction);
case 84: return visitor(callWith4ArgumentsInstruction);
case 85: return visitor(callWith5ArgumentsInstruction);
case 86: return visitor(callWith6ArgumentsInstruction);
case 87: return visitor(callWith7ArgumentsInstruction);
case 88: return visitor(callWith8ArgumentsInstruction);
case 89: return visitor(callWith9ArgumentsInstruction);
case 90: return visitor(callWith10ArgumentsInstruction);
case 91: return visitor(callWith11ArgumentsInstruction);
case 92: return visitor(callWith12ArgumentsInstruction);
case 93: return visitor(callWith13ArgumentsInstruction);
case 94: return visitor(callWith14ArgumentsInstruction);
case 95: return visitor(callWith15ArgumentsInstruction);
default: assert(false);
}
}
std::size_t tag;
union {
NoopInstruction noopInstruction;
ConstInt8Instruction constInt8Instruction;
ConstInt16Instruction constInt16Instruction;
ConstInt32Instruction constInt32Instruction;
ConstInt64Instruction constInt64Instruction;
ConstUInt8Instruction constUInt8Instruction;
ConstUInt16Instruction constUInt16Instruction;
ConstUInt32Instruction constUInt32Instruction;
ConstUInt64Instruction constUInt64Instruction;
ConstBooleanInstruction constBooleanInstruction;
ConstRationalInstruction constRationalInstruction;
ConstFloat32Instruction constFloat32Instruction;
ConstFloat64Instruction constFloat64Instruction;
ConstFloat128Instruction constFloat128Instruction;
MoveInstruction moveInstruction;
AddInt8Instruction addInt8Instruction;
AddInt16Instruction addInt16Instruction;
AddInt32Instruction addInt32Instruction;
AddInt64Instruction addInt64Instruction;
AddUInt8Instruction addUInt8Instruction;
AddUInt16Instruction addUInt16Instruction;
AddUInt32Instruction addUInt32Instruction;
AddUInt64Instruction addUInt64Instruction;
AddRationalInstruction addRationalInstruction;
AddFloat32Instruction addFloat32Instruction;
AddFloat64Instruction addFloat64Instruction;
AddFloat128Instruction addFloat128Instruction;
SubInt8Instruction subInt8Instruction;
SubInt16Instruction subInt16Instruction;
SubInt32Instruction subInt32Instruction;
SubInt64Instruction subInt64Instruction;
SubUInt8Instruction subUInt8Instruction;
SubUInt16Instruction subUInt16Instruction;
SubUInt32Instruction subUInt32Instruction;
SubUInt64Instruction subUInt64Instruction;
SubRationalInstruction subRationalInstruction;
SubFloat32Instruction subFloat32Instruction;
SubFloat64Instruction subFloat64Instruction;
SubFloat128Instruction subFloat128Instruction;
MulInt8Instruction mulInt8Instruction;
MulInt16Instruction mulInt16Instruction;
MulInt32Instruction mulInt32Instruction;
MulInt64Instruction mulInt64Instruction;
MulUInt8Instruction mulUInt8Instruction;
MulUInt16Instruction mulUInt16Instruction;
MulUInt32Instruction mulUInt32Instruction;
MulUInt64Instruction mulUInt64Instruction;
MulRationalInstruction mulRationalInstruction;
MulFloat32Instruction mulFloat32Instruction;
MulFloat64Instruction mulFloat64Instruction;
MulFloat128Instruction mulFloat128Instruction;
DivInt8Instruction divInt8Instruction;
DivInt16Instruction divInt16Instruction;
DivInt32Instruction divInt32Instruction;
DivInt64Instruction divInt64Instruction;
DivUInt8Instruction divUInt8Instruction;
DivUInt16Instruction divUInt16Instruction;
DivUInt32Instruction divUInt32Instruction;
DivUInt64Instruction divUInt64Instruction;
DivRationalInstruction divRationalInstruction;
DivFloat32Instruction divFloat32Instruction;
DivFloat64Instruction divFloat64Instruction;
DivFloat128Instruction divFloat128Instruction;
RemInt8Instruction remInt8Instruction;
RemInt16Instruction remInt16Instruction;
RemInt32Instruction remInt32Instruction;
RemInt64Instruction remInt64Instruction;
RemUInt8Instruction remUInt8Instruction;
RemUInt16Instruction remUInt16Instruction;
RemUInt32Instruction remUInt32Instruction;
RemUInt64Instruction remUInt64Instruction;
ModInt8Instruction modInt8Instruction;
ModInt16Instruction modInt16Instruction;
ModInt32Instruction modInt32Instruction;
ModInt64Instruction modInt64Instruction;
ModUInt8Instruction modUInt8Instruction;
ModUInt16Instruction modUInt16Instruction;
ModUInt32Instruction modUInt32Instruction;
ModUInt64Instruction modUInt64Instruction;
CallWithArgumentsFromArrayInstruction callWithArgumentsFromArrayInstruction;
CallWith0ArgumentsInstruction callWith0ArgumentsInstruction;
CallWith1ArgumentInstruction callWith1ArgumentInstruction;
CallWith2ArgumentsInstruction callWith2ArgumentsInstruction;
CallWith3ArgumentsInstruction callWith3ArgumentsInstruction;
CallWith4ArgumentsInstruction callWith4ArgumentsInstruction;
CallWith5ArgumentsInstruction callWith5ArgumentsInstruction;
CallWith6ArgumentsInstruction callWith6ArgumentsInstruction;
CallWith7ArgumentsInstruction callWith7ArgumentsInstruction;
CallWith8ArgumentsInstruction callWith8ArgumentsInstruction;
CallWith9ArgumentsInstruction callWith9ArgumentsInstruction;
CallWith10ArgumentsInstruction callWith10ArgumentsInstruction;
CallWith11ArgumentsInstruction callWith11ArgumentsInstruction;
CallWith12ArgumentsInstruction callWith12ArgumentsInstruction;
CallWith13ArgumentsInstruction callWith13ArgumentsInstruction;
CallWith14ArgumentsInstruction callWith14ArgumentsInstruction;
CallWith15ArgumentsInstruction callWith15ArgumentsInstruction;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment