aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-11-28 17:25:17 +0100
committerRon Evans <[email protected]>2019-12-07 16:04:47 +0100
commit06647aab24ace357c70a0b2d374fd2bad4c828f7 (patch)
treef536529c78bdf055533f0464cea348332664f071 /tools
parent24259cbb5f7b59090bb51d469f18a5171299db82 (diff)
downloadtinygo-06647aab24ace357c70a0b2d374fd2bad4c828f7.tar.gz
tinygo-06647aab24ace357c70a0b2d374fd2bad4c828f7.zip
tools/gen-device-avr: process files in parallel
This significantly speeds up processing of the files.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-device-avr/gen-device-avr.go72
1 files changed, 55 insertions, 17 deletions
diff --git a/tools/gen-device-avr/gen-device-avr.go b/tools/gen-device-avr/gen-device-avr.go
index d49162c9d..ac4c8b996 100755
--- a/tools/gen-device-avr/gen-device-avr.go
+++ b/tools/gen-device-avr/gen-device-avr.go
@@ -8,8 +8,10 @@ import (
"math/bits"
"os"
"path/filepath"
+ "runtime"
"strconv"
"strings"
+ "sync"
)
type AVRToolsDeviceFile struct {
@@ -426,31 +428,67 @@ __num_isrs = {{.numInterrupts}};
return t.Execute(out, device.metadata)
}
+func processFile(filepath, outdir string) error {
+ device, err := readATDF(filepath)
+ if err != nil {
+ return err
+ }
+ err = writeGo(outdir, device)
+ if err != nil {
+ return err
+ }
+ err = writeAsm(outdir, device)
+ if err != nil {
+ return err
+ }
+ return writeLD(outdir, device)
+}
+
func generate(indir, outdir string) error {
+ // Read list of ATDF files to process.
matches, err := filepath.Glob(indir + "/*.atdf")
if err != nil {
return err
}
+
+ // Start worker goroutines.
+ var wg sync.WaitGroup
+ workChan := make(chan string)
+ errChan := make(chan error, 1)
+ for i := 0; i < runtime.NumCPU(); i++ {
+ go func() {
+ for filepath := range workChan {
+ err := processFile(filepath, outdir)
+ wg.Done()
+ if err != nil {
+ // Store error to errChan if no error was stored before.
+ select {
+ case errChan <- err:
+ default:
+ }
+ }
+ }
+ }()
+ }
+
+ // Submit all jobs to the goroutines.
+ wg.Add(len(matches))
for _, filepath := range matches {
fmt.Println(filepath)
- device, err := readATDF(filepath)
- if err != nil {
- return err
- }
- err = writeGo(outdir, device)
- if err != nil {
- return err
- }
- err = writeAsm(outdir, device)
- if err != nil {
- return err
- }
- err = writeLD(outdir, device)
- if err != nil {
- return err
- }
+ workChan <- filepath
+ }
+ close(workChan)
+
+ // Wait until all workers have finished.
+ wg.Wait()
+
+ // Check for an error.
+ select {
+ case err := <-errChan:
+ return err
+ default:
+ return nil
}
- return nil
}
func main() {