Skip to content

Commit

Permalink
Work on flows: Add Dispatch, make flow.typ always str
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Apr 18, 2021
1 parent f30159e commit c3ad3ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/HP5370/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def tramp(cx):
continue
if len(i.flow_out) != 1:
continue
if i.flow_out[0].typ != ">":
if i.flow_out[0].typ != "J":
continue
if i.flow_out[0].cond is not True:
continue
Expand Down
16 changes: 11 additions & 5 deletions pyreveng/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
somehow. Code objects tie together with "flow" objects, which tell
where execution will continue.
It is imortant to understand that 'code' is not just assembler code
It is important to understand that 'code' is not just assembler code
but also semi-digested token-sequences in interpreted languages, for
instance the CHIP-8 'language' on RCA1802 CPUs or the RPN code of a
HP 48 Calculator.
Expand All @@ -48,7 +48,7 @@ class Flow():
Flows connect code leaves together and captures where
execution can go next and under what condition.
'''
def __init__(self, typ=True, cond=True, to=None, lang=None):
def __init__(self, typ="N", cond=True, to=None, lang=None):
self.fm = None
self.lang = lang
self.typ = typ
Expand All @@ -59,7 +59,8 @@ def __init__(self, typ=True, cond=True, to=None, lang=None):
def come_from(self, fm):
self.fm = fm

if self.typ is True:
if self.typ == "N":
assert self.to is None
self.to = fm.hi

if self.lang is None:
Expand All @@ -80,7 +81,7 @@ def __repr__(self):
return s

def lcmt(self, leaf):
if self.typ is True:
if self.typ == "N":
return
s = "Flow %s" % self.typ
if self.cond not in (True, None):
Expand All @@ -92,7 +93,7 @@ def lcmt(self, leaf):
class Jump(Flow):
''' Transfer of control with no return/link address '''
def __init__(self, **kwargs):
super().__init__(typ='>', **kwargs)
super().__init__(typ='J', **kwargs)

class Call(Flow):
''' Transfer of control with return/link address '''
Expand All @@ -104,6 +105,11 @@ class Return(Flow):
def __init__(self, **kwargs):
super().__init__(typ='R', **kwargs)

class Dispatch(Flow):
''' Transfer of control to different executor '''
def __init__(self, **kwargs):
super().__init__(typ='D', **kwargs)


#######################################################################

Expand Down

0 comments on commit c3ad3ef

Please sign in to comment.