Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
x0r committed May 6, 2024
1 parent 4e6b58a commit 3d25b1d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions masm2c/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ def convert_label_var(self, g, name, original_name) -> str:
logging.debug("Variable detected. Size: %s", g.size)
self.variable_size = source_var_size = g.size

if source_var_size == 0 and not g.issegment:
if g.issegment:
self._indirection = IndirectionType.VALUE
return f"seg_offset({original_name.lower()})"

if source_var_size == 0:
raise Exception("Invalid variable '%s' size %u" % (name, source_var_size))

if source_var_size:
self.isvariable = True
self.isvariable = True
if self._middle_size == 0: # TODO check
self._middle_size = source_var_size

if g.issegment:
self._indirection = IndirectionType.VALUE
return f"seg_offset({original_name.lower()})"
return self._convert_label_var_non_segment(g, name)

def _convert_label_var_non_segment(self, g, name):
Expand All @@ -199,7 +199,10 @@ def _convert_label_var_non_segment(self, g, name):
if not self.lea:
self._indirection = IndirectionType.POINTER

if g.elements == 1 and self._isjustlabel and not self.lea and g.size == self.element_size:
#print("\ng.elements == 1 %s, self._isjustlabel=%s, not self.lea=%s, g.size == self.element_size %s" %(
# g.elements == 1, self._isjustlabel, not self.lea, g.size == self.element_size))
simple_argument = g.elements == 1 and self._isjustlabel and not self.lea and g.size == self.element_size
if simple_argument:
self._indirection = IndirectionType.VALUE
result = g.name
else:
Expand All @@ -210,6 +213,8 @@ def _convert_label_var_non_segment_complex(self, g, name):
if self._work_segment == "cs":
self.body += "\tcs=seg_offset(" + g.segment + ");\n"

#print("\nnot self._isjustlabel=%s ?not self.lea=%s? self._indirection == IndirectionType.VALUE %s" %(
# not self._isjustlabel, not self.lea, self._indirection == IndirectionType.VALUE))
if not self._isjustlabel and not self.lea and self._indirection == IndirectionType.VALUE:
self._indirection = IndirectionType.POINTER

Expand Down

0 comments on commit 3d25b1d

Please sign in to comment.