]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] cmd/asm: changes to get identical output as new6a
authorRob Pike <r@golang.org>
Fri, 23 Jan 2015 19:24:42 +0000 (11:24 -0800)
committerRob Pike <r@golang.org>
Sat, 24 Jan 2015 03:28:26 +0000 (03:28 +0000)
Fix up a couple of minor things pointed out in the last review.
Also:

1. If the symbol starts with center dot, prefix the name with "".
2. If there is no locals size specified, use ArgsSizeUnknown (sic).
3. Do not emit a history point at the start of a macro invocation,
since we do not pop it at the end, behavior consistent with the
old code.

With these changes, old and new assemblers produce identical
output at least for my simple test case, so that provides a verifiable
check for future cleanups.

Change-Id: Iaa91d8e453109824b4be44321ec5e828f39f0299
Reviewed-on: https://go-review.googlesource.com/3242
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/asm/internal/asm/asm.go
src/cmd/asm/internal/lex/input.go
src/cmd/asm/internal/lex/lex.go
src/cmd/asm/internal/lex/tokenizer.go
src/cmd/asm/main.go

index 4ffbe558c6011bc92d984bacd249f1939cf4443b..29166ccf02aacf131e0c7aa10530bca17370b7ba 100644 (file)
@@ -144,7 +144,7 @@ func (p *Parser) asmText(word string, operands [][]lex.Token) {
        if !nameAddr.Is(addr.Symbol|addr.Register|addr.Indirect) || nameAddr.Register != arch.RSB {
                p.errorf("TEXT symbol %q must be an offset from SB", nameAddr.Symbol)
        }
-       name := strings.Replace(nameAddr.Symbol, "·", ".", 1)
+       name := nameAddr.Symbol
 
        // Operand 1 is the text flag, a literal integer.
        flagAddr := p.address(operands[1])
@@ -160,7 +160,7 @@ func (p *Parser) asmText(word string, operands [][]lex.Token) {
        // Not clear we can do better, but it doesn't matter.
        op := operands[2]
        n := len(op)
-       var locals int64
+       locals := int64(obj.ArgsSizeUnknown)
        if n >= 2 && op[n-2].ScanToken == '-' && op[n-1].ScanToken == scanner.Int {
                p.start(op[n-1:])
                locals = int64(p.expr())
index ae3199823917a83fdef3502d8199e8f1c5060e26..eefd6eb6efe9ad83ab2db324c38eb319c250d770 100644 (file)
@@ -234,7 +234,7 @@ func (in *Input) macroDefinition(name string) ([]string, []Token) {
                                continue
                        }
                }
-               tokens = append(tokens, Token{ScanToken(tok), in.Text()})
+               tokens = append(tokens, Make(tok, in.Text()))
                tok = in.Stack.Next()
        }
        return args, tokens
@@ -305,7 +305,7 @@ func (in *Input) argsFor(macro *Macro) map[string][]Token {
                                return args
                        }
                default:
-                       tokens = append(tokens, Token{tok, in.Stack.Text()})
+                       tokens = append(tokens, Make(tok, in.Stack.Text()))
                }
        }
 }
index 2153591e31ab4dea9ff324471043e50bd41b95da..4785350b1f51f47388832287f83991c47d9de68c 100644 (file)
@@ -107,6 +107,13 @@ type Token struct {
 
 // Make returns a Token with the given rune (ScanToken) and text representation.
 func Make(token ScanToken, text string) Token {
+       // If the symbol starts with center dot, as in ·x, rewrite it as ""·x
+       if token == scanner.Ident && strings.HasPrefix(text, "\u00B7") {
+               text = `""` + text
+       }
+       // Substitute the substitutes for . and /.
+       text = strings.Replace(text, "\u00B7", ".", 1)
+       text = strings.Replace(text, "\u2215", "/", -1)
        return Token{ScanToken: token, text: text}
 }
 
@@ -130,7 +137,7 @@ func tokenize(str string) []Token {
                if tok == scanner.EOF {
                        break
                }
-               tokens = append(tokens, Token{ScanToken: tok, text: t.Text()})
+               tokens = append(tokens, Make(tok, t.Text()))
        }
        return tokens
 }
index 6a6fdbc776678d80dca8a27d962d8b7236944053..24a72479db54eec985cfbf4b5aafa56f828367b1 100644 (file)
@@ -39,7 +39,9 @@ func NewTokenizer(name string, r io.Reader, file *os.File) *Tokenizer {
                scanner.ScanComments
        s.Position.Filename = name
        s.IsIdentRune = isIdentRune
-       obj.Linklinehist(linkCtxt, histLine, name, 0)
+       if file != nil {
+               obj.Linklinehist(linkCtxt, histLine, name, 0)
+       }
        return &Tokenizer{
                s:        &s,
                line:     1,
@@ -107,7 +109,9 @@ func (t *Tokenizer) Next() ScanToken {
        }
        switch t.tok {
        case '\n':
-               histLine++
+               if t.file != nil {
+                       histLine++
+               }
                t.line++
        case '-':
                if s.Peek() == '>' {
index 08354119a683cfec6808ed1cc7121427e5eea027..3c02d4eebd5e110126c2c44f90cb34c0a5e25123 100644 (file)
@@ -30,8 +30,7 @@ func main() {
                log.Fatalf("asm: unrecognized architecture %s", GOARCH)
        }
 
-       // Is this right?
-       flags.Parse(build.Default.GOROOT, build.Default.GOOS, GOARCH, architecture.Thechar)
+       flags.Parse(obj.Getgoroot(), obj.Getgoos(), obj.Getgoarch(), architecture.Thechar)
 
        // Create object file, write header.
        fd, err := os.Create(*flags.OutputFile)