From 6d6da8295a287039805e8ed070c8b57ec3e70caa Mon Sep 17 00:00:00 2001 From: Jhih-Ming Huang Date: Fri, 15 Mar 2019 17:36:14 +0800 Subject: core: vm: sqlvm: runtime: add loadRegister func Implement load register to input operands, before each op. --- core/vm/sqlvm/runtime/instructions.go | 2 +- core/vm/sqlvm/runtime/runtime.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'core') 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] + } + } +} -- cgit v1.2.3