1
0
mirror of https://github.com/golang/go synced 2024-11-20 08:54:40 -07:00

[dev.cc] cmd/asm: changes to get identical output as new6a

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>
This commit is contained in:
Rob Pike 2015-01-23 11:24:42 -08:00
parent 07a27ce09e
commit 89162307cd
5 changed files with 19 additions and 9 deletions

View 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())

View 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()))
}
}
}

View 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
}

View 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
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':
if t.file != nil {
histLine++
}
t.line++
case '-':
if s.Peek() == '>' {

View 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)