-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.go
84 lines (68 loc) · 1.74 KB
/
cli.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"strconv"
"strings"
"github.com/alexflint/go-arg"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
type argsParsed struct {
args
}
// Used to parse hexadecimal/decimal arguments as uint32
type HexUint uint32
func (h *HexUint) UnmarshalText(b []byte) error {
input := string(b)
var v uint64
var err error
// Check if the input string starts with "0x" or "0X" for hexadecimal
if strings.HasPrefix(input, "0x") || strings.HasPrefix(input, "0X") {
v, err = strconv.ParseUint(input, 0, 32)
} else {
// Assume decimal if not hexadecimal
v, err = strconv.ParseUint(input, 10, 32)
}
if err != nil {
return err
}
*h = HexUint(v)
return nil
}
func (args) Epilogue() string {
return "For more information visit github.com/Kaweees/RivoGo"
}
// CLI arguments
type args struct {
// File config
FileName string `arg:"required" help:"Image file to virtualize"`
// Logging config
Logging bool `arg:"-l,--logging" help:"Enable logging"`
// Starting address
Start HexUint `arg:"help:Program counter starting address"`
// Memory length
Length HexUint `arg:"-n,--length" help:"Memory length"`
}
// Returns a human-readable version string
func (args) Version() string {
return fmt.Sprintf("Version: %v, commit: %v, built at: %v", version, commit, date)
}
// Returns a description of the program
func (args) Description() string {
return "A simple assembler for the RISC-V architecture"
}
// Returns the parsed CLI arguments
func GetCliArgs() (cli argsParsed, err error) {
rawCli := args{
Logging: false,
Start: HexUint(PC_START),
Length: HexUint(MEM_MAX_SIZE),
}
arg.MustParse(&rawCli)
cli.args = rawCli
fmt.Printf("Parsed value: %d (hex: %x)\n", cli.Start, uint32(cli.Start))
return cli, nil
}