Add more to Instruction

This commit is contained in:
Siu Kwan Lam 2013-02-07 15:23:31 -06:00
commit 113f30ffab
4 changed files with 135 additions and 19 deletions

View file

@ -70,6 +70,7 @@ Float = BuiltinTypes('float')
Double = BuiltinTypes('double')
Uint64 = BuiltinTypes('uint64_t')
Int64 = BuiltinTypes('int64_t')
Int = BuiltinTypes('int')
Size_t = BuiltinTypes('size_t')
VoidPtr = BuiltinTypes('void*')
Bool = BuiltinTypes('bool')

View file

@ -1,10 +1,22 @@
from binding import *
from namespace import llvm
from Value import Constant, Value
UndefValue = llvm.Class(Constant)
ConstantInt = llvm.Class(Constant)
ConstantFP = llvm.Class(Constant)
ConstantArray = llvm.Class(Constant)
ConstantStruct = llvm.Class(Constant)
ConstantVector = llvm.Class(Constant)
ConstantDataSequential = llvm.Class(Constant)
ConstantDataArray = llvm.Class(ConstantDataSequential)
ConstantExpr = llvm.Class(Constant)
from LLVMContext import LLVMContext
from ADT.StringRef import StringRef
from ADT.SmallVector import SmallVector_Value, SmallVector_Unsigned
from Type import Type, IntegerType, ArrayType, StructType
from Value import Constant, Value
from Instruction import CmpInst
@Constant
@ -42,7 +54,6 @@ class Constant:
PyObjectPtr)
UndefValue = llvm.Class(Constant)
@UndefValue
class UndefValue:
@ -67,7 +78,6 @@ class UndefValue:
get = StaticMethod(ptr(UndefValue), ptr(Type))
ConstantInt = llvm.Class(Constant)
@ConstantInt
class ConstantInt:
@ -82,7 +92,6 @@ class ConstantInt:
getZExtValue = Method(cast(Uint64, int))
getSExtValue = Method(cast(Int64, int))
ConstantFP = llvm.Class(Constant)
@ConstantFP
class ConstantFP:
@ -95,7 +104,6 @@ class ConstantFP:
isNaN = Method(cast(Bool, bool))
ConstantArray = llvm.Class(Constant)
@ConstantArray
class ConstantArray:
@ -105,7 +113,6 @@ class ConstantArray:
PyObjectPtr, # Constants
)
ConstantStruct = llvm.Class(Constant)
@ConstantStruct
class ConstantStruct:
@ -120,7 +127,6 @@ class ConstantStruct:
cast(bool, Bool), # packed
).require_only(1)
ConstantVector = llvm.Class(Constant)
@ConstantVector
class ConstantVector:
@ -129,13 +135,11 @@ class ConstantVector:
PyObjectPtr, # constants
)
ConstantDataSequential = llvm.Class(Constant)
@ConstantDataSequential
class ConstantDataSequential:
pass
ConstantDataArray = llvm.Class(ConstantDataSequential)
@ConstantDataArray
class ConstantDataArray:
@ -146,7 +150,6 @@ class ConstantDataArray:
).require_only(2)
ConstantExpr = llvm.Class(Constant)
def _factory(*args):
return StaticMethod(ptr(Constant), *args)

View file

@ -1,6 +1,11 @@
from binding import *
from namespace import llvm
from Value import User
from Value import Value, MDNode, User, BasicBlock, Function
from ADT.StringRef import StringRef
from CallingConv import CallingConv
from Attributes import Attributes
from Constant import ConstantInt
Instruction = llvm.Class(User)
AtomicCmpXchgInst = llvm.Class(Instruction)
@ -54,7 +59,49 @@ FPTruncInst = llvm.Class(CastInst)
@Instruction
class Instruction:
pass
removeFromParent = Method()
eraseFromParent = Method()
eraseFromParent.disowning = True
getParent = Method(ptr(BasicBlock))
getOpcode = Method(cast(Unsigned, int))
getOpcodeName = Method(cast(ConstCharPtr, str))
insertBefore = Method(Void, ptr(Instruction))
insertAfter = Method(Void, ptr(Instruction))
moveBefore = Method(Void, ptr(Instruction))
isTerminator = Method(cast(Bool, bool))
isBinaryOp = Method(cast(Bool, bool))
isShift = Method(cast(Bool, bool))
isCast = Method(cast(Bool, bool))
isLogicalShift = Method(cast(Bool, bool))
isArithmeticShift = Method(cast(Bool, bool))
hasMetadata = Method(cast(Bool, bool))
hasMetadataOtherThanDebugLoc = Method(cast(Bool, bool))
isAssociative = Method(cast(Bool, bool))
isCommutative = Method(cast(Bool, bool))
isIdempotent = Method(cast(Bool, bool))
isNilpotent = Method(cast(Bool, bool))
mayWriteToMemory = Method(cast(Bool, bool))
mayReadFromMemory = Method(cast(Bool, bool))
mayReadOrWriteMemory = Method(cast(Bool, bool))
mayThrow = Method(cast(Bool, bool))
mayHaveSideEffects = Method(cast(Bool, bool))
hasMetadata = Method(cast(Bool, bool))
getMetadata = Method(ptr(MDNode), cast(str, StringRef))
setMetadata = Method(Void, cast(str, StringRef), ptr(MDNode))
clone = Method(ptr(Instruction))
# LLVM 3.3
# hasUnsafeAlgebra = Method(cast(Bool, bool))
# hasNoNans = Method(cast(Bool, bool))
# hasNoInfs = Method(cast(Bool, bool))
# hasNoSignedZeros = Method(cast(Bool, bool))
# hasAllowReciprocal = Method(cast(Bool, bool))
@AtomicCmpXchgInst
class AtomicCmpXchgInst:
@ -71,7 +118,16 @@ class BinaryOperator:
@CallInst
class CallInst:
pass
_downcast_ = Value, Instruction
getCallingConv = Method(CallingConv.ID)
setCallingConv = Method(Void, CallingConv.ID)
getParamAlignment = Method(cast(Unsigned, int), cast(int, Unsigned))
addAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
getCalledFunction = Method(ptr(Function))
getCalledValue = Method(ptr(Value))
setCalledFunction = Method(Void, ptr(Function))
isInlineAsm = Method(cast(Bool, bool))
@CmpInst
class CmpInst:
@ -87,6 +143,8 @@ class CmpInst:
'LAST_ICMP_PREDICATE',
'BAD_ICMP_PREDICATE',)
getPredicate = Method(Predicate)
@ExtractElementInst
class ExtractElementInst:
pass
@ -113,7 +171,14 @@ class LandingPadInst:
@PHINode
class PHINode:
pass
getNumIncomingValues = Method(cast(Unsigned, int))
getIncomingValue = Method(ptr(Value), cast(int, Unsigned))
setIncomingValue = Method(Void, cast(int, Unsigned), ptr(Value))
getIncomingBlock = Method(ptr(BasicBlock), cast(int, Unsigned))
setIncomingBlock = Method(Void, cast(int, Unsigned), ptr(BasicBlock))
addIncoming = Method(Void, ptr(Value), ptr(BasicBlock))
hasConstantValue = Method(ptr(Value))
getBasicBlockIndex = Method(cast(Int, int), ptr(BasicBlock))
@SelectInst
class SelectInst:
@ -125,11 +190,24 @@ class ShuffleVectorInst:
@StoreInst
class StoreInst:
pass
_downcast_ = Instruction
isVolatile = Method(cast(Bool, bool))
isSimple = Method(cast(Bool, bool))
isUnordered = Method(cast(Bool, bool))
isAtomic = Method(cast(Bool, bool))
setVolatile = Method(Void, cast(Bool, bool))
getAlignment = Method(cast(Unsigned, int))
setAlignment = Method(Void, cast(int, Unsigned))
classof = StaticMethod(cast(Bool, bool), ptr(Value))
@TerminatorInst
class TerminatorInst:
pass
getNumSuccessors = Method(cast(Unsigned, int))
getSuccessor = Method(ptr(BasicBlock), cast(int, Unsigned))
setSuccessor = Method(Void, cast(int, Unsigned), ptr(BasicBlock))
@UnaryInstruction
class UnaryInstruction:
@ -162,7 +240,15 @@ class IndirectBrInst:
@InvokeInst
class InvokeInst:
pass
_downcast_ = Value, Instruction
getCallingConv = Method(CallingConv.ID)
setCallingConv = Method(Void, CallingConv.ID)
getParamAlignment = Method(cast(Unsigned, int), cast(int, Unsigned))
addAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
getCalledFunction = Method(ptr(Function))
getCalledValue = Method(ptr(Value))
setCalledFunction = Method(Void, ptr(Function))
@ResumeInst
class ResumeInst:
@ -174,7 +260,13 @@ class ReturnInst:
@SwitchInst
class SwitchInst:
pass
getCondition = Method(ptr(Value))
setCondition = Method(Void, ptr(Value))
getDefaultDest = Method(ptr(BasicBlock))
setDefaultDest = Method(Void, ptr(BasicBlock))
getNumCases = Method(cast(int, Unsigned))
addCase = Method(Void, ptr(ConstantInt), ptr(BasicBlock))
@UnreachableInst
class UnreachableInst:
@ -195,7 +287,18 @@ class ExtractValueInst:
@LoadInst
class LoadInst:
pass
_downcast_ = Value, Instruction
isVolatile = Method(cast(Bool, bool))
isSimple = Method(cast(Bool, bool))
isUnordered = Method(cast(Bool, bool))
isAtomic = Method(cast(Bool, bool))
setVolatile = Method(Void, cast(Bool, bool))
getAlignment = Method(cast(Unsigned, int))
setAlignment = Method(Void, cast(int, Unsigned))
classof = StaticMethod(cast(Bool, bool), ptr(Value))
@VAArgInst
class VAArgInst:

View file

@ -31,6 +31,8 @@ class MDString:
@llvm.Class()
class NamedMDNode:
eraseFromParent = Method()
eraseFromParent.disowning = True
dropAllReferences = Method()
getParent = Method(ptr(Module))
getOperand = Method(ptr(MDNode), cast(int, Unsigned))
@ -41,3 +43,10 @@ class NamedMDNode:
print_.realname = "print"
dump = Method()
@CustomPythonMethod
def __str__(self):
import extra
os = extra.make_raw_ostream_for_printing()
self.print_(os, None)
return os.str()