Skip to content

Commit 70531ad

Browse files
committed
ARM: add span info to operand lvalues/rvalues
1 parent 3f96c89 commit 70531ad

12 files changed

+129
-38
lines changed

chb/arm/ARMOperand.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2024 Aarno Labs LLC
7+
# Copyright (c) 2021-2025 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -109,16 +109,22 @@ def offset(self) -> int:
109109
def ast_lvalue(
110110
self,
111111
astree: ASTInterface,
112+
iaddr: Optional[str] = None,
113+
bytestring: Optional[str] = None,
112114
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
113115
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
114-
return self.opkind.ast_lvalue(astree)
116+
return self.opkind.ast_lvalue(
117+
astree, iaddr=iaddr, bytestring=bytestring, vtype=vtype)
115118

116119
def ast_rvalue(
117120
self,
118121
astree: ASTInterface,
122+
iaddr: Optional[str] = None,
123+
bytestring: Optional[str] = None,
119124
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
120125
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
121-
return self.opkind.ast_rvalue(astree)
126+
return self.opkind.ast_rvalue(
127+
astree, iaddr=iaddr, bytestring=bytestring, vtype=vtype)
122128

123129
def __str__(self) -> str:
124130
return str(self.opkind)

chb/arm/ARMOperandKind.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ def scale_factor(self) -> Optional[int]:
184184
def ast_lvalue(
185185
self,
186186
astree: ASTInterface,
187+
iaddr: Optional[str] = None,
188+
bytestring: Optional[str] = None,
187189
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
188190
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
189191
raise UF.CHBError(
@@ -196,6 +198,8 @@ def ast_lvalue(
196198
def ast_rvalue(
197199
self,
198200
astree: ASTInterface,
201+
iaddr: Optional[str] = None,
202+
bytestring: Optional[str] = None,
199203
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
200204
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
201205
raise UF.CHBError(
@@ -230,6 +234,8 @@ def is_register(self) -> bool:
230234
def ast_lvalue(
231235
self,
232236
astree: ASTInterface,
237+
iaddr: Optional[str] = None,
238+
bytestring: Optional[str] = None,
233239
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
234240
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
235241
return (
@@ -238,6 +244,8 @@ def ast_lvalue(
238244
def ast_rvalue(
239245
self,
240246
astree: ASTInterface,
247+
iaddr: Optional[str] = None,
248+
bytestring: Optional[str] = None,
241249
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
242250
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
243251
return (
@@ -277,6 +285,8 @@ def name(self) -> str:
277285
def ast_lvalue(
278286
self,
279287
astree: ASTInterface,
288+
iaddr: Optional[str] = None,
289+
bytestring: Optional[str] = None,
280290
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
281291
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
282292
return (
@@ -285,6 +295,8 @@ def ast_lvalue(
285295
def ast_rvalue(
286296
self,
287297
astree: ASTInterface,
298+
iaddr: Optional[str] = None,
299+
bytestring: Optional[str] = None,
288300
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
289301
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
290302
return (
@@ -318,6 +330,8 @@ def is_special_register(self) -> bool:
318330
def ast_lvalue(
319331
self,
320332
astree: ASTInterface,
333+
iaddr: Optional[str] = None,
334+
bytestring: Optional[str] = None,
321335
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
322336
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
323337
return (
@@ -326,6 +340,8 @@ def ast_lvalue(
326340
def ast_rvalue(
327341
self,
328342
astree: ASTInterface,
343+
iaddr: Optional[str] = None,
344+
bytestring: Optional[str] = None,
329345
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
330346
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
331347
return (
@@ -378,6 +394,8 @@ def index(self) -> int:
378394
def ast_lvalue(
379395
self,
380396
astree: ASTInterface,
397+
iaddr: Optional[str] = None,
398+
bytestring: Optional[str] = None,
381399
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
382400
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
383401
return (
@@ -388,6 +406,8 @@ def ast_lvalue(
388406
def ast_rvalue(
389407
self,
390408
astree: ASTInterface,
409+
iaddr: Optional[str] = None,
410+
bytestring: Optional[str] = None,
391411
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
392412
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
393413
return (
@@ -456,6 +476,8 @@ def name(self) -> str:
456476
def ast_lvalue(
457477
self,
458478
astree: ASTInterface,
479+
iaddr: Optional[str] = None,
480+
bytestring: Optional[str] = None,
459481
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
460482
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
461483
return (
@@ -464,6 +486,8 @@ def ast_lvalue(
464486
def ast_rvalue(
465487
self,
466488
astree: ASTInterface,
489+
iaddr: Optional[str] = None,
490+
bytestring: Optional[str] = None,
467491
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
468492
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
469493
return (
@@ -597,6 +621,8 @@ def scale_factor(self) -> Optional[int]:
597621
def ast_lvalue(
598622
self,
599623
astree: ASTInterface,
624+
iaddr: Optional[str] = None,
625+
bytestring: Optional[str] = None,
600626
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
601627
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
602628
raise UF.CHBError(
@@ -605,6 +631,8 @@ def ast_lvalue(
605631
def ast_rvalue(
606632
self,
607633
astree: ASTInterface,
634+
iaddr: Optional[str] = None,
635+
bytestring: Optional[str] = None,
608636
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
609637
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
610638
srt = self.shift_rotate
@@ -688,6 +716,8 @@ def width(self) -> int:
688716
def ast_lvalue(
689717
self,
690718
astree: ASTInterface,
719+
iaddr: Optional[str] = None,
720+
bytestring: Optional[str] = None,
691721
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
692722
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
693723
raise UF.CHBError(
@@ -696,6 +726,8 @@ def ast_lvalue(
696726
def ast_rvalue(
697727
self,
698728
astree: ASTInterface,
729+
iddr: Optional[str] = None,
730+
bytestring: Optional[str] = None,
699731
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
700732
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
701733
"""
@@ -741,6 +773,8 @@ def is_absolute(self) -> bool:
741773
def ast_rvalue(
742774
self,
743775
astree: ASTInterface,
776+
iaddr: Optional[str] = None,
777+
bytestring: Optional[str] = None,
744778
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
745779
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
746780
return (astree.mk_integer_constant(self.address.get_int()), [], [])
@@ -765,6 +799,8 @@ def address(self) -> "AsmAddress":
765799
def ast_rvalue(
766800
self,
767801
astree: ASTInterface,
802+
iaddr: Optional[str] = None,
803+
bytestring: Optional[str] = None,
768804
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
769805
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
770806
gvname = "gv_" + self.address.get_hex()
@@ -854,6 +890,8 @@ def is_index(self) -> bool:
854890
def ast_lvalue(
855891
self,
856892
astree: ASTInterface,
893+
iaddr: Optional[str] = None,
894+
bytestring: Optional[str] = None,
857895
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
858896
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
859897
offset = self.memory_offset.ast_rvalue(astree)
@@ -864,7 +902,8 @@ def ast_lvalue(
864902

865903
if self.is_write_back:
866904
reglv = astree.mk_variable_lval(self.register)
867-
assign = astree.mk_assign(reglv, xindex)
905+
assign = astree.mk_assign(
906+
reglv, xindex, iaddr=iaddr, bytestring=bytestring)
868907
if self.is_index:
869908
memexp = astree.mk_memref_lval(xindex)
870909
return (memexp, [], [assign])
@@ -878,6 +917,8 @@ def ast_lvalue(
878917
def ast_addr_rvalue(
879918
self,
880919
astree: ASTInterface,
920+
iaddr: Optional[str] = None,
921+
bytestring: Optional[str] = None,
881922
vtype: Optional[AST.ASTTyp] = None) -> AST.ASTExpr:
882923
xreg = astree.mk_register_variable_expr(self.register, vtype=vtype)
883924
offset = self.memory_offset.ast_rvalue(astree)
@@ -889,9 +930,12 @@ def ast_addr_rvalue(
889930
def ast_rvalue(
890931
self,
891932
astree: ASTInterface,
933+
iaddr: Optional[str] = None,
934+
bytestring: Optional[str] = None,
892935
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
893936
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
894-
(lval, preinstrs, postinstrs) = self.ast_lvalue(astree, vtype=vtype)
937+
(lval, preinstrs, postinstrs) = self.ast_lvalue(
938+
astree, iaddr=iaddr, bytestring=bytestring, vtype=vtype)
895939
rval = astree.mk_lval_expr(lval)
896940
return (rval, preinstrs, postinstrs)
897941

@@ -940,13 +984,17 @@ def is_immediate(self) -> bool:
940984
def ast_lvalue(
941985
self,
942986
astree: ASTInterface,
987+
iaddr: Optional[str] = None,
988+
bytestring: Optional[str] = None,
943989
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
944990
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
945991
raise UF.CHBError("Immediate operand cannot be an lvalue")
946992

947993
def ast_rvalue(
948994
self,
949995
astree: ASTInterface,
996+
iaddr: Optional[str] = None,
997+
bytestring: Optional[str] = None,
950998
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
951999
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
9521000
return (astree.mk_integer_constant(self.value), [], [])
@@ -978,13 +1026,17 @@ def is_fp_constant(self) -> bool:
9781026
def ast_lvalue(
9791027
self,
9801028
astree: ASTInterface,
1029+
iaddr: Optional[str] = None,
1030+
bytestring: Optional[str] = None,
9811031
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
9821032
AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
9831033
raise UF.CHBError("Floating point constant cannot be an lvalue")
9841034

9851035
def ast_rvalue(
9861036
self,
9871037
astree: ASTInterface,
1038+
iaddr: Optional[str] = None,
1039+
bytestring: Optional[str] = None,
9881040
vtype: Optional[AST.ASTTyp] = None) -> Tuple[
9891041
AST.ASTExpr, List[AST.ASTInstruction], List[AST.ASTInstruction]]:
9901042
return (astree.mk_float_constant(self.floatvalue), [], [])

chb/arm/opcodes/ARMLoadRegister.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ def ast_prov(
232232

233233
# low-level assignment
234234

235-
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(astree)
235+
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(
236+
astree, iaddr=iaddr, bytestring=bytestring)
236237
(ll_op1, _, _) = self.opargs[1].ast_rvalue(astree)
237238
(ll_op2, _, _) = self.opargs[2].ast_rvalue(astree)
238239
(ll_lhs, _, _) = self.opargs[0].ast_lvalue(astree)
@@ -318,8 +319,10 @@ def has_cast() -> bool:
318319

319320
if self.opargs[3].is_indirect_register and self.opargs[3].is_write_back:
320321
addrop = cast("ARMOffsetAddressOp", self.opargs[3].opkind)
321-
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(astree)
322-
ll_addr_rhs = addrop.ast_addr_rvalue(astree)
322+
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(
323+
astree, iaddr=iaddr, bytestring=bytestring)
324+
ll_addr_rhs = addrop.ast_addr_rvalue(
325+
astree, iaddr=iaddr, bytestring=bytestring)
323326

324327
ll_addr_assign = astree.mk_assign(
325328
ll_addr_lhs,

chb/arm/opcodes/ARMLoadRegisterByte.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ def ast_prov(
233233

234234
# low-level assignment
235235

236-
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(astree)
236+
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(
237+
astree, iaddr=iaddr, bytestring=bytestring)
237238
(ll_op1, _, _) = self.opargs[1].ast_rvalue(astree)
238239
(ll_op2, _, _) = self.opargs[2].ast_rvalue(astree)
239240
(ll_lhs, _, _) = self.opargs[0].ast_lvalue(astree)
@@ -310,8 +311,10 @@ def has_cast() -> bool:
310311

311312
if self.opargs[3].is_indirect_register and self.opargs[3].is_write_back:
312313
addrop = cast("ARMOffsetAddressOp", self.opargs[3].opkind)
313-
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(astree)
314-
ll_addr_rhs = addrop.ast_addr_rvalue(astree)
314+
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(
315+
astree, iaddr=iaddr, bytestring=bytestring)
316+
ll_addr_rhs = addrop.ast_addr_rvalue(
317+
astree, iaddr=iaddr, bytestring=bytestring)
315318

316319
ll_addr_assign = astree.mk_assign(
317320
ll_addr_lhs,

chb/arm/opcodes/ARMLoadRegisterDual.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ def ast_prov(
236236

237237
# low-level assignments
238238

239-
(ll_rhs1, ll_pre1, ll_post1) = self.opargs[4].ast_rvalue(astree)
239+
(ll_rhs1, ll_pre1, ll_post1) = self.opargs[4].ast_rvalue(
240+
astree, iaddr=iaddr, bytestring=bytestring)
240241
(ll_lhs1, _, _) = self.opargs[0].ast_lvalue(astree)
241242

242243
ll_assign1 = astree.mk_assign(
@@ -246,7 +247,8 @@ def ast_prov(
246247
bytestring=bytestring,
247248
annotations=annotations)
248249

249-
(ll_rhs2, ll_pre2, ll_post2) = self.opargs[5].ast_rvalue(astree)
250+
(ll_rhs2, ll_pre2, ll_post2) = self.opargs[5].ast_rvalue(
251+
astree, iaddr=iaddr, bytestring=bytestring)
250252
(ll_lhs2, _, _) = self.opargs[1].ast_lvalue(astree)
251253

252254
ll_assign2 = astree.mk_assign(

chb/arm/opcodes/ARMLoadRegisterHalfword.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ def ast_prov(
227227

228228
# low-level assignment
229229

230-
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(astree)
230+
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(
231+
astree, iaddr=iaddr, bytestring=bytestring)
231232
(ll_op1, _, _) = self.opargs[1].ast_rvalue(astree)
232233
(ll_op2, _, _) = self.opargs[2].ast_rvalue(astree)
233234
(ll_lhs, _, _) = self.opargs[0].ast_lvalue(astree)
@@ -310,8 +311,10 @@ def has_cast() -> bool:
310311

311312
if self.opargs[3].is_indirect_register and self.opargs[3].is_write_back:
312313
addrop = cast("ARMOffsetAddressOp", self.opargs[3].opkind)
313-
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(astree)
314-
ll_addr_rhs = addrop.ast_addr_rvalue(astree)
314+
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(
315+
astree, iaddr=iaddr, bytestring=bytestring)
316+
ll_addr_rhs = addrop.ast_addr_rvalue(
317+
astree, iaddr=iaddr, bytestring=bytestring)
315318

316319
ll_addr_assign = astree.mk_assign(
317320
ll_addr_lhs,

chb/arm/opcodes/ARMLoadRegisterSignedByte.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def ast_prov(
155155

156156
# low-level assignment
157157

158-
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(astree)
158+
(ll_rhs, ll_pre, ll_post) = self.opargs[3].ast_rvalue(
159+
astree, iaddr=iaddr, bytestring=bytestring)
159160
(ll_op1, _, _) = self.opargs[1].ast_rvalue(astree)
160161
(ll_op2, _, _) = self.opargs[2].ast_rvalue(astree)
161162
(ll_lhs, _, _) = self.opargs[0].ast_lvalue(astree)
@@ -217,8 +218,10 @@ def ast_prov(
217218

218219
if self.opargs[3].is_indirect_register and self.opargs[3].is_write_back:
219220
addrop = cast("ARMOffsetAddressOp", self.opargs[3].opkind)
220-
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(astree)
221-
ll_addr_rhs = addrop.ast_addr_rvalue(astree)
221+
(ll_addr_lhs, _, _) = self.opargs[1].ast_lvalue(
222+
astree, iaddr=iaddr, bytestring=bytestring)
223+
ll_addr_rhs = addrop.ast_addr_rvalue(
224+
astree, iaddr=iaddr, bytestring=bytestring)
222225

223226
ll_addr_assign = astree.mk_assign(
224227
ll_addr_lhs,

0 commit comments

Comments
 (0)