stubbing berlin opcodes

This commit is contained in:
jangko 2020-11-25 16:43:34 +07:00
parent e2cd9b20fa
commit 5a78b8a5a7
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
4 changed files with 35 additions and 1 deletions

View File

@ -535,6 +535,9 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
Msize: fixed GasBase,
Gas: fixed GasBase,
JumpDest: fixed GasJumpDest,
BeginSub: fixed GasBase,
ReturnSub: fixed GasLow,
JumpSub: fixed GasHigh,
# 60s & 70s: Push Operations
Push1: fixed GasVeryLow,

View File

@ -95,6 +95,9 @@ fill_enum_holes:
Msize = 0x59, # Get the size of active memory in bytes.
Gas = 0x5a, # Get the amount of available gas, including the corresponding reduction for the cost of this instruction.
JumpDest = 0x5b, # Mark a valid destination for jumps. This operation has no effect on machine state during execution.
BeginSub = 0x5c, # Marks the entry point to a subroutine
ReturnSub = 0x5d, # Returns control to the caller of a subroutine.
JumpSub = 0x5e, # Transfers control to a subroutine.
# 60s & 70s: Push Operations.
Push1 = 0x60, # Place 1-byte item on stack.

View File

@ -542,6 +542,18 @@ op jumpDest, inline = true:
## 0x5b, Mark a valid destination for jumps. This operation has no effect on machine state during execution.
discard
op beginSub, inline = true:
## 0x5c, Marks the entry point to a subroutine
discard
op returnSub, inline = true:
## 0x5d, Returns control to the caller of a subroutine.
discard
op jumpSub, inline = true:
## 0x5e, Transfers control to a subroutine.
discard
# ##########################################
# 60s & 70s: Push Operations.
# 80s: Duplication Operations

View File

@ -229,6 +229,14 @@ proc genIstanbulJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compile
let IstanbulOpDispatch {.compileTime.}: array[Op, NimNode] = genIstanbulJumpTable(PetersburgOpDispatch)
proc genBerlinJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTime.} =
result = ops
result[BeginSub] = newIdentNode "beginSub"
result[ReturnSub] = newIdentNode "returnSub"
result[JumpSub] = newIdentNode "jumpSub"
let BerlinOpDispatch {.compileTime.}: array[Op, NimNode] = genBerlinJumpTable(IstanbulOpDispatch)
proc opTableToCaseStmt(opTable: array[Op, NimNode], c: NimNode): NimNode =
let instr = quote do: `c`.instr
@ -308,6 +316,9 @@ macro genPetersburgDispatch(c: Computation): untyped =
macro genIstanbulDispatch(c: Computation): untyped =
result = opTableToCaseStmt(IstanbulOpDispatch, c)
macro genBerlinDispatch(c: Computation): untyped =
result = opTableToCaseStmt(BerlinOpDispatch, c)
proc frontierVM(c: Computation) =
genFrontierDispatch(c)
@ -332,6 +343,9 @@ proc petersburgVM(c: Computation) {.gcsafe.} =
proc istanbulVM(c: Computation) {.gcsafe.} =
genIstanbulDispatch(c)
proc berlinVM(c: Computation) {.gcsafe.} =
genBerlinDispatch(c)
proc selectVM(c: Computation, fork: Fork) {.gcsafe.} =
# TODO: Optimise getting fork and updating opCodeExec only when necessary
case fork
@ -349,8 +363,10 @@ proc selectVM(c: Computation, fork: Fork) {.gcsafe.} =
c.constantinopleVM()
of FkPetersburg:
c.petersburgVM()
else:
of FkIstanbul:
c.istanbulVM()
else:
c.berlinVM()
proc executeOpcodes(c: Computation) =
let fork = c.fork