]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: report more than one instruction encoding error
authorRuss Cox <rsc@golang.org>
Fri, 22 Jan 2016 03:48:29 +0000 (22:48 -0500)
committerRuss Cox <rsc@golang.org>
Sun, 24 Jan 2016 05:00:28 +0000 (05:00 +0000)
Also, remove output file if there are encoding errors.
The extra reports are convenient.
Removing the output file is very important.
Noticed while testing.

Change-Id: I0fab17d4078f93c5a0d6d1217d8d9a63ac789696
Reviewed-on: https://go-review.googlesource.com/18845
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/asm/main.go
src/cmd/internal/obj/x86/asm6.go

index db0e28e2e59862b00e186aa69a4c6428982ceb68..528481c13299c084a2522d8f3a1fe2a6c6bf183b 100644 (file)
@@ -47,21 +47,28 @@ func main() {
        }
        ctxt.Bso = obj.Binitw(os.Stdout)
        defer ctxt.Bso.Flush()
-       ctxt.Diag = log.Fatalf
        output := obj.Binitw(fd)
        fmt.Fprintf(output, "go object %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion())
        fmt.Fprintf(output, "!\n")
 
        lexer := lex.NewLexer(flag.Arg(0), ctxt)
        parser := asm.NewParser(ctxt, architecture, lexer)
+       diag := false
+       ctxt.Diag = func(format string, args ...interface{}) {
+               diag = true
+               log.Printf(format, args...)
+       }
        pList := obj.Linknewplist(ctxt)
        var ok bool
        pList.Firstpc, ok = parser.Parse()
-       if !ok {
+       if ok {
+               // reports errors to parser.Errorf
+               obj.Writeobjdirect(ctxt, output)
+       }
+       if !ok || diag {
                log.Printf("asm: assembly of %s failed", flag.Arg(0))
                os.Remove(*flags.OutputFile)
                os.Exit(1)
        }
-       obj.Writeobjdirect(ctxt, output)
        output.Flush()
 }
index 164dbd60647af7228732d2a8dab9af302e9900d4..d5d52bb0556d47ae1fb458a6b51c81c2d18949bf 100644 (file)
@@ -4274,7 +4274,8 @@ bad:
                }
        }
 
-       ctxt.Diag("doasm: notfound ft=%d tt=%d %v %d %d", p.Ft, p.Tt, p, oclass(ctxt, p, &p.From), oclass(ctxt, p, &p.To))
+       ctxt.Diag("invalid instruction: %v", p)
+       //      ctxt.Diag("doasm: notfound ft=%d tt=%d %v %d %d", p.Ft, p.Tt, p, oclass(ctxt, p, &p.From), oclass(ctxt, p, &p.To))
        return
 }