diff options
author | Giovanni Bajo <rasky@develer.com> | 2018-03-01 01:39:01 +0100 |
---|---|---|
committer | Giovanni Bajo <rasky@develer.com> | 2018-03-01 18:10:48 +0000 |
commit | 879a1ff1e494188a7aec8f094fac9bd71850d392 (patch) | |
tree | 6447af3d97b06356ce47a13761b9708af3c32c01 /test/run.go | |
parent | 9372e3f5ef6c9653d29cbba2dc06bdcad2b3724c (diff) | |
download | go-879a1ff1e494188a7aec8f094fac9bd71850d392.tar.gz go-879a1ff1e494188a7aec8f094fac9bd71850d392.zip |
test: improve asmcheck syntax
asmcheck comments now support a compact form of specifying
multiple checks for each platform, using the following syntax:
amd64:"SHL\t[$]4","SHR\t[$]4"
Negative checks are also parsed using the following syntax:
amd64:-"ROR"
though they are still not working.
Moreover, out-of-line comments have been implemented. This
allows to specify asmchecks on comment-only lines, that will
be matched on the first subsequent non-comment non-empty line.
// amd64:"XOR"
// arm:"EOR"
x ^= 1
Change-Id: I110c7462fc6a5c70fd4af0d42f516016ae7f2760
Reviewed-on: https://go-review.googlesource.com/97816
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/run.go')
-rw-r--r-- | test/run.go | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/test/run.go b/test/run.go index ae29ad2fa6..271a6f8014 100644 --- a/test/run.go +++ b/test/run.go @@ -1247,8 +1247,23 @@ func (t *test) wantedErrors(file, short string) (errs []wantedError) { return } +const ( + // Regexp to match a single opcode check: optionally begin with "-" (to indicate + // a negative check), followed by a string literal enclosed in "" or ``. For "", + // backslashes must be handled. + reMatchCheck = `-?(?:\x60[^\x60]*\x60|"(?:[^"\\]|\\.)*")` +) + var ( - rxAsmCheck = regexp.MustCompile(`//(?:\s+(\w+):((?:"(?:.+?)")|(?:` + "`" + `(?:.+?)` + "`" + `)))+`) + // Regexp to split a line in code and comment, trimming spaces + rxAsmComment = regexp.MustCompile(`^\s*(.*?)\s*(?:\/\/\s*(.+)\s*)?$`) + + // Regexp to extract an architecture check: architecture name, followed by semi-colon, + // followed by a comma-separated list of opcode checks. + rxAsmPlatform = regexp.MustCompile(`(\w+):(` + reMatchCheck + `(?:,` + reMatchCheck + `)*)`) + + // Regexp to extract a single opcoded check + rxAsmCheck = regexp.MustCompile(reMatchCheck) ) type wantedAsmOpcode struct { @@ -1262,33 +1277,52 @@ func (t *test) wantedAsmOpcodes(fn string) (map[string]map[string][]wantedAsmOpc ops := make(map[string]map[string][]wantedAsmOpcode) archs := make(map[string]bool) + comment := "" src, _ := ioutil.ReadFile(fn) for i, line := range strings.Split(string(src), "\n") { - matches := rxAsmCheck.FindStringSubmatch(line) - if len(matches) == 0 { + matches := rxAsmComment.FindStringSubmatch(line) + code, cmt := matches[1], matches[2] + + // Keep comments pending in the comment variable until + // we find a line that contains some code. + comment += " " + cmt + if code == "" { continue } + // Parse and extract any architecture check from comments, + // made by one architecture name and multiple checks. lnum := fn + ":" + strconv.Itoa(i+1) - for j := 1; j < len(matches); j += 2 { - rxsrc, err := strconv.Unquote(matches[j+1]) - if err != nil { - log.Fatalf("%s:%d: error unquoting string: %v", t.goFileName(), i+1, err) - } - oprx, err := regexp.Compile(rxsrc) - if err != nil { - log.Fatalf("%s:%d: %v", t.goFileName(), i+1, err) - } - arch := matches[j] - if ops[arch] == nil { - ops[arch] = make(map[string][]wantedAsmOpcode) + for _, ac := range rxAsmPlatform.FindAllStringSubmatch(comment, -1) { + arch, allchecks := ac[1], ac[2] + + for _, m := range rxAsmCheck.FindAllString(allchecks, -1) { + negative := false + if m[0] == '-' { + negative = true + m = m[1:] + } + + rxsrc, err := strconv.Unquote(m) + if err != nil { + log.Fatalf("%s:%d: error unquoting string: %v", t.goFileName(), i+1, err) + } + oprx, err := regexp.Compile(rxsrc) + if err != nil { + log.Fatalf("%s:%d: %v", t.goFileName(), i+1, err) + } + if ops[arch] == nil { + ops[arch] = make(map[string][]wantedAsmOpcode) + } + archs[arch] = true + ops[arch][lnum] = append(ops[arch][lnum], wantedAsmOpcode{ + negative: negative, + line: i + 1, + opcode: oprx, + }) } - archs[arch] = true - ops[arch][lnum] = append(ops[arch][lnum], wantedAsmOpcode{ - line: i + 1, - opcode: oprx, - }) } + comment = "" } var sarchs []string |