commit 893f0b89b8254f5c20c7ccc379971c758e84f5c8
parent d71924386ddda2af1322442efe4775d442433b42
Author: Gabriel G. de Brito <gabrielgbrito@icloud.com>
Date: Wed, 13 Dec 2023 23:23:54 -0300
Implemented functional Machine interface
Diffstat:
3 files changed, 61 insertions(+), 22 deletions(-)
diff --git a/machine.go b/machine.go
@@ -1,19 +0,0 @@
-package main
-
-// Interface that machine structs are required to implement to work with EGG.
-//
-// It always use uint64 because if we used variable-lengh []bytes, they would
-// need to be stored on the heap. Converting from any size less than and to 64
-// bits can be done with a single x86 instruction.
-type Machine interface {
- LoadProgram([]uint8) error
- NextInstruction() error
- GetMemory(uint64) (uint64, error)
- SetMemory(uint64, uint64) error
- // Address than size.
- GetMemoryChunk(uint64, uint64) ([]uint8, error)
- SetMemoryChunk(uint64, []uint8) error
- GetRegister(uint64) (uint64, error)
- // Address than content.
- SetRegister(uint64, uint64) error
-}
diff --git a/machine/machine.go b/machine/machine.go
@@ -0,0 +1,20 @@
+// Package egg/machine has the interface used by EGG backends.
+package machine
+
+// Interface that machine structs are required to implement to work with EGG.
+//
+// It always use uint64 because if we used variable-lengh []bytes, they would
+// need to be stored on the heap. Converting from any size less than and to 64
+// bits can be done with a single x86 instruction.
+type Machine interface {
+ LoadProgram([]uint8) error
+ NextInstruction() error
+ GetMemory(uint64) (uint8, error)
+ SetMemory(uint64, uint8) error
+ // Address than size.
+ GetMemoryChunk(uint64, uint64) ([]uint8, error)
+ SetMemoryChunk(uint64, []uint8) error
+ GetRegister(uint64) (uint64, error)
+ // Address than content.
+ SetRegister(uint64, uint64) error
+}
diff --git a/main.go b/main.go
@@ -1,11 +1,49 @@
package main
import (
- "fmt"
+ "flag"
- // "github.com/gboncoffee/egg/riscv"
+ "github.com/gboncoffee/egg/riscv"
+ "github.com/gboncoffee/egg/machine"
)
+func runMachine(m machine.Machine) {
+ panic("not yet implemented")
+}
+
+func debugMachine(m machine.Machine) {
+ panic("not yet implemented")
+}
+
func main() {
- fmt.Println("Hello, World!")
+ var architeture string
+ var debug bool
+ var file string
+ var outf string
+ var m machine.Machine
+
+ // Add new architetures to the help string!
+ flag.StringVar(&architeture, "arch", "riscv", "Select architeture to use. Currently available: 'riscv'.")
+ flag.StringVar(&architeture, "a", "riscv", "Select architeture to use (shorthand).")
+ flag.BoolVar(&debug, "debug", false, "Enter debugger upon startup.")
+ flag.BoolVar(&debug, "d", false, "Enter debugger upon startup (shorthand).")
+ flag.StringVar(&file, "file", "", "Assembly source or ELF file to load.")
+ flag.StringVar(&file, "f", "", "Assembly source or ELF file to load (shorthand).")
+ flag.StringVar(&outf, "out", "", "ELF file to save assembled code.")
+ flag.StringVar(&outf, "o", "", "ELF file to save assembled code (shorthand).")
+
+ flag.Parse()
+
+ // And the switch case!
+ switch architeture {
+ case "riscv":
+ var r riscv.RiscV
+ m = &r
+ }
+
+ if debug {
+ debugMachine(m)
+ } else {
+ runMachine(m)
+ }
}