Improve stringification of llvm AST nodes.
This commit is contained in:
parent
b6dafa24f1
commit
2008b63919
40
ll.py
40
ll.py
|
@ -80,10 +80,15 @@ def ty2s(ty):
|
||||||
elif isinstance(ty, StructType):
|
elif isinstance(ty, StructType):
|
||||||
return ('{{{}}}'
|
return ('{{{}}}'
|
||||||
.format(', '.join(map(ty2s, ty.fields))))
|
.format(', '.join(map(ty2s, ty.fields))))
|
||||||
if isinstance(ty, NamedType):
|
elif isinstance(ty, ArrayType):
|
||||||
|
return ('[{} x {}]'
|
||||||
|
.format(ty.length, ty2s(ty.inner_ty)))
|
||||||
|
elif isinstance(ty, FunctionType):
|
||||||
|
print('TODO: ty2s: FunctionType')
|
||||||
|
return '<func>'
|
||||||
|
elif isinstance(ty, NamedType):
|
||||||
return '%' + ty.other_name
|
return '%' + ty.other_name
|
||||||
else:
|
else:
|
||||||
# TODO
|
|
||||||
print('ty2s: Unknown type: {}'
|
print('ty2s: Unknown type: {}'
|
||||||
.format(ty))
|
.format(ty))
|
||||||
return str(ty)
|
return str(ty)
|
||||||
|
@ -161,6 +166,7 @@ def insn2s(insn):
|
||||||
.format(insn))
|
.format(insn))
|
||||||
return '???'
|
return '???'
|
||||||
|
|
||||||
|
|
||||||
def terminator2s(terminator):
|
def terminator2s(terminator):
|
||||||
if isinstance(terminator, Ret):
|
if isinstance(terminator, Ret):
|
||||||
if terminator.oper is None:
|
if terminator.oper is None:
|
||||||
|
@ -182,3 +188,33 @@ def terminator2s(terminator):
|
||||||
else:
|
else:
|
||||||
print('terminator2s: Unknown terminator {}'
|
print('terminator2s: Unknown terminator {}'
|
||||||
.format(terminator))
|
.format(terminator))
|
||||||
|
|
||||||
|
|
||||||
|
def ginit2s(ginit):
|
||||||
|
if isinstance(ginit, GNull):
|
||||||
|
return 'null'
|
||||||
|
elif isinstance(ginit, GGid):
|
||||||
|
return '@' + ginit.val
|
||||||
|
elif isinstance(ginit, GInt):
|
||||||
|
return str(ginit.val)
|
||||||
|
elif isinstance(ginit, GString):
|
||||||
|
return ('c"{}"'
|
||||||
|
.format(ll_encode(ginit.val)))
|
||||||
|
elif isinstance(ginit, GArray):
|
||||||
|
return ('[{}]'
|
||||||
|
.format(', '.join('{} {}'.format(ty2s(t), ginit2s(g))
|
||||||
|
for t, g in ginit.entries)))
|
||||||
|
elif isinstance(ginit, GStruct):
|
||||||
|
return ('{{{}}}'
|
||||||
|
.format(', '.join('{} {}'.format(ty2s(t), ginit2s(g))
|
||||||
|
for t, g in ginit.fields)))
|
||||||
|
|
||||||
|
|
||||||
|
def gdecl2s(gdecl):
|
||||||
|
return ('@{} = {} {}'
|
||||||
|
.format(gdecl.name, ty2s(gdecl.ty), ginit2s(gdecl.body)))
|
||||||
|
|
||||||
|
|
||||||
|
def ll_encode(s):
|
||||||
|
# TODO
|
||||||
|
return s
|
||||||
|
|
Loading…
Reference in New Issue
Block a user