Skip to content

Commit 4f84c05

Browse files
committed
CMD:CFG: add option to show nodes with NOPS
1 parent 5404691 commit 4f84c05

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

chb/app/Instruction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ def is_store_instruction(self) -> bool:
206206
def is_return_instruction(self) -> bool:
207207
...
208208

209+
@property
210+
def is_nop_instruction(self) -> bool:
211+
return False
212+
209213
@property
210214
@abstractmethod
211215
def call_target(self) -> CallTarget:

chb/arm/ARMInstruction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def is_store_instruction(self) -> bool:
171171
def is_return_instruction(self) -> bool:
172172
return self.opcode.is_return_instruction(self.xdata)
173173

174+
@property
175+
def is_nop_instruction(self) -> bool:
176+
return self.opcode.is_nop_instruction(self.xdata)
177+
174178
def return_value(self) -> Optional[XXpr]:
175179
if self.is_return_instruction:
176180
return self.opcode.return_value(self.xdata)

chb/arm/ARMOpcode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ def is_load_instruction(self, xdata: InstrXData) -> bool:
408408
def is_store_instruction(self, xdata: InstrXData) -> bool:
409409
return False
410410

411+
def is_nop_instruction(self, xdata: InstrXData) -> bool:
412+
return False
413+
411414
def simulate(self, iaddr: str, simstate: "SimulationState") -> str:
412415
raise SU.CHBSimError(
413416
simstate,

chb/arm/opcodes/ARMMove.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def opargs(self) -> List[ARMOperand]:
9898
def operandstring(self) -> str:
9999
return ", ".join(str(op) for op in self.operands)
100100

101+
def is_nop_instruction(self, xdata: InstrXData) -> bool:
102+
return xdata.is_nop
103+
101104
def annotation(self, xdata: InstrXData) -> str:
102105
if xdata.is_nop:
103106
return "NOP"

chb/cmdline/chkx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ def parse() -> argparse.Namespace:
759759
'--calls',
760760
action="store_true",
761761
help="add calls to nodes")
762+
showcfg.add_argument(
763+
"--nops",
764+
action="store_true",
765+
help="show node in yellow if first instruction is a no-op")
762766
showcfg.add_argument(
763767
"--instr_opcodes",
764768
action="store_true",

chb/cmdline/commandutil.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ def showcfg(args: argparse.Namespace) -> NoReturn:
17641764
xview: bool = args.view
17651765
xpredicates: bool = args.predicates
17661766
xcalls: bool = args.calls
1767+
xnops: bool = args.nops
17671768
xstores: bool = args.stores
17681769
xinstr_opcodes: bool = args.instr_opcodes
17691770
xinstr_text: bool = args.instr_text
@@ -1811,6 +1812,10 @@ def showcfg(args: argparse.Namespace) -> NoReturn:
18111812
if any(k.is_unreachable for k in invariants[b]):
18121813
nodecolors[b] = "grey"
18131814

1815+
if xnops:
1816+
if f.instruction(b).is_nop_instruction:
1817+
nodecolors[b] = "yellow"
1818+
18141819
if xjson:
18151820
fresult = JU.function_cfg_to_json_result(f)
18161821
if fresult.is_ok:

0 commit comments

Comments
 (0)