forked from chipsalliance/riscv-vector-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single.go
57 lines (47 loc) · 1.18 KB
/
single.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
package main
import (
"errors"
"flag"
"fmt"
"github.com/ksco/riscv-vector-tests/generator"
"os"
"path/filepath"
"regexp"
)
func fatalIf(err error) {
if err == nil {
return
}
fmt.Printf("fatal: %s\n", err.Error())
os.Exit(1)
}
var vlenF = flag.Int("VLEN", 256, "")
var xlenF = flag.Int("XLEN", 64, "")
var outputFileF = flag.String("outputfile", "", "output file name.")
var configFileF = flag.String("configfile", "", "config file path.")
func main() {
flag.Parse()
if outputFileF == nil || *outputFileF == "" {
fatalIf(errors.New("-outputfile is required"))
}
if configFileF == nil || *configFileF == "" {
fatalIf(errors.New("-configfile is required"))
}
option := generator.Option{
VLEN: generator.VLEN(*vlenF),
XLEN: generator.XLEN(*xlenF),
}
fp := *configFileF
contents, err := os.ReadFile(fp)
fatalIf(err)
insn, err := generator.ReadInsnFromToml(contents, option)
fatalIf(err)
r := regexp.MustCompile(".word 0x.+")
writeTo(*outputFileF, r.ReplaceAllString(insn.Generate(-1)[0], ""))
}
func writeTo(path string, contents string) {
err := os.MkdirAll(filepath.Dir(path), 0777)
fatalIf(err)
err = os.WriteFile(path, []byte(contents), 0644)
fatalIf(err)
}