2021-04-08 14:52:10 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
2021-04-20 15:39:32 +00:00
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
2021-04-08 14:52:10 +00:00
|
|
|
|
|
|
|
import
|
2021-04-20 15:39:32 +00:00
|
|
|
./compu_helper,
|
2021-04-21 08:06:46 +00:00
|
|
|
./interpreter/[gas_meter, op_handlers, op_handlers/oph_defs, gas_costs],
|
2021-04-20 15:39:32 +00:00
|
|
|
./code_stream,
|
|
|
|
./v2types,
|
|
|
|
chronicles
|
2021-04-08 14:52:10 +00:00
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "vm opcode"
|
|
|
|
|
2021-04-20 15:39:32 +00:00
|
|
|
proc selectVM*(c: Computation, fork: Fork) {.gcsafe.} =
|
2021-04-20 12:07:01 +00:00
|
|
|
var desc: Vm2Ctx
|
|
|
|
|
2021-04-20 11:14:43 +00:00
|
|
|
if c.tracingEnabled:
|
|
|
|
c.prepareTracer()
|
|
|
|
|
|
|
|
while true:
|
|
|
|
c.instr = c.code.next()
|
2021-04-20 12:07:01 +00:00
|
|
|
var op = c.instr
|
2021-04-20 11:14:43 +00:00
|
|
|
|
|
|
|
if op == Stop:
|
|
|
|
trace "op: Stop"
|
|
|
|
if not c.code.atEnd() and c.tracingEnabled:
|
|
|
|
c.opIndex = c.traceOpCodeStarted(Stop)
|
|
|
|
c.traceOpCodeEnded(Stop, c.opIndex)
|
|
|
|
break
|
|
|
|
|
|
|
|
if c.tracingEnabled:
|
|
|
|
c.opIndex = c.traceOpCodeStarted(op)
|
|
|
|
if BaseGasCosts[op].kind == GckFixed:
|
|
|
|
c.gasMeter.consumeGas(c.gasCosts[op].cost, reason = $op)
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
desc.cpt = c
|
2021-04-20 11:14:43 +00:00
|
|
|
opHandlersRun(fork, op, desc)
|
|
|
|
|
|
|
|
if c.tracingEnabled:
|
|
|
|
c.traceOpCodeEnded(op, c.opIndex)
|
|
|
|
|
|
|
|
case op
|
|
|
|
of Create, Create2, Call, CallCode, DelegateCall, StaticCall:
|
|
|
|
if not c.continuation.isNil:
|
2021-04-20 12:07:01 +00:00
|
|
|
break
|
2021-04-20 11:14:43 +00:00
|
|
|
of Return, Revert, SelfDestruct:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
discard
|
|
|
|
|