Disassembler skeleton
This commit is contained in:
@@ -42,7 +42,7 @@ func (state *State) stackFrame() *stackFrame {
|
||||
return state.stack[len(state.stack)-1]
|
||||
}
|
||||
|
||||
func (state *State) function() []*Instruction {
|
||||
func (state *State) function() *Function {
|
||||
return state.program.Functions[state.functionIndex]
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func (state *State) setError(err error) {
|
||||
|
||||
func (state *State) setHandlers() {
|
||||
for _, fnc := range state.program.Functions {
|
||||
for _, instr := range fnc {
|
||||
for _, instr := range fnc.Instructions {
|
||||
handler, found := opHandlers[instr.OpCode]
|
||||
if !found {
|
||||
state.setError(fmt.Errorf("Invalid OpCode: 0x%08x", instr.OpCode))
|
||||
@@ -67,7 +67,7 @@ func (state *State) setHandlers() {
|
||||
|
||||
func (state *State) processInstruction() {
|
||||
fnc := state.function()
|
||||
instr := fnc[state.instructionIndex]
|
||||
instr := fnc.Instructions[state.instructionIndex]
|
||||
state.instructionIndex += 1
|
||||
instr.opHandler(state, instr)
|
||||
|
||||
@@ -75,7 +75,7 @@ func (state *State) processInstruction() {
|
||||
state.ret()
|
||||
}
|
||||
|
||||
if state.instructionIndex >= int64(len(fnc)) {
|
||||
if state.instructionIndex >= int64(len(fnc.Instructions)) {
|
||||
state.ret()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user