1
0
mirror of https://github.com/golang/go synced 2024-10-05 16:31:21 -06:00
Commit Graph

115 Commits

Author SHA1 Message Date
Rob Pike
eeebcd9db3 [dev.cc] asm: fix handling of statics (data<>) and symbols
A typo limited the number of center-dot substitutions to one. Fixed.

With these changes, plus a recent fix to 6a, the are no differences,
down to the bit level, in object code for any assembly files in std
between asm and 6a. (Runtime has not been checked yet, but I
expect no errors.)

Change-Id: I0e8045b4414223d937e7f8919c8768860554b7d5
Reviewed-on: https://go-review.googlesource.com/3820
Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-03 20:43:37 +00:00
Rob Pike
68475da68d [dev.cc] cmd/asm: fix a few minor issues
Fix one place where semicolons were not recognized and fix the
pattern match for the syntax of some pseudo ops.
Also clean up a couple of unreachable code pieces.

There is still an undiagnosed bit difference betwen old and new .6
files. TBD.

With these fixes, asm can successfully compile and test the entire tree.
(Verified by
	turn off verifyAsm in cmd/go
	make.bash
	cp $GOROOT/bin/asm $GOROOT/pkg/tool/darwin_amd64/6a
	go test -short std
)

Change-Id: I91ea892098f76ef4f129fd2530e0c63ffd8745a9
Reviewed-on: https://go-review.googlesource.com/3688
Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-02 20:04:45 +00:00
Rob Pike
5beec6a699 [dev.cc] cmd/asm: handle the case where a macro is named without arguments
Given
	#define X() foo
	X()
	X
cpp produces
	foo
	X
Asm does now as well.

Change-Id: Ia36b88a23ce1660e6a02559c4f730593d62066f1
Reviewed-on: https://go-review.googlesource.com/3611
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-30 21:19:49 +00:00
Rob Pike
d6eb21e331 [dev.cc] cmd/asm: rewrite the macro processor
The previous one was too broken, so just rewrite the code that invokes
a macro. Basically it was evaluating things too early, and mishandling
nested invocations. It's also easier to understand now.

Keep backslash-newline around in macro definitions. They get
processed when the body is evaluated.

Write some golden tests.

Change-Id: I27435f77f258a0873f80932bdc8d13ad39821ac1
Reviewed-on: https://go-review.googlesource.com/3550
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-30 16:38:25 +00:00
Rob Pike
b528063099 [dev.cc] cmd/asm: delete overflow checking, make labels function-scoped
The overflow checking was causing more problems than it was avoiding,
so get rid of it. But because arithmetic is done with uint64s, to simplify
dealing with large constants, complain about right shift and divide with
huge numbers to avoid ambiguity about signed shifts.

Change-Id: I5b5ea55d8e8c02846605f4a3f8fd7a176b1e962b
Reviewed-on: https://go-review.googlesource.com/3531
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-29 20:26:26 +00:00
Rob Pike
36e5f4d53f [dev.cc] cmd/asm: set the flags to production settings (turn off debug)
Set -S to false and add -debug to control the other debugging print.

Change-Id: I864866c3d264a33e6dd0ce12a86a050a5fe0f875
Reviewed-on: https://go-review.googlesource.com/3453
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-29 19:08:26 +00:00
Rob Pike
29428e322d [dev.cc] cmd/asm: check for overflow on multiply and left shift
The internal size of integers is not part of the definition of the assembler,
so if bits roll out the top it's a portability problem at best.

If you need to use shift to create a mask, use & to restrict the bit count
before shifting. That will make it portable, too.

Change-Id: I24f9a4d2152c3f9f253e22ff75270fe50c18612b
Reviewed-on: https://go-review.googlesource.com/3451
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-28 22:26:41 +00:00
Rob Pike
0012b83507 [dev.cc] cmd/asm: fix the expression parser and add tests
Rewrite the grammar to have one more production so it parses
	~0*0
correctly and write tests to prove it.

Change-Id: I0dd652baf65b48a3f26c9287c420702db4eaec59
Reviewed-on: https://go-review.googlesource.com/3443
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-28 20:39:39 +00:00
Rob Pike
ad82238653 [dev.cc] cmd/asm: the text flag argument to TEXT psudo-op is optional
Allow TEXT to have two or three operands.
In
	TEXT foo(SB),flag,$0
the flag can be missing, in which case we take it to be zero.

Change-Id: I7b88543b52019f7890baac4b95f9e63884d43c83
Reviewed-on: https://go-review.googlesource.com/3440
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-28 20:34:40 +00:00
Rob Pike
92e5120c77 [dev.cc] cmd/asm: rewrite parsing of TEXT $3-2
It was too complicated, assuming the syntax is more general than reality.
It must be a possibly negative integer followed by an optional minus sign
and positive integer. Literals only, no expresssions.

Also put in a TODO about address parsing and clean up a couple of types.

Change-Id: If8652249c742e42771ccf2e3024f77307b2e5d9a
Reviewed-on: https://go-review.googlesource.com/3370
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-28 18:17:13 +00:00
Rob Pike
89162307cd [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>
2015-01-24 03:28:26 +00:00
Rob Pike
fdeee3a538 [dev.cc] cmd/asm: the assembler proper
Add main.go, the simple driver for the assembler, and the
subdirectory internal/asm, which contains the parser and
instruction generator.

It's likely that much of the implementation is superstition,
or at best experimental phenomenology, but it does generate
working binaries.

Change-Id: I322a9ae8a20174b6693153f30e39217ba68f8032
Reviewed-on: https://go-review.googlesource.com/3196
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-23 04:54:05 +00:00
Rob Pike
8642639575 [dev.cc] cmd/asm: add lex internal package
Add the lexing code for the new portable assembler.
It is internal to the assembler, so lives in a subdirectory of cmd/asm/internal.

Its only new dependency is the flags package for the assembler, so
add that too; it's trivial. That package manages the command-line
flags in a central place.

The lexer builds on text/scanner to lex the input, including doing a
Plan 9-level implementation of the C preprocessor.

Change-Id: I262e8717b8c797010afaa5051920839906c0dd19
Reviewed-on: https://go-review.googlesource.com/3195
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-23 04:24:57 +00:00
Rob Pike
40eb0ed0d8 [dev.cc] cmd/asm: add addr package
This simple package holds the definition of the Addr (address) type
that represents addresses inside the assembler.

It has no dependencies.

Change-Id: I7573fd70f1847ef68e3d6b663dc4c39eb2ebf8b3
Reviewed-on: https://go-review.googlesource.com/3193
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-23 03:30:37 +00:00
Rob Pike
6017f68029 [dev.cc] cmd/asm: add arch package
This package builds the representation of the machine architecture
for the new assembler.

Almost nothing in it is likely to last but this will get things running.

Change-Id: I8edd891f927a81f76d2dbdcd7484b9c87ac0fb2e
Reviewed-on: https://go-review.googlesource.com/3194
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-23 03:18:55 +00:00