-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.go
34 lines (27 loc) · 940 Bytes
/
machine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package machine
import (
"errors"
"github.com/Moleus/comp-arch-lab3/pkg/isa"
"io"
"log"
)
type Machine struct {
}
type SimulationStatistics struct {
}
func RunSimulation(dataInput []isa.IoData, program isa.Program, dataPathOutput io.Writer, controlUnitStateOutput io.Writer) error {
clock := &Clock{currentTick: 0}
dataPath := NewDataPath(dataInput, dataPathOutput, clock)
controlUnit := NewControlUnit(program, dataPath, controlUnitStateOutput, clock)
log.Println("starting simulation")
controlUnit.PresetInstructionCounter(controlUnit.program.StartAddress)
err := controlUnit.RunInstructionCycle()
var controlUnitError *ControlUnitError
if err == nil {
return errors.New("simulation should finish with HLT")
} else if !errors.As(err, &controlUnitError) {
return err
}
log.Printf("simulation finished. Instructions executed: %d, ticks: %d", controlUnit.ExecutedInstructions, clock.GetCurrentTick())
return nil
}