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):
|
||||
return ('{{{}}}'
|
||||
.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
|
||||
else:
|
||||
# TODO
|
||||
print('ty2s: Unknown type: {}'
|
||||
.format(ty))
|
||||
return str(ty)
|
||||
|
@ -161,6 +166,7 @@ def insn2s(insn):
|
|||
.format(insn))
|
||||
return '???'
|
||||
|
||||
|
||||
def terminator2s(terminator):
|
||||
if isinstance(terminator, Ret):
|
||||
if terminator.oper is None:
|
||||
|
@ -182,3 +188,33 @@ def terminator2s(terminator):
|
|||
else:
|
||||
print('terminator2s: Unknown 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