Add DynamicLibrary and InlineFunction

This commit is contained in:
Siu Kwan Lam 2013-02-08 18:12:51 -06:00
commit 60336d1c5f
3 changed files with 64 additions and 3 deletions

View file

@ -6,6 +6,7 @@
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/FormattedStream.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/DynamicLibrary.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
@ -747,3 +748,28 @@ PyObject* IRBuilder_CreateAggregateRet(llvm::IRBuilder<>* builder,
return pycapsule_new(inst, "llvm::Value", "llvm:ReturnInst");
}
static
PyObject* DynamicLibrary_LoadLibraryPermanently(const char * Filename,
PyObject* ErrMsg = 0)
{
using namespace llvm::sys;
bool failed;
if (ErrMsg) {
std::string errmsg;
failed = DynamicLibrary::LoadLibraryPermanently(Filename, &errmsg);
if (failed) {
if (-1 == PyFile_WriteString(errmsg.c_str(), ErrMsg)) {
return NULL;
}
}
} else {
failed = DynamicLibrary::LoadLibraryPermanently(Filename);
}
if (failed) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}

View file

@ -1,6 +1,28 @@
from binding import *
from ..namespace import sys
from ..ADT.StringRef import StringRef
DynamicLibrary = sys.Namespace('DynamicLibrary')
#LoadLibraryPermanently
DynamicLibrary = sys.Class()
@DynamicLibrary
class DynamicLibrary:
_include_ = 'llvm/Support/DynamicLibrary.h'
isValid = Method(cast(Bool, bool))
getAddressOfSymbol = Method(cast(VoidPtr, int), cast(str, ConstCharPtr))
LoadPermanentLibrary = CustomStaticMethod(
'DynamicLibrary_LoadLibraryPermanently',
PyObjectPtr, # bool --- failed?
cast(str, ConstCharPtr), # filename
PyObjectPtr, # std::string * errmsg = 0
).require_only(1)
SearchForAddressOfSymbol = StaticMethod(cast(VoidPtr, int), # address
cast(str, ConstCharPtr), # symName
)
AddSymbol = StaticMethod(Void,
cast(str, StringRef), # symbolName
cast(int, VoidPtr), # address
)

View file

@ -1,8 +1,21 @@
from binding import *
from src.namespace import llvm
from src.Module import Module
from src.Instruction import CallInst
llvm.includes.add('llvm/Transforms/Utils/Cloning.h')
@llvm.Class()
class InlineFunctionInfo:
new = Constructor()
delete = Destructor()
CloneModule = llvm.Function('CloneModule', ptr(Module), ptr(Module))
InlineFunction = llvm.Function('InlineFunction',
cast(Bool, bool), # bool --- failed
ptr(CallInst),
ref(InlineFunctionInfo),
cast(bool, Bool), # insert lifetime = true
).require_only(2)