Support optional LLVM-level debug info
This commit is contained in:
parent
f6e687ae66
commit
3fba8e4adf
2 changed files with 30 additions and 21 deletions
|
|
@ -37,6 +37,24 @@ def get_lfunc(llvm_module, lfunc):
|
||||||
# Debug descriptors that generate LLVM Metadata
|
# Debug descriptors that generate LLVM Metadata
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class desc(object):
|
||||||
|
"""
|
||||||
|
Descriptor of a debug field.
|
||||||
|
|
||||||
|
field_name:
|
||||||
|
name of the field (keyword argument name)
|
||||||
|
build_metadata:
|
||||||
|
metadata callback :: (llvm_module, Python value) -> LLVM Value
|
||||||
|
default:
|
||||||
|
default value for this field
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, field_name, build_metadata, default=None):
|
||||||
|
self.field_name = field_name
|
||||||
|
self.build_metadata = build_metadata
|
||||||
|
self.default = default
|
||||||
|
|
||||||
|
|
||||||
def build_operand_list(type_descriptors, idx2name, operands, kwargs):
|
def build_operand_list(type_descriptors, idx2name, operands, kwargs):
|
||||||
"""
|
"""
|
||||||
Build the list of operands from the positional and keyword arguments
|
Build the list of operands from the positional and keyword arguments
|
||||||
|
|
@ -57,7 +75,7 @@ def build_operand_list(type_descriptors, idx2name, operands, kwargs):
|
||||||
else:
|
else:
|
||||||
typedesc = type_descriptors[i]
|
typedesc = type_descriptors[i]
|
||||||
assert typedesc.default is not None, (
|
assert typedesc.default is not None, (
|
||||||
"No value found for field %s" % typedesc.field_name)
|
"No value found for field %s" % typedesc.field_name)
|
||||||
op = typedesc.default
|
op = typedesc.default
|
||||||
|
|
||||||
operands.append(op)
|
operands.append(op)
|
||||||
|
|
@ -81,9 +99,11 @@ class DebugInfoDescriptor(object):
|
||||||
self.metadata_cache = {}
|
self.metadata_cache = {}
|
||||||
|
|
||||||
operands = list(args)
|
operands = list(args)
|
||||||
self.operands = build_operand_list(self.type_descriptors,
|
if kwargs:
|
||||||
self.idx2name, operands, kwargs)
|
operands = build_operand_list(self.type_descriptors,
|
||||||
|
self.idx2name, operands, kwargs)
|
||||||
|
|
||||||
|
self.operands = operands
|
||||||
self.operands_dict = dict(
|
self.operands_dict = dict(
|
||||||
(typedesc.field_name, operand)
|
(typedesc.field_name, operand)
|
||||||
for typedesc, operand in zip(self.type_descriptors, operands))
|
for typedesc, operand in zip(self.type_descriptors, operands))
|
||||||
|
|
@ -146,26 +166,10 @@ class DebugInfoDescriptor(object):
|
||||||
md = self.get_metadata(llvm_module)
|
md = self.get_metadata(llvm_module)
|
||||||
llvm.core.MetaData.add_named_operand(llvm_module, "dbg", md)
|
llvm.core.MetaData.add_named_operand(llvm_module, "dbg", md)
|
||||||
|
|
||||||
class desc(object):
|
|
||||||
"""
|
|
||||||
Descriptor of a debug field.
|
|
||||||
|
|
||||||
field_name:
|
|
||||||
name of the field (keyword argument name)
|
|
||||||
build_metadata:
|
|
||||||
metadata callback :: (llvm_module, Python value) -> LLVM Value
|
|
||||||
default:
|
|
||||||
default value for this field
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, field_name, build_metadata, default=None):
|
|
||||||
self.field_name = field_name
|
|
||||||
self.build_metadata = build_metadata
|
|
||||||
self.default = default
|
|
||||||
|
|
||||||
class EmptyMetadata(DebugInfoDescriptor):
|
class EmptyMetadata(DebugInfoDescriptor):
|
||||||
"""
|
"""
|
||||||
Metadata without any fields. Same as MDList([])
|
Metadata without any fields.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type_descriptors = []
|
type_descriptors = []
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ class TestDebugInfo(unittest.TestCase):
|
||||||
|
|
||||||
# compile_unit.add_metadata("subprograms", subprograms)
|
# compile_unit.add_metadata("subprograms", subprograms)
|
||||||
compile_unit.define(mod)
|
compile_unit.define(mod)
|
||||||
|
subprogram.define(mod)
|
||||||
|
|
||||||
value = square.args[0]
|
value = square.args[0]
|
||||||
result = bldr.fmul(value, value)
|
result = bldr.fmul(value, value)
|
||||||
|
|
@ -66,11 +67,15 @@ class TestDebugInfo(unittest.TestCase):
|
||||||
print mod
|
print mod
|
||||||
|
|
||||||
modstr = str(mod)
|
modstr = str(mod)
|
||||||
|
|
||||||
|
# Test compile unit
|
||||||
self.assertIn("my_cool_compiler", modstr)
|
self.assertIn("my_cool_compiler", modstr)
|
||||||
self.assertIn("test_debug_info.py", modstr)
|
self.assertIn("test_debug_info.py", modstr)
|
||||||
self.assertIn(os.path.expanduser("~/"), modstr)
|
self.assertIn(os.path.expanduser("~"), modstr)
|
||||||
self.assertIn("my_cool_compiler", modstr)
|
self.assertIn("my_cool_compiler", modstr)
|
||||||
|
|
||||||
|
# Test subprogram
|
||||||
|
self.assertIn("some_function", modstr)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# TestDebugInfo("test_dwarf_constants").debug()
|
# TestDebugInfo("test_dwarf_constants").debug()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue