Skip to content

Commit bef1465

Browse files
Merge branch 'bug-fix-benchmark-script' into counting-update
2 parents 5faf9d0 + 50ac5eb commit bef1465

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/main/java/it/unipr/analysis/contract/SmartContract.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ public JSONObject toJson() {
814814
jsonObject.put("basic_blocks_pc", _basicBlocks != null ? BasicBlock.basicBlocksToLongArrayToString(
815815
BasicBlock.basicBlocksToLongArray(_basicBlocks)) : new JSONArray());
816816

817+
jsonObject.put("last_pc", this._cfg.getLastOpcodePc());
818+
817819
jsonObject.put("execution_time", _executionTime);
818820

819821
return jsonObject;

src/main/java/it/unipr/cfg/EVMCFG.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ public Set<Statement> getExternalData() {
114114
return this.externalData;
115115
}
116116

117+
/**
118+
* Yields the program counter of the last opcode in the CFG.
119+
* This method iterates over all basic blocks and their statements to find
120+
* the highest program counter value, which corresponds to the last instruction
121+
* in the bytecode.
122+
*
123+
* @return the maximum program counter found among all statements
124+
*/
125+
public int getLastOpcodePc() {
126+
int maxPc = 0;
127+
Set<BasicBlock> bbs = getAllBasicBlocks();
128+
for (BasicBlock bb : bbs) {
129+
int max = 0;
130+
for (Statement st : bb.getStatements())
131+
if (((ProgramCounterLocation) st.getLocation()).getPc() > max)
132+
max = ((ProgramCounterLocation) st.getLocation()).getPc();
133+
if (max > maxPc)
134+
maxPc = max;
135+
}
136+
137+
return maxPc;
138+
}
139+
117140
/**
118141
* Returns a set of all the SSTORE statements in the CFG.
119142
*

0 commit comments

Comments
 (0)