From 28245e92a297e51542961f1fde1895f2d2a71e58 Mon Sep 17 00:00:00 2001 From: andri lim Date: Fri, 22 Feb 2019 16:05:21 +0700 Subject: [PATCH] fixes #235 --- nimbus/vm/code_stream.nim | 4 +++- nimbus/vm/interpreter_dispatch.nim | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nimbus/vm/code_stream.nim b/nimbus/vm/code_stream.nim index 53921f655..85c16445b 100644 --- a/nimbus/vm/code_stream.nim +++ b/nimbus/vm/code_stream.nim @@ -152,7 +152,9 @@ proc displayDecompiled*(c: CodeStream) = for op in opcodes: echo op[0], " ", op[1], " ", op[2] - proc hasSStore*(c: var CodeStream): bool = let opcodes = c.decompile() result = opcodes.anyIt(it[1] == SSTORE) + +proc atEnd*(c: CodeStream): bool = + result = c.pc >= c.bytes.len diff --git a/nimbus/vm/interpreter_dispatch.nim b/nimbus/vm/interpreter_dispatch.nim index 62a5eaabc..08350897c 100644 --- a/nimbus/vm/interpreter_dispatch.nim +++ b/nimbus/vm/interpreter_dispatch.nim @@ -187,13 +187,17 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo # Add a branch for each (opcode, proc) pair # We dispatch to the next instruction at the end of each branch for op, opImpl in opTable.pairs: + let asOp = quote do: Op(`op`) # TODO: unfortunately when passing to runtime, ops are transformed into int let branchStmt = block: if op == Stop: quote do: trace "op: Stop" + if not `computation`.code.atEnd() and `computation`.tracingEnabled: + # we only trace `REAL STOP` and ignore `FAKE STOP` + let lastOpIndex = `computation`.traceOpCodeStarted(`asOp`) + `computation`.traceOpCodeEnded(`asOp`, lastOpIndex) break else: - let asOp = quote do: Op(`op`) # TODO: unfortunately when passing to runtime, ops are transformed into int if BaseGasCosts[op].kind == GckFixed: quote do: var lastOpIndex: int