summaryrefslogtreecommitdiff
path: root/as/main.go
diff options
context:
space:
mode:
authorstefan <stefan@s00.xyz>2023-05-24 08:32:08 -0400
committerstefan <stefan@s00.xyz>2023-05-24 08:32:08 -0400
commitba2b9c8a1bb1876b6eb4c9783fde798b19de4418 (patch)
tree9b49307112b0f489189cf65c1b50dd281f8e430f /as/main.go
parentc30e7f5f99f9ad4d9552b645d7b89d7385972f99 (diff)
downloadevm-ba2b9c8a1bb1876b6eb4c9783fde798b19de4418.tar.gz
init
Diffstat (limited to 'as/main.go')
-rw-r--r--as/main.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/as/main.go b/as/main.go
new file mode 100644
index 0000000..95aff46
--- /dev/null
+++ b/as/main.go
@@ -0,0 +1,59 @@
+package main
+
+import (
+ "os"
+ "fmt"
+)
+
+func usage(arg0 string) {
+ fmt.Fprintf(os.Stderr, "usage: %s [-o file] file.easm\n", os.Args[0])
+ os.Exit(1)
+}
+
+func main() {
+ if (len(os.Args) <= 2) {
+ usage(os.Args[0])
+ }
+
+
+ var aout int = 0
+ var ain int = 0
+
+ for i := 0; i < len(os.Args); i++ {
+ fmt.Println(os.Args[i])
+ switch os.Args[i] {
+ case "-o":
+ i = i + 1
+ aout = i
+ default:
+ ain = i
+ }
+ }
+
+ if (ain == 0) {
+ usage(os.Args[0])
+ }
+
+ var outf string = "out.bin"
+ if (aout != 0) {
+ outf = os.Args[aout]
+ }
+
+ b, errin := os.ReadFile(os.Args[ain])
+ out, errout := os.Create(outf)
+
+ if errin != nil {
+ fmt.Fprintf(os.Stderr, "failed to read file: %s\n", os.Args[ain])
+ os.Exit(1)
+ }
+
+ if errout != nil {
+ fmt.Fprintf(os.Stderr, "failed to create file for output: %s\n", outf)
+ os.Exit(1)
+ }
+
+ s := string(b)
+ c := Assemble(s)
+
+ out.Write(c)
+}