Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
modify array handling for multi-dimensional arrays
Browse files Browse the repository at this point in the history
Signed-off-by: Paul <[email protected]>
  • Loading branch information
Paul committed Feb 28, 2020
1 parent 8b54fc5 commit 95acbf6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/dwarf_to_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,11 @@ def get_type_ref(die, attr):

elif die.tag == DW_TAG.array_type:
subtype = get_type_ref(die, 'type')
count = None
counts = []
for val in die.children:
if val.tag == DW_TAG.subrange_type:
count = get_int(val, 'upper_bound')
if count is not None:
count += 1 # count is upper_bound + 1
typeref = array_ref(subtype, count)
counts.append(get_int(val, 'upper_bound') + 1)
typeref = array_ref(subtype, counts)

elif die.tag in [DW_TAG.subroutine_type, DW_TAG.subprogram]:
inline = get_int(die, 'inline', 0)
Expand Down Expand Up @@ -282,8 +280,8 @@ def qualified_ref(ref, tag):
# tag: DW_TAG.const_type, DW_TAG.volatile_type, DW_TAG.restrict_type
return lambda x: ref(x) #Const(ref(x))

def array_ref(ref, count=None):
return lambda x: c_ast.ArrayDecl(ref(x), dim=IntConst(count))
def array_ref(ref, counts=[]):
return lambda x: c_ast.ArrayDecl(ref(x), dim=[(lambda x : IntConst(x))(x) for x in counts])

# Main conversion function
def parse_dwarf(infile, cuname):
Expand Down
3 changes: 2 additions & 1 deletion src/pycunparser/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ def _generate_type(self, n, modifiers=[]):
if isinstance(modifier, c_ast.ArrayDecl):
if (i != 0 and isinstance(modifiers[i - 1], c_ast.PtrDecl)):
nstr = '(' + nstr + ')'
nstr += '[' + self.visit(modifier.dim) + ']'
for v in modifier.dim:
nstr += '[' + self.visit(v) + ']'
elif isinstance(modifier, c_ast.FuncDecl):
if (i != 0 and isinstance(modifiers[i - 1], c_ast.PtrDecl)):
nstr = '(' + nstr + ')'
Expand Down

0 comments on commit 95acbf6

Please sign in to comment.