Add basic block and instruction position descriptors
This commit is contained in:
parent
3fba8e4adf
commit
3b75974731
2 changed files with 97 additions and 22 deletions
|
|
@ -31,21 +31,15 @@ class TestDebugInfo(unittest.TestCase):
|
|||
bb = square.append_basic_block('entry')
|
||||
bldr = Builder.new(bb)
|
||||
|
||||
compile_unit = debuginfo.CompileUnitDescriptor(
|
||||
# DW_LANG_Python segfaults:
|
||||
# llvm/ADT/StringRef.h:79: llvm::StringRef::StringRef(const char*):
|
||||
# Assertion `Str && "StringRef cannot be built from a NULL argument"'
|
||||
# _dwarf.DW_LANG_Python,
|
||||
_dwarf.DW_LANG_C89,
|
||||
"test_debug_info.py",
|
||||
os.path.expanduser("~"),
|
||||
"my_cool_compiler",
|
||||
)
|
||||
source_filename = "test_debug_info.py"
|
||||
source_filedir = os.path.expanduser("~")
|
||||
|
||||
filedesc = debuginfo.FileDescriptor.from_compileunit(compile_unit)
|
||||
# Debug info for our file
|
||||
filedesc = debuginfo.FileDescriptor(source_filename, source_filedir)
|
||||
|
||||
# Debug info for our function
|
||||
subprogram = debuginfo.SubprogramDescriptor(
|
||||
compile_unit,
|
||||
filedesc,
|
||||
"some_function",
|
||||
"some_function",
|
||||
"some_function",
|
||||
|
|
@ -56,26 +50,53 @@ class TestDebugInfo(unittest.TestCase):
|
|||
)
|
||||
subprograms = debuginfo.MDList([subprogram])
|
||||
|
||||
# compile_unit.add_metadata("subprograms", subprograms)
|
||||
compile_unit.define(mod)
|
||||
subprogram.define(mod)
|
||||
# Debug info for our basic blocks
|
||||
blockdescr1 = debuginfo.BlockDescriptor(subprogram, 2, 4) # lineno, col
|
||||
blockdescr2 = debuginfo.BlockDescriptor(blockdescr1, 3, 4) # lineno, col
|
||||
|
||||
# Debug info for our instructions
|
||||
posinfo1 = debuginfo.PositionInfoDescriptor(2, 4, blockdescr1)
|
||||
posinfo2 = debuginfo.PositionInfoDescriptor(2, 4, blockdescr2)
|
||||
|
||||
# Debug info for our module
|
||||
compile_unit = debuginfo.CompileUnitDescriptor(
|
||||
# DW_LANG_Python segfaults:
|
||||
# llvm/ADT/StringRef.h:79: llvm::StringRef::StringRef(const char*):
|
||||
# Assertion `Str && "StringRef cannot be built from a NULL argument"'
|
||||
# _dwarf.DW_LANG_Python,
|
||||
_dwarf.DW_LANG_C89,
|
||||
source_filename,
|
||||
source_filedir,
|
||||
"my_cool_compiler",
|
||||
subprograms=subprograms,
|
||||
)
|
||||
|
||||
# Define our module debug data
|
||||
compile_unit.define(mod)
|
||||
|
||||
# Build some instructions
|
||||
value = square.args[0]
|
||||
result = bldr.fmul(value, value)
|
||||
bldr.ret(result)
|
||||
ret = bldr.ret(result)
|
||||
|
||||
print mod
|
||||
# Annotate instructions with source position
|
||||
result.set_metadata("dbg", posinfo1.get_metadata(mod))
|
||||
ret.set_metadata("dbg", posinfo2.get_metadata(mod))
|
||||
|
||||
# ... Aaaand, test...
|
||||
# print mod
|
||||
|
||||
modstr = str(mod)
|
||||
|
||||
# Test compile unit
|
||||
self.assertIn("my_cool_compiler", modstr)
|
||||
self.assertIn("test_debug_info.py", modstr)
|
||||
self.assertIn(os.path.expanduser("~"), modstr)
|
||||
self.assertIn(source_filename, modstr)
|
||||
self.assertIn(source_filedir, modstr)
|
||||
self.assertIn("my_cool_compiler", modstr)
|
||||
|
||||
# Test subprogram
|
||||
self.assertIn("some_function", modstr)
|
||||
self.assertIn("float (float)* @square", modstr)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# TestDebugInfo("test_dwarf_constants").debug()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue