mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/asm: fix EOF message on operand parsing errors.
If the parsing of an operand completes but the parser thinks there is more to read, return an "expected end of operand" error message instead of "expected EOF." This also removes extra "asm: " prefixes in error strings since "asm: " is already set as the global log prefix. Fixes #14071 Change-Id: I7d621c1aea529a0eca3bcba032359bd25b3e1080 Reviewed-on: https://go-review.googlesource.com/19731 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
d17727bdb4
commit
45c4ebec5b
5 changed files with 21 additions and 16 deletions
|
|
@ -297,7 +297,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
|
|||
p.errorf("illegal use of register list")
|
||||
}
|
||||
p.registerList(a)
|
||||
p.expect(scanner.EOF)
|
||||
p.expectOperandEnd()
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -331,7 +331,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
|
|||
}
|
||||
}
|
||||
// fmt.Printf("REG %s\n", obj.Dconv(&emptyProg, 0, a))
|
||||
p.expect(scanner.EOF)
|
||||
p.expectOperandEnd()
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -363,7 +363,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
|
|||
a.Type = obj.TYPE_FCONST
|
||||
a.Val = p.floatExpr()
|
||||
// fmt.Printf("FCONST %s\n", obj.Dconv(&emptyProg, 0, a))
|
||||
p.expect(scanner.EOF)
|
||||
p.expectOperandEnd()
|
||||
return true
|
||||
}
|
||||
if p.have(scanner.String) {
|
||||
|
|
@ -378,7 +378,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
|
|||
a.Type = obj.TYPE_SCONST
|
||||
a.Val = str
|
||||
// fmt.Printf("SCONST %s\n", obj.Dconv(&emptyProg, 0, a))
|
||||
p.expect(scanner.EOF)
|
||||
p.expectOperandEnd()
|
||||
return true
|
||||
}
|
||||
a.Offset = int64(p.expr())
|
||||
|
|
@ -392,7 +392,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
|
|||
a.Type = obj.TYPE_MEM
|
||||
}
|
||||
// fmt.Printf("CONST %d %s\n", a.Offset, obj.Dconv(&emptyProg, 0, a))
|
||||
p.expect(scanner.EOF)
|
||||
p.expectOperandEnd()
|
||||
return true
|
||||
}
|
||||
// fmt.Printf("offset %d \n", a.Offset)
|
||||
|
|
@ -402,7 +402,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
|
|||
p.registerIndirect(a, prefix)
|
||||
// fmt.Printf("DONE %s\n", p.arch.Dconv(&emptyProg, 0, a))
|
||||
|
||||
p.expect(scanner.EOF)
|
||||
p.expectOperandEnd()
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -983,14 +983,19 @@ func (p *Parser) more() bool {
|
|||
|
||||
// get verifies that the next item has the expected type and returns it.
|
||||
func (p *Parser) get(expected lex.ScanToken) lex.Token {
|
||||
p.expect(expected)
|
||||
p.expect(expected, expected.String())
|
||||
return p.next()
|
||||
}
|
||||
|
||||
// expectOperandEnd verifies that the parsing state is properly at the end of an operand.
|
||||
func (p *Parser) expectOperandEnd() {
|
||||
p.expect(scanner.EOF, "end of operand")
|
||||
}
|
||||
|
||||
// expect verifies that the next item has the expected type. It does not consume it.
|
||||
func (p *Parser) expect(expected lex.ScanToken) {
|
||||
if p.peek() != expected {
|
||||
p.errorf("expected %s, found %s", expected, p.next())
|
||||
func (p *Parser) expect(expectedToken lex.ScanToken, expectedMessage string) {
|
||||
if p.peek() != expectedToken {
|
||||
p.errorf("expected %s, found %s", expectedMessage, p.next())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func TestErroneous(t *testing.T) {
|
|||
{"TEXT", "%", "expect two or three operands for TEXT"},
|
||||
{"TEXT", "1, 1", "TEXT symbol \"<erroneous symbol>\" must be a symbol(SB)"},
|
||||
{"TEXT", "$\"foo\", 0, $1", "TEXT symbol \"<erroneous symbol>\" must be a symbol(SB)"},
|
||||
{"TEXT", "$0É:0, 0, $1", "expected EOF, found É"}, // Issue #12467.
|
||||
{"TEXT", "$0É:0, 0, $1", "expected end of operand, found É"}, // Issue #12467.
|
||||
{"TEXT", "$:0:(SB, 0, $1", "expected '(', found 0"}, // Issue 12468.
|
||||
{"FUNCDATA", "", "expect two operands for FUNCDATA"},
|
||||
{"FUNCDATA", "(SB ", "expect two operands for FUNCDATA"},
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ type Input struct {
|
|||
peekText string
|
||||
}
|
||||
|
||||
// NewInput returns a
|
||||
// NewInput returns an Input from the given path.
|
||||
func NewInput(name string) *Input {
|
||||
return &Input{
|
||||
// include directories: look in source dir, then -I directories.
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func NewLexer(name string, ctxt *obj.Link) TokenReader {
|
|||
input := NewInput(name)
|
||||
fd, err := os.Open(name)
|
||||
if err != nil {
|
||||
log.Fatalf("asm: %s\n", err)
|
||||
log.Fatalf("%s\n", err)
|
||||
}
|
||||
input.Push(NewTokenizer(name, fd, fd))
|
||||
return input
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func main() {
|
|||
|
||||
architecture := arch.Set(GOARCH)
|
||||
if architecture == nil {
|
||||
log.Fatalf("asm: unrecognized architecture %s", GOARCH)
|
||||
log.Fatalf("unrecognized architecture %s", GOARCH)
|
||||
}
|
||||
|
||||
flags.Parse()
|
||||
|
|
@ -66,7 +66,7 @@ func main() {
|
|||
obj.Writeobjdirect(ctxt, output)
|
||||
}
|
||||
if !ok || diag {
|
||||
log.Printf("asm: assembly of %s failed", flag.Arg(0))
|
||||
log.Printf("assembly of %s failed", flag.Arg(0))
|
||||
os.Remove(*flags.OutputFile)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue