From 541c119fc38ef87e7ade743ceb4402db7f213b68 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 7 Feb 2013 13:50:16 -0600 Subject: [PATCH] Add binding for MDNode, MDString, InlineAsm --- newbinding/include/llvm_binding/extra.h | 17 +++++++++++++++-- newbinding/src/InlineAsm.py | 24 ++++++++++++++++++++++++ newbinding/src/Metadata.py | 23 +++++++++++++++++++++-- newbinding/src/Value.py | 1 + 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 newbinding/src/InlineAsm.py diff --git a/newbinding/include/llvm_binding/extra.h b/newbinding/include/llvm_binding/extra.h index 0d9ba16..df0cecd 100644 --- a/newbinding/include/llvm_binding/extra.h +++ b/newbinding/include/llvm_binding/extra.h @@ -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 vals; + bool ok = extract::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"); +} + + + + diff --git a/newbinding/src/InlineAsm.py b/newbinding/src/InlineAsm.py new file mode 100644 index 0000000..a4ce16b --- /dev/null +++ b/newbinding/src/InlineAsm.py @@ -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) + diff --git a/newbinding/src/Metadata.py b/newbinding/src/Metadata.py index 96dbc01..bda09e1 100644 --- a/newbinding/src/Metadata.py +++ b/newbinding/src/Metadata.py @@ -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 + ) + +@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() diff --git a/newbinding/src/Value.py b/newbinding/src/Value.py index 5d8c0a9..27bcda0 100644 --- a/newbinding/src/Value.py +++ b/newbinding/src/Value.py @@ -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)