commit c56f6c63f6ac730f6745e45020b51614e6f5e48f
parent aa25412557ade7364fe82a5beea5f1c565e058b3
Author: lash <dev@holbrook.no>
Date: Mon, 26 Aug 2024 22:41:30 +0100
Add missing file
Diffstat:
2 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/asm/flag.go b/asm/flag.go
@@ -0,0 +1,61 @@
+package asm
+
+import (
+ "encoding/csv"
+ "fmt"
+ "io"
+ "os"
+ "strconv"
+)
+
+type FlagParser struct {
+ flags map[string]string
+}
+
+func NewFlagParser() *FlagParser {
+ return &FlagParser{
+ flags: make(map[string]string),
+ }
+}
+
+func(pp *FlagParser) Get(key string) (string, error) {
+ v, ok := pp.flags[key]
+ if !ok {
+ return "", fmt.Errorf("no flag registered under key: %s", key)
+ }
+ return v, nil
+}
+
+func(pp *FlagParser) Load(fp string) (int, error) {
+ var i int
+ f, err := os.Open(fp)
+ if err != nil {
+ return 0, err
+ }
+ defer f.Close()
+ r := csv.NewReader(f)
+ for i = 0; true; i++ {
+ r, err := r.Read()
+ if err != nil {
+ if err == io.EOF {
+ break
+ }
+ return 0, err
+ }
+ if r[0] == "flag" {
+ if len(r) < 3 {
+ return 0, fmt.Errorf("Not enough fields for flag setting in line %d", i)
+ }
+ _, err = strconv.Atoi(r[2])
+ if err != nil {
+ return 0, fmt.Errorf("Flag translation value must be numeric")
+ }
+ pp.flags[r[1]] = r[2]
+ Logg.Debugf("added flag translation", "from", r[1], "to", r[2])
+ }
+ }
+
+ return i, nil
+}
+
+
diff --git a/dev/asm/main.go b/dev/asm/main.go
@@ -20,7 +20,6 @@ type arg struct {
One *string `(@Sym | @NumFirst)`
Two *string `((@Sym | @NumFirst) Whitespace?)?`
Three *string `((@Sym | @NumFirst) Whitespace?)?`
- //Desc *string `(Quote ((@Sym | @Size) @Whitespace?)+ Quote Whitespace?)?`
}
type instruction struct {