aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJhih-Ming Huang <jm.huang@cobinhood.com>2019-03-15 17:36:14 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-04-11 10:39:59 +0800
commit83cc9f585ef42031d045282cb9ea7f6190c24282 (patch)
tree01bdce2d41a30336b23e6dffd291ca41bd534819
parent978fa21ee0b38b5be13de6cff9da33057f3f9813 (diff)
downloaddexon-83cc9f585ef42031d045282cb9ea7f6190c24282.tar
dexon-83cc9f585ef42031d045282cb9ea7f6190c24282.tar.gz
dexon-83cc9f585ef42031d045282cb9ea7f6190c24282.tar.bz2
dexon-83cc9f585ef42031d045282cb9ea7f6190c24282.tar.lz
dexon-83cc9f585ef42031d045282cb9ea7f6190c24282.tar.xz
dexon-83cc9f585ef42031d045282cb9ea7f6190c24282.tar.zst
dexon-83cc9f585ef42031d045282cb9ea7f6190c24282.zip
core: vm: sqlvm: runtime: add loadRegister func
Implement load register to input operands, before each op.
-rw-r--r--core/vm/sqlvm/runtime/instructions.go2
-rw-r--r--core/vm/sqlvm/runtime/runtime.go9
2 files changed, 10 insertions, 1 deletions
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
index 9ecc41231..668da692c 100644
--- a/core/vm/sqlvm/runtime/instructions.go
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -57,5 +57,5 @@ type Operand struct {
IsImmediate bool
Meta []ast.DataType
Data []Tuple
- RegisterIndex *int
+ RegisterIndex uint
}
diff --git a/core/vm/sqlvm/runtime/runtime.go b/core/vm/sqlvm/runtime/runtime.go
index a8f8db7ee..8c3a105ac 100644
--- a/core/vm/sqlvm/runtime/runtime.go
+++ b/core/vm/sqlvm/runtime/runtime.go
@@ -10,6 +10,7 @@ import (
func Run(stateDB vm.StateDB, ins []Instruction, registers []*Operand) (ret []byte, err error) {
for _, in := range ins {
opFunc := jumpTable[in.Op]
+ loadRegister(in.Input, registers)
errCode := opFunc(&common.Context{}, in.Input, registers, in.Output)
if errCode != nil {
err = errors.Error{
@@ -23,3 +24,11 @@ func Run(stateDB vm.StateDB, ins []Instruction, registers []*Operand) (ret []byt
// TODO: ret = ABIEncode(ins[len(ins)-1].Output)
return
}
+
+func loadRegister(input, registers []*Operand) {
+ for i, operand := range input {
+ if operand != nil && !operand.IsImmediate {
+ input[i] = registers[operand.RegisterIndex]
+ }
+ }
+}