diff options
author | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-03-15 17:36:14 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-03-26 17:48:22 +0800 |
commit | 6d039362787332877704901fd393505544555f1b (patch) | |
tree | 4bcda75f40f06bc07313b4d0ecb25aa4d71fb428 | |
parent | 95fab1aca3f01c33491b6a4840b0e2d814aa6e77 (diff) | |
download | dexon-6d039362787332877704901fd393505544555f1b.tar.gz dexon-6d039362787332877704901fd393505544555f1b.tar.zst dexon-6d039362787332877704901fd393505544555f1b.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.go | 2 | ||||
-rw-r--r-- | core/vm/sqlvm/runtime/runtime.go | 9 |
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] + } + } +} |