Make it possible to pass LLVM options from environment variables.

These options are parsed like commandline options to llc.
This commit is contained in:
Siu Kwan Lam 2012-08-26 21:00:29 -07:00
commit 38d4de35bb
3 changed files with 50 additions and 1 deletions

View file

@ -43,6 +43,8 @@
#include "llvm-c/ExecutionEngine.h"
#include "llvm-c/Target.h"
#include "llvm-c/Transforms/IPO.h"
#include "llvm/Support/CommandLine.h"
#if LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 2
#include "llvm-c/Linker.h"
#else
@ -1413,6 +1415,20 @@ _wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
static PyObject *
_wLLVMParseEnvOpts(PyObject *self, PyObject *args)
{
const char * progname;
const char * envname;
if(!PyArg_ParseTuple(args, "ss", &progname, &envname)) {
return NULL;
}
llvm::cl::ParseEnvironmentOptions(progname, envname);
Py_RETURN_NONE;
}
//_wrap_obj2obj(LLVMInlineFunction, LLVMValueRef, int)
/* Expose the void* inside a PyCObject as a PyLong. This allows us to
@ -2015,6 +2031,8 @@ static PyMethodDef core_methods[] = {
/* Misc */
_method( LLVMGetIntrinsic )
_method( LLVMLoadLibraryPermanently )
_method( LLVMParseEnvOpts )
//_method( LLVMInlineFunction )
_method( PyCObjectVoidPtrToPyLong )
{ NULL }

View file

@ -2147,7 +2147,8 @@ def inline_function(call):
check_is_value(call)
return _core.LLVMInlineFunction(call.ptr)
def parse_environment_options(progname, envname):
_core.LLVMParseEnvOpts(progname, envname)
#===----------------------------------------------------------------------===
# Initialization
@ -2178,3 +2179,4 @@ if True: # use PTX?
except AttributeError:
pass

29
test/native_asm.py Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env python
from llvm import *
from llvm.core import *
import sys, os
import unittest
class TestNativeAsm(unittest.TestCase):
def test_asm(self):
# create a module
m = Module.new('module1')
foo = m.add_function(Type.function(Type.int(), [Type.int(), Type.int()]), name="foo")
bldr = Builder.new(foo.append_basic_block('entry'))
x = bldr.add(foo.args[0], foo.args[1])
bldr.ret(x)
att_syntax = m.to_native_assembly()
os.environ["LLVMPY_OPTIONS"] = "-x86-asm-syntax=intel"
parse_environment_options(sys.argv[0], "LLVMPY_OPTIONS")
intel_syntax = m.to_native_assembly()
print(att_syntax)
print(intel_syntax)
self.assertNotEqual(att_syntax, intel_syntax)
if __name__ == '__main__':
unittest.main()