llvm.org GIT mirror llvm / 4df1557
Don't require C bindings opcode numbers to be kept in sync. They are not in sync now, for example Bitcast would show up as LLVMCall. So instead introduce 2 functions that map to and from the opcodes in the C bindings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141290 91177308-0d34-0410-b5e6-96231b3b80d8 Torok Edwin 8 years ago
2 changed file(s) with 33 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
178178 LLVMPHI = 44,
179179 LLVMCall = 45,
180180 LLVMSelect = 46,
181 /* UserOp1 */
182 /* UserOp2 */
181 LLVMUserOp1 = 47,
182 LLVMUserOp2 = 48,
183183 LLVMVAArg = 49,
184184 LLVMExtractElement = 50,
185185 LLVMInsertElement = 51,
194194
195195 /* Exception Handling Operators */
196196 LLVMResume = 58,
197 LLVMLandingPad = 59
197 LLVMLandingPad = 59,
198 LLVMUnwind = 60
199
198200
199201 } LLVMOpcode;
200202
653653 return wrap(ConstantVector::get(makeArrayRef(
654654 unwrap(ScalarConstantVals, Size), Size)));
655655 }
656
657 /*-- Opcode mapping */
658
659 static LLVMOpcode map_to_llvmopcode(int opcode)
660 {
661 switch (opcode) {
662 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
663 #include "llvm/Instruction.def"
664 #undef HANDLE_INST
665 default:
666 assert(false && "Unhandled Opcode.");
667 }
668 }
669
670 static int map_from_llvmopcode(LLVMOpcode code)
671 {
672 switch (code) {
673 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
674 #include "llvm/Instruction.def"
675 #undef HANDLE_INST
676 default:
677 assert(false && "Unhandled Opcode.");
678 }
679 }
680
656681 /*--.. Constant expressions ................................................--*/
657682
658683 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
659 return (LLVMOpcode)unwrap(ConstantVal)->getOpcode();
684 return map_to_llvmopcode(unwrap(ConstantVal)->getOpcode());
660685 }
661686
662687 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
19181943 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
19191944 LLVMValueRef LHS, LLVMValueRef RHS,
19201945 const char *Name) {
1921 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(Op), unwrap(LHS),
1946 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
19221947 unwrap(RHS), Name));
19231948 }
19241949
21052130
21062131 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
21072132 LLVMTypeRef DestTy, const char *Name) {
2108 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(Op), unwrap(Val),
2133 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
21092134 unwrap(DestTy), Name));
21102135 }
21112136