]> Cypherpunks repositories - gostls13.git/commitdiff
test: improve asmcheck syntax
authorGiovanni Bajo <rasky@develer.com>
Thu, 1 Mar 2018 00:39:01 +0000 (01:39 +0100)
committerGiovanni Bajo <rasky@develer.com>
Thu, 1 Mar 2018 18:10:48 +0000 (18:10 +0000)
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>
test/codegen/rotate.go
test/run.go

index f305a9cfc0e877e13e793cf0be6f4ed9cca7ff12..f2b587d20224190f9c190568b5ba58c0779aaff6 100644 (file)
@@ -21,5 +21,7 @@ func rot64(x uint64) uint64 {
 }
 
 func copysign(a, b float64) float64 {
+       // amd64:"SHLQ\t[$]1","SHRQ\t[$]1","SHRQ\t[$]63","SHLQ\t[$]63","ORQ"
+       // ppc64le:"FCPSGN" s390x:"CPSDR",-"MOVD"
        return math.Copysign(a, b)
 }
index ae29ad2fa6c2cb4da666e11a6ddb22ef32013c2b..271a6f8014836e71665102adf8e4a7be58a90294 100644 (file)
@@ -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