diff --git a/llvm/_core.cpp b/llvm/_core.cpp index b8f86e3..7e40566 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -485,7 +485,8 @@ _wrap_list2obj(LLVMConstVector, LLVMValueRef, LLVMValueRef) /* Constant expressions */ -_wrap_obj2obj(LLVMGetConstOpcode, LLVMValueRef, int) +_wrap_obj2obj(LLVMGetConstExprOpcode, LLVMValueRef, int) +_wrap_obj2str(LLVMGetConstExprOpcodeName, LLVMValueRef) _wrap_obj2obj(LLVMSizeOf, LLVMTypeRef, LLVMValueRef) _wrap_obj2obj(LLVMConstNeg, LLVMValueRef, LLVMValueRef) _wrap_obj2obj(LLVMConstNot, LLVMValueRef, LLVMValueRef) @@ -1580,7 +1581,8 @@ static PyMethodDef core_methods[] = { _method( LLVMConstVector ) /* Constant expressions */ - _method( LLVMGetConstOpcode ) + _method( LLVMGetConstExprOpcode ) + _method( LLVMGetConstExprOpcodeName ) _method( LLVMSizeOf ) _method( LLVMConstNeg ) _method( LLVMConstNot ) diff --git a/llvm/core.py b/llvm/core.py index 8a75d42..0f25766 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -1174,7 +1174,11 @@ class Constant(User): class ConstantExpr(Constant): @property def opcode(self): - return _core.LLVMGetConstOpcode(self.ptr) + return _core.LLVMGetConstExprOpcode(self.ptr) + + @property + def opcode_name(self): + return _core.LLVMGetConstExprOpcodeName(self.ptr) class ConstantAggregateZero(Constant): diff --git a/llvm/extra.cpp b/llvm/extra.cpp index 89bf3a0..088b366 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -126,6 +126,19 @@ const CodeGenOpt::Level OptLevelMap[] = { }; } // end anony namespace + + + +const char *LLVMGetConstExprOpcodeName(LLVMValueRef inst) +{ + return llvm::unwrap(inst)->getOpcodeName(); +} + +unsigned LLVMGetConstExprOpcode(LLVMValueRef inst) +{ + return llvm::unwrap(inst)->getOpcode(); +} + void LLVMLdSetAlignment(LLVMValueRef inst, unsigned align) { return llvm::unwrap(inst)->setAlignment(align); diff --git a/llvm/extra.h b/llvm/extra.h index 4cc3072..a0e743a 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -53,6 +53,18 @@ extern "C" { #endif + + +/* + * Wraps ConstantExpr::getOpcodeName(); + */ +const char *LLVMGetConstExprOpcodeName(LLVMValueRef inst); + +/* + * Wraps ConstantExpr::getOpcode(); + */ +unsigned LLVMGetConstExprOpcode(LLVMValueRef inst); + /* * Wraps LoadInst::SetAlignment */ diff --git a/test/constexpr.py b/test/constexpr.py new file mode 100644 index 0000000..a1beccd --- /dev/null +++ b/test/constexpr.py @@ -0,0 +1,17 @@ +import unittest +from llvm.core import * + +class TestConstExpr(unittest.TestCase): + def test_constexpr_opcode(self): + mod = Module.new('test_constexpr_opcode') + func = mod.add_function(Type.function(Type.void(), []), name="foo") + builder = Builder.new(func.append_basic_block('entry')) + a = builder.inttoptr(Constant.int(Type.int(), 123), + Type.pointer(Type.int())) + self.assertTrue(isinstance(a, ConstantExpr)) + self.assertEqual(a.opcode, OPCODE_INTTOPTR) + self.assertEqual(a.opcode_name, "inttoptr") + +if __name__ == '__main__': + unittest.main() +