Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct private function semantics for pp_str methods #370

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pyvex/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,17 @@ def _pp_str(self) -> str:
if self.statements is not None:
for i, s in enumerate(self.statements):
if isinstance(s, stmt.Put):
stmt_str = s._pp_str(
stmt_str = s.pp_str(
reg_name=self.arch.translate_register_name(s.offset, s.data.result_size(self.tyenv) // 8)
)
elif isinstance(s, stmt.WrTmp) and isinstance(s.data, expr.Get):
stmt_str = s._pp_str(
stmt_str = s.pp_str(
reg_name=self.arch.translate_register_name(s.data.offset, s.data.result_size(self.tyenv) // 8)
)
elif isinstance(s, stmt.Exit):
stmt_str = s._pp_str(reg_name=self.arch.translate_register_name(s.offsIP, self.arch.bits // 8))
stmt_str = s.pp_str(reg_name=self.arch.translate_register_name(s.offsIP, self.arch.bits // 8))
else:
stmt_str = s._pp_str()
stmt_str = s.pp_str()
sa.append(" %02d | %s" % (i, stmt_str))
else:
sa.append(" Statements are omitted.")
Expand Down
12 changes: 7 additions & 5 deletions pyvex/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,13 @@ def ty(self):
def type(self):
return get_enum_from_int(self.ty_int)

def _pp_str(self, reg_name=None):
if reg_name:
return f"GET:{self.ty[4:]}({reg_name})"
else:
return f"GET:{self.ty[4:]}(offset={self.offset})"
def _pp_str(self):
return f"GET:{self.ty[4:]}(offset={self.offset})"

def pp_str_with_name(self, reg_name: str):
"""pp_str_with_name is used to print the expression with the name of the
register instead of the offset"""
return f"GET:{self.ty[4:]}({reg_name})"

@staticmethod
def _from_c(c_expr):
Expand Down
2 changes: 1 addition & 1 deletion pyvex/lifting/util/lifter_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _lift(self):
dst = irsb_c.irsb.addr + irsb_c.irsb.size
dst_ty = vex_int_class(irsb_c.irsb.arch.bits).type
irsb_c.irsb.next = irsb_c.mkconst(dst, dst_ty)
log.debug(self.irsb._pp_str())
log.debug(str(self.irsb))
if self.dump_irsb:
self.irsb.pp()
return self.irsb
Expand Down
34 changes: 17 additions & 17 deletions pyvex/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def replace_expression(self, replacements):
setattr(self, k, tuple(_lst))

def __str__(self):
return self._pp_str(None, None, None)
return self.pp_str(None, None, None)

def _pp_str(self, reg_name=None, arch=None, tyenv=None) -> str:
def pp_str(self, reg_name=None, arch=None, tyenv=None) -> str:
raise NotImplementedError()


Expand All @@ -100,7 +100,7 @@ class NoOp(IRStmt):

tag = "Ist_NoOp"

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "IR-NoOp"

@staticmethod
Expand All @@ -124,7 +124,7 @@ def __init__(self, addr: int, length: int, delta: int):
self.len = length
self.delta = delta

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "------ IMark(0x%x, %d, %d) ------" % (self.addr, self.len, self.delta)

@staticmethod
Expand All @@ -146,7 +146,7 @@ def __init__(self, base, length, nia):
self.len = length
self.nia = nia

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "====== AbiHint(0x%s, %d, %s) ======" % (self.base, self.len, self.nia)

@staticmethod
Expand All @@ -170,7 +170,7 @@ def __init__(self, data: "IRExpr", offset):
self.offset = offset

## TODO: Check if result_size and arch are available before looking of arch register name
def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
if arch is not None and tyenv is not None:
reg_name = arch.translate_register_name(self.offset, self.data.result_size(tyenv) // 8)

Expand Down Expand Up @@ -202,7 +202,7 @@ def __init__(self, descr, ix, data, bias):
self.data = data
self.bias = bias

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "PutI(%s)[%s,%d] = %s" % (self.descr, self.ix, self.bias, self.data)

@staticmethod
Expand Down Expand Up @@ -238,14 +238,14 @@ def __init__(self, tmp, data: "IRExpr"):
self.tmp = tmp
self.data = data

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
# Support for named register in string representation of expr.Get

if arch is not None and tyenv is not None and isinstance(self.data, Get):
reg_name = arch.translate_register_name(self.data.offset, self.data.result_size(tyenv) // 8)

if reg_name is not None and isinstance(self.data, expr.Get):
return "t%d = %s" % (self.tmp, self.data._pp_str(reg_name=reg_name))
return "t%d = %s" % (self.tmp, self.data.pp_str_with_name(reg_name))
else:
return "t%d = %s" % (self.tmp, self.data)

Expand Down Expand Up @@ -281,7 +281,7 @@ def __init__(self, addr: "IRExpr", data: "IRExpr", end: str):
def endness(self):
return self.end

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return f"ST{self.endness[-2:].lower()}({self.addr}) = {self.data}"

@staticmethod
Expand Down Expand Up @@ -331,7 +331,7 @@ def __init__(self, addr, dataLo, dataHi, expdLo, expdHi, oldLo, oldHi, end):
def endness(self):
return self.end

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "t({},{}) = CAS{}({} :: ({},{})->({},{}))".format(
self.oldLo, self.oldHi, self.end[-2:].lower(), self.addr, self.expdLo, self.expdHi, self.dataLo, self.dataHi
)
Expand Down Expand Up @@ -413,7 +413,7 @@ def __init__(self, addr, storedata, result, end):
def endness(self):
return self.end

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
if self.storedata is None:
return "t%d = LD%s-Linked(%s)" % (self.result, self.end[-2:].lower(), self.addr)
else:
Expand Down Expand Up @@ -460,7 +460,7 @@ class MBE(IRStmt):
def __init__(self, event):
self.event = event

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "MBusEvent-" + self.event

@staticmethod
Expand All @@ -483,7 +483,7 @@ def __init__(self, cee, guard, args, tmp, mFx, mAddr, mSize, nFxState):
self.mSize = mSize
self.nFxState = nFxState

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "t{} = DIRTY {} {} ::: {}({})".format(
self.tmp, self.guard, "TODO(effects)", self.cee, ",".join(str(a) for a in self.args)
)
Expand Down Expand Up @@ -537,7 +537,7 @@ def __init__(self, guard, dst, jk, offsIP):
def jumpkind(self):
return self.jk

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
if arch is not None and tyenv is not None:
reg_name = arch.translate_register_name(self.offsIP, arch.bits // 8)

Expand Down Expand Up @@ -600,7 +600,7 @@ def __init__(self, end, cvt, dst, addr, alt, guard):
def endness(self):
return self.end

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return "t%d = if (%s) %s(LD%s(%s)) else %s" % (
self.dst,
self.guard,
Expand Down Expand Up @@ -669,7 +669,7 @@ def __init__(self, end, addr, data, guard):
def endness(self):
return self.end

def _pp_str(self, reg_name=None, arch=None, tyenv=None):
def pp_str(self, reg_name=None, arch=None, tyenv=None):
return f"if ({self.guard}) ST{self.end[-2:].lower()}({self.addr}) = {self.data}"

@staticmethod
Expand Down