forked from extremecoders-re/bytecode_simplifier
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicblock.py
More file actions
Latest commit
35 lines (29 loc) · 1010 Bytes
/
Copy pathbasicblock.py
File metadata and controls
35 lines (29 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
classBasicBlock:
"""
A basic block is a set of instructions, that has a single entry and single exit.
Execution begins from the top and ends at the bottom. There can be no branching
in between.
"""
def__init__(self):
self.address=0
self.instructions= []
self.has_xrefs_to=False
# Instructions which xreference this basic block
self.xref_instructions= []
# b_seen is used to perform a DFS of basicblocks
self.b_seen=False
defadd_instruction(self, ins):
self.instructions.append(ins)
definstruction_iter(self):
"""
An iterator for traversing over the instructions.
:return: An iterator for iterating over the instruction
"""
forinsinself.instructions:
yieldins
defsize(self):
"""
Calculates the size of the basic block
:return:
"""
returnreduce(lambdax, ins: x+ins.size, self.instructions, 0)