forked from indygreg/llvm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#===-- Generated python interface definitions for 'TargetMachine.h' --------===# | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# | ||
#===------------------------------------------------------------------------===# | ||
# | ||
# This file is automatically generated by 'generate-from-includes.py', | ||
# do not edit manually. | ||
# | ||
#===-----------------------------------------------------------------------====# | ||
|
||
import ctypes | ||
from ..common import c_object_p | ||
|
||
function_declarations = { | ||
'LLVMGetFirstTarget': (c_object_p, | ||
[]), | ||
'LLVMGetNextTarget': (c_object_p, | ||
['LLVMTargetRef']), | ||
'LLVMGetTargetName': (ctypes.POINTER(ctypes.c_char), | ||
['LLVMTargetRef']), | ||
'LLVMGetTargetDescription': (ctypes.POINTER(ctypes.c_char), | ||
['LLVMTargetRef']), | ||
'LLVMTargetHasJIT': ('LLVMBool', | ||
['LLVMTargetRef']), | ||
'LLVMTargetHasTargetMachine': ('LLVMBool', | ||
['LLVMTargetRef']), | ||
'LLVMTargetHasAsmBackend': ('LLVMBool', | ||
['LLVMTargetRef']), | ||
'LLVMCreateTargetMachine': (c_object_p, | ||
['LLVMTargetRef', ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, 'LLVMCodeGenOptLevel', 'LLVMRelocMode', 'LLVMCodeModel']), | ||
'LLVMDisposeTargetMachine': (None, | ||
['LLVMTargetMachineRef']), | ||
'LLVMGetTargetMachineTarget': (c_object_p, | ||
['LLVMTargetMachineRef']), | ||
'LLVMGetTargetMachineTriple': (ctypes.POINTER(ctypes.c_char), | ||
['LLVMTargetMachineRef']), | ||
'LLVMGetTargetMachineCPU': (ctypes.POINTER(ctypes.c_char), | ||
['LLVMTargetMachineRef']), | ||
'LLVMGetTargetMachineFeatureString': (ctypes.POINTER(ctypes.c_char), | ||
['LLVMTargetMachineRef']), | ||
'LLVMGetTargetMachineData': (c_object_p, | ||
['LLVMTargetMachineRef']), | ||
'LLVMTargetMachineEmitToFile': ('LLVMBool', | ||
['LLVMTargetMachineRef', 'LLVMModuleRef', ctypes.c_char_p, 'LLVMCodeGenFileType', ctypes.POINTER(ctypes.c_char_p)]), | ||
'LLVMTargetMachineEmitToMemoryBuffer': ('LLVMBool', | ||
['LLVMTargetMachineRef', 'LLVMModuleRef', 'LLVMCodeGenFileType', ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(c_object_p)]), | ||
} | ||
|
||
enum_declarations = { | ||
'LLVMCodeGenOptLevel': { | ||
'LLVMCodeGenLevelNone': 0, | ||
'LLVMCodeGenLevelLess': 1, | ||
'LLVMCodeGenLevelDefault': 2, | ||
'LLVMCodeGenLevelAggressive': 3, | ||
}, | ||
|
||
'LLVMRelocMode': { | ||
'LLVMRelocDefault': 0, | ||
'LLVMRelocStatic': 1, | ||
'LLVMRelocPIC': 2, | ||
'LLVMRelocDynamicNoPic': 3, | ||
}, | ||
|
||
'LLVMCodeModel': { | ||
'LLVMCodeModelDefault': 0, | ||
'LLVMCodeModelJITDefault': 1, | ||
'LLVMCodeModelSmall': 2, | ||
'LLVMCodeModelKernel': 3, | ||
'LLVMCodeModelMedium': 4, | ||
'LLVMCodeModelLarge': 5, | ||
}, | ||
|
||
'LLVMCodeGenFileType': { | ||
'LLVMAssemblyFile': 0, | ||
'LLVMObjectFile': 1, | ||
}, | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#===- targetmachine.py - Python Object Bindings --------------*- python -*--===# | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# | ||
#===------------------------------------------------------------------------===# | ||
|
||
|
||
from .common import c_object_p | ||
from .common import LLVMObject | ||
from .common import get_library | ||
from .common import create_c_object_p_array | ||
|
||
from .core import types | ||
|
||
import ctypes | ||
|
||
lib = get_library() | ||
|
||
|
||
@lib.c_name("LLVMTargetRef") | ||
class Target(LLVMObject): | ||
|
||
@property | ||
def name(self): | ||
"""Name of the target""" | ||
return lib.LLVMGetTargetName(self) | ||
|
||
@property | ||
def description(self): | ||
"""Targets description""" | ||
return lib.LLVMGetTargetDescription(self) | ||
|
||
@property | ||
def has_jit(self): | ||
"""True if the target has a JIT""" | ||
return bool(lib.LLVMTargetHasJIT(self)) | ||
|
||
@property | ||
def has_target_machine(self): | ||
"""True if the target has a TargetMachine associated""" | ||
return bool(lib.LLVMTargetHasTargetMachine(self)) | ||
|
||
@property | ||
def has_asm_backend(self): | ||
"""True if the target as an ASM backend (required for emitting output)""" | ||
return bool(lib.LLVMTargetHasAsmBackend(self)) | ||
|
||
|
||
def list(): | ||
""" | ||
List all available targets. | ||
""" | ||
o = lib.LLVMGetFirstTarget() | ||
while o: | ||
t = Target(ptr=o) | ||
yield t | ||
o = lib.LLVMGetNextTarget(t) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import llvm.targetmachine | ||
|
||
from .base import TestBase | ||
|
||
class TestTargetMachine(TestBase): | ||
|
||
def test_targetlist(self): | ||
count = 0 | ||
for t in llvm.targetmachine.list(): | ||
count += 1 | ||
assert isinstance(t.name, basestring) | ||
assert isinstance(t.description, basestring) | ||
assert isinstance(t.has_jit, bool) | ||
assert isinstance(t.has_target_machine, bool) | ||
assert isinstance(t.has_asm_backend, bool) | ||
|
||
self.assert_(count > 0) | ||
|