All of DataLayout, IRBuilder and started on ExecutionEngine.
This commit is contained in:
parent
59d0dfddc7
commit
437b1e9490
20 changed files with 688 additions and 41 deletions
|
|
@ -39,6 +39,16 @@ PyObject* pycapsule_new(void* ptr,
|
|||
}
|
||||
|
||||
|
||||
static
|
||||
PyObject* pycapsule_new(const void* ptr,
|
||||
const char* basename,
|
||||
const char* classname=NULL)
|
||||
{
|
||||
// Use const_cast to strip the constantness.
|
||||
// Let the user take the responsibility.
|
||||
return pycapsule_new(const_cast<void*>(ptr), basename, classname);
|
||||
}
|
||||
|
||||
|
||||
#endif //LLVMPY_CAPSULE_CONTEXT_H_
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <llvm/Value.h>
|
||||
#include <llvm/Function.h>
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
|
||||
#include <llvm/ExecutionEngine/ExecutionEngine.h>
|
||||
|
||||
namespace extra{
|
||||
using namespace llvm;
|
||||
|
|
@ -97,11 +97,34 @@ PyObject* make_small_vector_from_values(PyObject* self, PyObject* args)
|
|||
}
|
||||
|
||||
|
||||
static
|
||||
PyObject* make_small_vector_from_unsigned(PyObject* self, PyObject* args)
|
||||
{
|
||||
using llvm::Value;
|
||||
typedef llvm::SmallVector<unsigned, 8> SmallVector_Unsigned;
|
||||
|
||||
SmallVector_Unsigned* SV = new SmallVector_Unsigned;
|
||||
Py_ssize_t size = PyTuple_Size(args);
|
||||
for (Py_ssize_t i = 0; i < size; ++i) {
|
||||
PyObject* item = PyTuple_GetItem(args, i);
|
||||
if (!item) {
|
||||
return NULL;
|
||||
}
|
||||
unsigned value = PyLong_AsUnsignedLong(item);
|
||||
if (PyErr_Occurred()){
|
||||
return NULL;
|
||||
}
|
||||
SV->push_back(value);
|
||||
}
|
||||
return pycapsule_new(SV, "llvm::SmallVector<unsigned,8>");
|
||||
}
|
||||
|
||||
static PyMethodDef extra_methodtable[] = {
|
||||
#define method(func) { #func, (PyCFunction)func, METH_VARARGS, NULL }
|
||||
method( make_raw_ostream_for_printing ),
|
||||
method( make_small_vector_from_types ),
|
||||
method( make_small_vector_from_values ),
|
||||
method( make_small_vector_from_unsigned ),
|
||||
#undef method
|
||||
{ NULL }
|
||||
};
|
||||
|
|
@ -139,11 +162,20 @@ PyObject* iplist_to_pylist(iplist &IPL, const char * capsuleName,
|
|||
className);
|
||||
}
|
||||
|
||||
static
|
||||
bool string_equal(const char *A, const char *B){
|
||||
for (; *A and *B; ++A, ++B) {
|
||||
if (*A != *B) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////
|
||||
static
|
||||
PyObject* Value_use_iterator_to_list(llvm::Value* val)
|
||||
{
|
||||
return iterator_to_pylist(val->use_begin(), val->use_end(),
|
||||
"llvm::Value", "llvm::User");
|
||||
"llvm::Value", "llvm::User");
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -158,4 +190,47 @@ PyObject* Function_getBasicBlockList(llvm::Function* fn)
|
|||
{
|
||||
return iplist_to_pylist(fn->getBasicBlockList(), "llvm::Value",
|
||||
"llvm::BasicBlock");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* errout --- can be any file object
|
||||
*
|
||||
*/
|
||||
static
|
||||
llvm::ExecutionEngine* ExecutionEngine_create(
|
||||
llvm::Module* M,
|
||||
bool ForceInterpreter = false,
|
||||
PyObject* errout = 0,
|
||||
llvm::CodeGenOpt::Level OptLevel = llvm::CodeGenOpt::Default,
|
||||
bool GVsWithCode = true)
|
||||
{
|
||||
using namespace llvm;
|
||||
std::string ErrorStr;
|
||||
ExecutionEngine *ee = ExecutionEngine::create(M, ForceInterpreter,
|
||||
&ErrorStr, OptLevel,
|
||||
GVsWithCode);
|
||||
PyFile_WriteString(ErrorStr.c_str(), errout);
|
||||
return ee;
|
||||
}
|
||||
|
||||
/*
|
||||
* errout --- can be any file object
|
||||
*
|
||||
*/
|
||||
static
|
||||
llvm::ExecutionEngine* ExecutionEngine_createJIT(
|
||||
llvm::Module* M,
|
||||
PyObject* errout = 0,
|
||||
llvm::JITMemoryManager* JMM = 0,
|
||||
llvm::CodeGenOpt::Level OL = llvm::CodeGenOpt::Default,
|
||||
bool GCsWithCode = true,
|
||||
llvm::Reloc::Model RM = llvm::Reloc::Default,
|
||||
llvm::CodeModel::Model CMM = llvm::CodeModel::JITDefault)
|
||||
{
|
||||
using namespace llvm;
|
||||
std::string ErrorStr;
|
||||
ExecutionEngine *ee = ExecutionEngine::createJIT(M, &ErrorStr, JMM, OL,
|
||||
GCsWithCode, RM, CMM);
|
||||
PyFile_WriteString(ErrorStr.c_str(), errout);
|
||||
return ee;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue