Skip to content

Commit 60871b3

Browse files
committed
ARM: use inferred argument types
1 parent 4293a7e commit 60871b3

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

chb/arm/ARMCallOpcode.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
from chb.bctypes.BCTyp import BCTyp
4545

46+
from chb.invariants.XVariable import XVariable
4647
from chb.invariants.XXpr import XXpr, XprCompound
4748
import chb.invariants.XXprUtil as XU
4849

@@ -98,6 +99,12 @@ def operands(self) -> List[ARMOperand]:
9899
def opargs(self) -> List[ARMOperand]:
99100
return [self.armd.arm_operand(self.args[0])]
100101

102+
def lhs(self, xdata: InstrXData) -> List[XVariable]:
103+
if len(xdata.vars) > 0:
104+
return [xdata.vars[0]]
105+
else:
106+
return []
107+
101108
def argument_count(self, xdata: InstrXData) -> int:
102109
if self.is_call_instruction(xdata):
103110
argcount = xdata.call_target_argument_count()
@@ -326,29 +333,49 @@ def ast_call_prov(
326333
x, xdata, iaddr, astree)
327334

328335
elif x.is_global_address:
329-
hexgaddr = hex(x.constant.value)
330-
if hexgaddr in astree.global_addresses:
331-
vinfo = astree.global_addresses[hexgaddr]
332-
vtype = vinfo.vtype
333-
if vtype is not None:
334-
if vtype.is_array:
335-
hl_arg = astree.mk_vinfo_lval_expression(vinfo)
336+
if argtype is not None and argtype.is_integer:
337+
argtype = cast(AST.ASTTypInt, argtype)
338+
hl_arg = astree.mk_integer_constant(
339+
x.constant.value, argtype.ikind)
340+
341+
elif (
342+
argtype is not None
343+
and (argtype.is_function
344+
or (argtype.is_pointer
345+
and cast(
346+
AST.ASTTypPtr,
347+
argtype).tgttyp.is_function))):
348+
hexaddr = hex(x.constant.value)
349+
argname = "sub_" + hexaddr[2:]
350+
hl_arg = astree.mk_global_variable_expr(
351+
argname,
352+
vtype=argtype,
353+
globaladdress=x.constant.value)
354+
else:
355+
hexgaddr = hex(x.constant.value)
356+
if hexgaddr in astree.global_addresses:
357+
vinfo = astree.global_addresses[hexgaddr]
358+
vtype = vinfo.vtype
359+
if vtype is not None:
360+
if vtype.is_array:
361+
hl_arg = astree.mk_vinfo_lval_expression(
362+
vinfo)
363+
else:
364+
hl_arg = astree.mk_address_of(
365+
astree.mk_vinfo_lval(vinfo))
336366
else:
337-
hl_arg = astree.mk_address_of(
338-
astree.mk_vinfo_lval(vinfo))
339-
else:
340-
chklogger.logger.warning(
341-
("Type of global address %s at instr. address "
342-
+ "%s not known"),
343-
str(x), iaddr)
367+
chklogger.logger.warning(
368+
("Type of global address %s at instr. "
369+
+ "address %s not known"),
370+
str(x), iaddr)
344371
hl_arg = astree.mk_address_of(
345372
astree.mk_vinfo_lval(vinfo))
346-
else:
347-
chklogger.logger.error(
348-
("Unknown global address %s as call argument at "
349-
+ "address %s"),
350-
hexgaddr, iaddr)
351-
hl_arg = astree.mk_temp_lval_expression()
373+
else:
374+
chklogger.logger.error(
375+
("Unknown global address %s as call "
376+
+ "argument at address %s"),
377+
hexgaddr, iaddr)
378+
hl_arg = astree.mk_temp_lval_expression()
352379

353380
else:
354381
hl_arg = XU.xxpr_to_ast_def_expr(x, xdata, iaddr, astree)

chb/arm/ARMInstruction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def global_refs(self) -> Tuple[Sequence[XVariable], Sequence[XXpr]]:
339339
rhs = self.opcode.rhs(self.xdata)
340340
return (
341341
[x for x in lhs if x.is_global_variable],
342-
[x for x in rhs if x.has_global_references()])
342+
[x for x in rhs if x.has_global_references() or x.is_global_address])
343343

344344
def string_pointer_loaded(self) -> Optional[Tuple[str, str]]:
345345
return None

0 commit comments

Comments
 (0)