asm := ats.compileToAsm(tt, dir)
for _, at := range ats.tests {
- funcName := nameRegexp.FindString(at.function)[5:]
- fa := funcAsm(asm, funcName)
- at.verifyAsm(tt, fa)
+ funcName := nameRegexp.FindString(at.function)[len("func "):]
+ fa := funcAsm(tt, asm, funcName)
+ if fa != "" {
+ at.verifyAsm(tt, fa)
+ }
}
})
}
})
}
+var nextTextRegexp = regexp.MustCompile(`\n\S`)
+
// funcAsm returns the assembly listing for the given function name.
-func funcAsm(asm string, funcName string) string {
+func funcAsm(t *testing.T, asm string, funcName string) string {
if i := strings.Index(asm, fmt.Sprintf("TEXT\t\"\".%s(SB)", funcName)); i >= 0 {
asm = asm[i:]
+ } else {
+ t.Errorf("could not find assembly for function %v", funcName)
+ return ""
}
- if i := strings.Index(asm[1:], "TEXT\t\"\"."); i >= 0 {
- asm = asm[:i+1]
+ // Find the next line that doesn't begin with whitespace.
+ loc := nextTextRegexp.FindStringIndex(asm)
+ if loc != nil {
+ asm = asm[:loc[0]]
}
return asm
// Now, compile the individual file for which we want to see the generated assembly.
asm := ats.runGo(t, "tool", "compile", "-I", testDir, "-S", "-o", filepath.Join(testDir, "out.o"), src)
-
- // Get rid of code for "".init. Also gets rid of type algorithms & other junk.
- if i := strings.Index(asm, "\n\"\".init "); i >= 0 {
- asm = asm[:i+1]
- }
-
return asm
}