Skip to content

Commit

Permalink
Vm2Ctx -> VmCtx, Vm2Op -> VmOp (#2369)
Browse files Browse the repository at this point in the history
Legacy evm  have been removed, no longer to keep the Vm2 prefix.
  • Loading branch information
jangko committed Jun 15, 2024
1 parent 242bbf0 commit 27d7102
Show file tree
Hide file tree
Showing 17 changed files with 461 additions and 461 deletions.
12 changes: 6 additions & 6 deletions nimbus/evm/interpreter/op_dispatcher.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export
# Helpers
# ------------------------------------------------------------------------------

template handleStopDirective(k: var Vm2Ctx) =
template handleStopDirective(k: var VmCtx) =
#trace "op: Stop"
if not k.cpt.code.atEnd() and k.cpt.tracingEnabled:
# we only trace `REAL STOP` and ignore `FAKE STOP`
k.cpt.opIndex = k.cpt.traceOpCodeStarted(Stop)
k.cpt.traceOpCodeEnded(Stop, k.cpt.opIndex)


template handleFixedGasCostsDirective(fork: EVMFork; op: Op; k: var Vm2Ctx) =
template handleFixedGasCostsDirective(fork: EVMFork; op: Op; k: var VmCtx) =
if k.cpt.tracingEnabled:
k.cpt.opIndex = k.cpt.traceOpCodeStarted(op)

Expand All @@ -56,7 +56,7 @@ template handleFixedGasCostsDirective(fork: EVMFork; op: Op; k: var Vm2Ctx) =
k.cpt.traceOpCodeEnded(op, k.cpt.opIndex)


template handleOtherDirective(fork: EVMFork; op: Op; k: var Vm2Ctx) =
template handleOtherDirective(fork: EVMFork; op: Op; k: var VmCtx) =
if k.cpt.tracingEnabled:
k.cpt.opIndex = k.cpt.traceOpCodeStarted(op)

Expand Down Expand Up @@ -124,11 +124,11 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
# Public macros/functions
# ------------------------------------------------------------------------------

macro genOptimisedDispatcher*(fork: EVMFork; op: Op; k: Vm2Ctx): untyped =
macro genOptimisedDispatcher*(fork: EVMFork; op: Op; k: VmCtx): untyped =
result = fork.toCaseStmt(op, k)


template genLowMemDispatcher*(fork: EVMFork; op: Op; k: Vm2Ctx) =
template genLowMemDispatcher*(fork: EVMFork; op: Op; k: VmCtx) =
if op == Stop:
handleStopDirective(k)
break
Expand All @@ -155,7 +155,7 @@ when isMainModule and isChatty:
import ../types

proc optimised(c: Computation, fork: EVMFork): EvmResultVoid {.compileTime.} =
var desc: Vm2Ctx
var desc: VmCtx
while true:
genOptimisedDispatcher(fork, desc.cpt.instr, desc)

Expand Down
48 changes: 24 additions & 24 deletions nimbus/evm/interpreter/op_handlers.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http:https://www.apache.org/licenses/LICENSE-2.0)
Expand Down Expand Up @@ -28,25 +28,25 @@ import

const
allHandlersList = @[
(vm2OpExecArithmetic, "Arithmetic"),
(vm2OpExecHash, "Hash"),
(vm2OpExecEnvInfo, "EnvInfo"),
(vm2OpExecBlockData, "BlockData"),
(vm2OpExecMemory, "Memory"),
(vm2OpExecPush, "Push"),
(vm2OpExecPushZero, "PushZero"),
(vm2OpExecDup, "Dup"),
(vm2OpExecSwap, "Swap"),
(vm2OpExecLog, "Log"),
(vm2OpExecCreate, "Create"),
(vm2OpExecCall, "Call"),
(vm2OpExecSysOp, "SysOp")]
(VmOpExecArithmetic, "Arithmetic"),
(VmOpExecHash, "Hash"),
(VmOpExecEnvInfo, "EnvInfo"),
(VmOpExecBlockData, "BlockData"),
(VmOpExecMemory, "Memory"),
(VmOpExecPush, "Push"),
(VmOpExecPushZero, "PushZero"),
(VmOpExecDup, "Dup"),
(VmOpExecSwap, "Swap"),
(VmOpExecLog, "Log"),
(VmOpExecCreate, "Create"),
(VmOpExecCall, "Call"),
(VmOpExecSysOp, "SysOp")]

# ------------------------------------------------------------------------------
# Helper
# ------------------------------------------------------------------------------

proc mkOpTable(selected: EVMFork): array[Op,Vm2OpExec] {.compileTime.} =
proc mkOpTable(selected: EVMFork): array[Op,VmOpExec] {.compileTime.} =

# Collect selected <fork> entries
for (subList,subName) in allHandlersList:
Expand Down Expand Up @@ -75,8 +75,8 @@ proc mkOpTable(selected: EVMFork): array[Op,Vm2OpExec] {.compileTime.} =
# ------------------------------------------------------------------------------

#const
# vm2OpHandlers* = block:
# var rc: array[Fork, array[Op, Vm2OpExec]]
# VmOpHandlers* = block:
# var rc: array[Fork, array[Op, VmOpExec]]
# for w in Fork:
# rc[w] = w.mkOpTable
# rc
Expand All @@ -85,7 +85,7 @@ type
vmOpHandlersRec* = tuple
name: string ## Name (or ID) of op handler
info: string ## Some op handler info
run: Vm2OpFn ## Executable handler
run: VmOpFn ## Executable handler

const
# Pack handler record.
Expand All @@ -97,12 +97,12 @@ const
#
# to pick right function when <op> is a variable . Using
#
# vm2OpHandlers[fork][op].exec.run
# VmOpHandlers[fork][op].exec.run
#
# only works when <op> is a constant. There seems to be some optimisation
# that garbles the <exec> sub-structures elements <prep>, <run>, and <post>.
# Moreover, <post> is seen NULL under the debugger. It is untested yet
# under what circumstances the vm2OpHandlers[] matrix is set up correctly.
# under what circumstances the VmOpHandlers[] matrix is set up correctly.
# Linearising/flattening the index has no effect here.
#
vmOpHandlers* = ## Op handler records matrix indexed `fork` x `op`
Expand All @@ -122,7 +122,7 @@ const

when isMainModule and isChatty:

proc opHandlersRun(fork: EVMFork; op: Op; d: var Vm2Ctx) {.used.} =
proc opHandlersRun(fork: EVMFork; op: Op; d: var VmCtx) {.used.} =
## Given a particular `fork` and an `op`-code, run the associated handler
vmOpHandlers[fork][op].run(d)

Expand All @@ -140,10 +140,10 @@ when isMainModule and isChatty:
echo ">>> berlin[swap16]: ", FkBerlin.opHandlersInfo(Swap16)
echo ">>> berlin[log4]: ", FkBerlin.opHandlersInfo(Log4)

echo ">>> frontier[sstore]: ", FkFrontier.opHandlersInfo(Sstore)
echo ">>> frontier[sstore]: ", FkFrontier.opHandlersInfo(Sstore)
echo ">>> constantinople[sstore]: ", FkConstantinople.opHandlersInfo(Sstore)
echo ">>> berlin[sstore]: ", FkBerlin.opHandlersInfo(Sstore)
echo ">>> paris[sstore]: ", FkParis.opHandlersInfo(Sstore)
echo ">>> berlin[sstore]: ", FkBerlin.opHandlersInfo(Sstore)
echo ">>> paris[sstore]: ", FkParis.opHandlersInfo(Sstore)

# ------------------------------------------------------------------------------
# End
Expand Down
Loading

0 comments on commit 27d7102

Please sign in to comment.