Add binding for MDNode, MDString, InlineAsm

This commit is contained in:
Siu Kwan Lam 2013-02-07 13:50:16 -06:00
commit 541c119fc3
4 changed files with 61 additions and 4 deletions

View file

@ -697,8 +697,8 @@ PyObject* ConstantVector_get(PyObject* Elems)
static
PyObject* Intrinsic_getDeclaration(llvm::Module* Mod,
unsigned ID,
PyObject* Types=NULL)
unsigned ID,
PyObject* Types=NULL)
{
using namespace llvm;
Function* Fn = NULL;
@ -713,3 +713,16 @@ PyObject* Intrinsic_getDeclaration(llvm::Module* Mod,
return pycapsule_new(Fn, "llvm::Value", "llvm::Function");
}
static
PyObject* MDNode_get(llvm::LLVMContext &Cxt, PyObject* Vals)
{
std::vector<llvm::Value*> vals;
bool ok = extract<llvm::Value>::from_py_sequence(vals, Vals, "llvm::Value");
if (not ok) return NULL;
llvm::MDNode* md = llvm::MDNode::get(Cxt, vals);
return pycapsule_new(md, "llvm::Value", "llvm::MDNode");
}

View file

@ -0,0 +1,24 @@
from binding import *
from namespace import llvm
from Value import Value
from DerivedTypes import FunctionType
from ADT.StringRef import StringRef
llvm.includes.add('llvm/InlineAsm.h')
InlineAsm = llvm.Class(Value)
@InlineAsm
class InlineAsm:
AsmDialect = Enum('AD_ATT', 'AD_Intel')
ConstraintPrefix = Enum('''isInput, isOutput, isClobber''')
get = StaticMethod(ptr(InlineAsm),
ptr(FunctionType),
cast(str, StringRef), # AsmString
cast(str, StringRef), # Constrains
cast(bool, Bool), # hasSideEffects
cast(bool, Bool), # isAlignStack
AsmDialect, # default = AD_ATT
).require_only(4)

View file

@ -1,14 +1,32 @@
from binding import *
from namespace import llvm
from Value import MDNode
from Value import Value, MDNode, MDString
from LLVMContext import LLVMContext
from ADT.StringRef import StringRef
from Module import Module
from Function import Function
from Support.raw_ostream import raw_ostream
from Assembly.AssemblyAnnotationWriter import AssemblyAnnotationWriter
@MDNode
class MDNode:
pass
replaceOperandWith = Method(Void, cast(int, Unsigned), ptr(Value))
getOperand = Method(ptr(Value), cast(int, Unsigned))
getNumOperands = Method(cast(Unsigned, int))
isFunctionLocal = Method(cast(Bool, bool))
getFunction = Method(const(ptr(Function)))
get = CustomStaticMethod('MDNode_get',
PyObjectPtr, # MDNode*
ref(LLVMContext),
PyObjectPtr, # ArrayRef<Value*>
)
@MDString
class MDString:
get = StaticMethod(ptr(MDString), ref(LLVMContext), cast(str, StringRef))
getString = Method(cast(StringRef, str))
getLength = Method(cast(int, Unsigned))
@llvm.Class()
class NamedMDNode:
@ -18,6 +36,7 @@ class NamedMDNode:
getOperand = Method(ptr(MDNode), cast(int, Unsigned))
getNumOperands = Method(cast(Unsigned, int))
getName = Method(cast(StringRef, str))
addOperand = Method(Void, ptr(MDNode))
print_ = Method(Void, ref(raw_ostream), ptr(AssemblyAnnotationWriter))
print_.realname = "print"
dump = Method()

View file

@ -5,6 +5,7 @@ from namespace import llvm
Value = llvm.Class()
Argument = llvm.Class(Value)
MDNode = llvm.Class(Value)
MDString = llvm.Class(Value)
User = llvm.Class(Value)
BasicBlock = llvm.Class(Value)
Constant = llvm.Class(User)