Fix ConstantExpr opcode to use C++ enum values.
Note: C++ opcode is different from C opcode values. Add ConstantExpr opcode name. Add test for these.
This commit is contained in:
parent
76c60adbca
commit
5d14461c84
5 changed files with 51 additions and 3 deletions
|
|
@ -485,7 +485,8 @@ _wrap_list2obj(LLVMConstVector, LLVMValueRef, LLVMValueRef)
|
||||||
|
|
||||||
/* Constant expressions */
|
/* Constant expressions */
|
||||||
|
|
||||||
_wrap_obj2obj(LLVMGetConstOpcode, LLVMValueRef, int)
|
_wrap_obj2obj(LLVMGetConstExprOpcode, LLVMValueRef, int)
|
||||||
|
_wrap_obj2str(LLVMGetConstExprOpcodeName, LLVMValueRef)
|
||||||
_wrap_obj2obj(LLVMSizeOf, LLVMTypeRef, LLVMValueRef)
|
_wrap_obj2obj(LLVMSizeOf, LLVMTypeRef, LLVMValueRef)
|
||||||
_wrap_obj2obj(LLVMConstNeg, LLVMValueRef, LLVMValueRef)
|
_wrap_obj2obj(LLVMConstNeg, LLVMValueRef, LLVMValueRef)
|
||||||
_wrap_obj2obj(LLVMConstNot, LLVMValueRef, LLVMValueRef)
|
_wrap_obj2obj(LLVMConstNot, LLVMValueRef, LLVMValueRef)
|
||||||
|
|
@ -1580,7 +1581,8 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMConstVector )
|
_method( LLVMConstVector )
|
||||||
|
|
||||||
/* Constant expressions */
|
/* Constant expressions */
|
||||||
_method( LLVMGetConstOpcode )
|
_method( LLVMGetConstExprOpcode )
|
||||||
|
_method( LLVMGetConstExprOpcodeName )
|
||||||
_method( LLVMSizeOf )
|
_method( LLVMSizeOf )
|
||||||
_method( LLVMConstNeg )
|
_method( LLVMConstNeg )
|
||||||
_method( LLVMConstNot )
|
_method( LLVMConstNot )
|
||||||
|
|
|
||||||
|
|
@ -1174,7 +1174,11 @@ class Constant(User):
|
||||||
class ConstantExpr(Constant):
|
class ConstantExpr(Constant):
|
||||||
@property
|
@property
|
||||||
def opcode(self):
|
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):
|
class ConstantAggregateZero(Constant):
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,19 @@ const CodeGenOpt::Level OptLevelMap[] = {
|
||||||
};
|
};
|
||||||
} // end anony namespace
|
} // end anony namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const char *LLVMGetConstExprOpcodeName(LLVMValueRef inst)
|
||||||
|
{
|
||||||
|
return llvm::unwrap<llvm::ConstantExpr>(inst)->getOpcodeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned LLVMGetConstExprOpcode(LLVMValueRef inst)
|
||||||
|
{
|
||||||
|
return llvm::unwrap<llvm::ConstantExpr>(inst)->getOpcode();
|
||||||
|
}
|
||||||
|
|
||||||
void LLVMLdSetAlignment(LLVMValueRef inst, unsigned align)
|
void LLVMLdSetAlignment(LLVMValueRef inst, unsigned align)
|
||||||
{
|
{
|
||||||
return llvm::unwrap<LoadInst>(inst)->setAlignment(align);
|
return llvm::unwrap<LoadInst>(inst)->setAlignment(align);
|
||||||
|
|
|
||||||
12
llvm/extra.h
12
llvm/extra.h
|
|
@ -53,6 +53,18 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wraps ConstantExpr::getOpcodeName();
|
||||||
|
*/
|
||||||
|
const char *LLVMGetConstExprOpcodeName(LLVMValueRef inst);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wraps ConstantExpr::getOpcode();
|
||||||
|
*/
|
||||||
|
unsigned LLVMGetConstExprOpcode(LLVMValueRef inst);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wraps LoadInst::SetAlignment
|
* Wraps LoadInst::SetAlignment
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
17
test/constexpr.py
Normal file
17
test/constexpr.py
Normal file
|
|
@ -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()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue