-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.go
More file actions
53 lines (44 loc) · 1.6 KB
/
flags.go
File metadata and controls
53 lines (44 loc) · 1.6 KB
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
package main
import (
"flag"
"fmt"
"os"
)
type flags struct {
inFile string // input file name
outFile string // output file name
outFmt string // output format
nopBuff uint // number of nop instructions to include after each instruction
quiet bool // suppress printing version and status stdout
instruction string // instruction to assemble
}
// printUsage prints help information to the flag output (defaults to stderr).
func printUsage() {
fmt.Fprint(flag.CommandLine.Output(),
"Usage of dsdii-assembler:\n",
"\tdsdii-assembler version\n",
"\tdsdii-assembler [options...] <instruction>\n\n",
"Options:\n",
)
flag.PrintDefaults()
}
// parseFlags parses the command line flags and returns a flags struct.
//
// If the first argument is "version", the version is printed and the program
// exits with status 0.
func parseFlags() flags {
var f flags
flag.Usage = printUsage
flag.StringVar(&f.inFile, "i", "", "Input file containing assembly instructions. If not set, the instruction parameter should contain the singular instruction to be assembled.")
flag.StringVar(&f.outFile, "o", "stdout", "Output file to write machine code to.")
flag.StringVar(&f.outFmt, "out-fmt", "hex", "Output format (hex, vhdl-byte, vhdl-word, binary, binary-nibble, binary-byte).")
flag.UintVar(&f.nopBuff, "nop-buff", 0, "Optional number of nop instructions to include after each instruction.")
flag.BoolVar(&f.quiet, "q", false, "Suppress printing version and status to stdout.")
flag.Parse()
if flag.Arg(0) == "version" {
printVersion()
os.Exit(0)
}
f.instruction = flag.Arg(0)
return f
}