Skip to content

Commit a0908ff

Browse files
kenbelldeadprogram
authored andcommitted
compiler: openocd commands in tinygo command line
1 parent 2f1f8fb commit a0908ff

File tree

3 files changed

+55
-35
lines changed

3 files changed

+55
-35
lines changed

builder/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,28 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
1717
if err != nil {
1818
return nil, err
1919
}
20+
21+
if options.OpenOCDCommands != nil {
22+
// Override the OpenOCDCommands from the target spec if specified on
23+
// the command-line
24+
spec.OpenOCDCommands = options.OpenOCDCommands
25+
}
26+
2027
goroot := goenv.Get("GOROOT")
2128
if goroot == "" {
2229
return nil, errors.New("cannot locate $GOROOT, please set it manually")
2330
}
31+
2432
major, minor, err := goenv.GetGorootVersion(goroot)
2533
if err != nil {
2634
return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err)
2735
}
2836
if major != 1 || minor < 13 || minor > 16 {
2937
return nil, fmt.Errorf("requires go version 1.13 through 1.16, got go%d.%d", major, minor)
3038
}
39+
3140
clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT"))
41+
3242
return &compileopts.Config{
3343
Options: options,
3444
Target: spec,

compileopts/options.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,25 @@ var (
1717
// Options contains extra options to give to the compiler. These options are
1818
// usually passed from the command line.
1919
type Options struct {
20-
Target string
21-
Opt string
22-
GC string
23-
PanicStrategy string
24-
Scheduler string
25-
PrintIR bool
26-
DumpSSA bool
27-
VerifyIR bool
28-
PrintCommands bool
29-
Debug bool
30-
PrintSizes string
31-
PrintAllocs *regexp.Regexp // regexp string
32-
PrintStacks bool
33-
Tags string
34-
WasmAbi string
35-
GlobalValues map[string]map[string]string // map[pkgpath]map[varname]value
36-
TestConfig TestConfig
37-
Programmer string
20+
Target string
21+
Opt string
22+
GC string
23+
PanicStrategy string
24+
Scheduler string
25+
PrintIR bool
26+
DumpSSA bool
27+
VerifyIR bool
28+
PrintCommands bool
29+
Debug bool
30+
PrintSizes string
31+
PrintAllocs *regexp.Regexp // regexp string
32+
PrintStacks bool
33+
Tags string
34+
WasmAbi string
35+
GlobalValues map[string]map[string]string // map[pkgpath]map[varname]value
36+
TestConfig TestConfig
37+
Programmer string
38+
OpenOCDCommands []string
3839
}
3940

4041
// Verify performs a validation on the given options, raising an error if options are not valid.

main.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ func main() {
905905
printAllocsString := flag.String("print-allocs", "", "regular expression of functions for which heap allocations should be printed")
906906
printCommands := flag.Bool("x", false, "Print commands")
907907
nodebug := flag.Bool("no-debug", false, "disable DWARF debug symbol generation")
908+
ocdCommandsString := flag.String("ocd-commands", "", "OpenOCD commands, overriding target spec (can specify multiple separated by commas)")
908909
ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug")
909910
port := flag.String("port", "", "flash port (can specify multiple candidates separated by commas)")
910911
programmer := flag.String("programmer", "", "which hardware programmer to use")
@@ -943,6 +944,7 @@ func main() {
943944
fmt.Fprintln(os.Stderr, err)
944945
os.Exit(1)
945946
}
947+
946948
var printAllocs *regexp.Regexp
947949
if *printAllocsString != "" {
948950
printAllocs, err = regexp.Compile(*printAllocsString)
@@ -951,24 +953,31 @@ func main() {
951953
os.Exit(1)
952954
}
953955
}
956+
957+
var ocdCommands []string
958+
if *ocdCommandsString != "" {
959+
ocdCommands = strings.Split(*ocdCommandsString, ",")
960+
}
961+
954962
options := &compileopts.Options{
955-
Target: *target,
956-
Opt: *opt,
957-
GC: *gc,
958-
PanicStrategy: *panicStrategy,
959-
Scheduler: *scheduler,
960-
PrintIR: *printIR,
961-
DumpSSA: *dumpSSA,
962-
VerifyIR: *verifyIR,
963-
Debug: !*nodebug,
964-
PrintSizes: *printSize,
965-
PrintStacks: *printStacks,
966-
PrintAllocs: printAllocs,
967-
PrintCommands: *printCommands,
968-
Tags: *tags,
969-
GlobalValues: globalVarValues,
970-
WasmAbi: *wasmAbi,
971-
Programmer: *programmer,
963+
Target: *target,
964+
Opt: *opt,
965+
GC: *gc,
966+
PanicStrategy: *panicStrategy,
967+
Scheduler: *scheduler,
968+
PrintIR: *printIR,
969+
DumpSSA: *dumpSSA,
970+
VerifyIR: *verifyIR,
971+
Debug: !*nodebug,
972+
PrintSizes: *printSize,
973+
PrintStacks: *printStacks,
974+
PrintAllocs: printAllocs,
975+
PrintCommands: *printCommands,
976+
Tags: *tags,
977+
GlobalValues: globalVarValues,
978+
WasmAbi: *wasmAbi,
979+
Programmer: *programmer,
980+
OpenOCDCommands: ocdCommands,
972981
}
973982

974983
os.Setenv("CC", "clang -target="+*target)

0 commit comments

Comments
 (0)