feat(asm): the operand forms and defines GOROOT writes
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+10
-2
@@ -664,6 +664,7 @@ func runCorpusAudit(root string, dirs includeDirs) (*corpusStats, error) {
|
||||
f, errs := parser.ParseWithOptions(path, src, parser.Options{
|
||||
Expand: true,
|
||||
IncludeDirs: append(slices.Clone(dirs), hdrDir),
|
||||
Predefines: platformPredefinesFor(goarchName(tg.a), goos),
|
||||
})
|
||||
if len(errs) > 0 {
|
||||
ok = false
|
||||
@@ -683,12 +684,19 @@ func runCorpusAudit(root string, dirs includeDirs) (*corpusStats, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
f, errs := parser.ParseWithOptions(path, src, parser.Options{Expand: true, IncludeDirs: dirs})
|
||||
|
||||
ok := true
|
||||
for _, i := range wanted {
|
||||
tg, t := targets[i], tallies[i]
|
||||
t.attempted++
|
||||
// The parse carries the target's platform predefines, so it
|
||||
// cannot be shared across targets the way a header-free file's
|
||||
// could: a #ifdef GOARCH_arm block must be live on arm64 and
|
||||
// dead everywhere else.
|
||||
f, errs := parser.ParseWithOptions(path, src, parser.Options{
|
||||
Expand: true,
|
||||
IncludeDirs: dirs,
|
||||
Predefines: platformPredefinesFor(goarchName(tg.a), goos),
|
||||
})
|
||||
var err error
|
||||
if len(errs) > 0 {
|
||||
err = errs[0] // a parse failure is a failure for every target
|
||||
|
||||
+29
-6
@@ -574,7 +574,7 @@ naming the package.
|
||||
defer cleanup()
|
||||
dirs = append(dirs, hdrDir)
|
||||
}
|
||||
f, errs := parser.ParseWithOptions(path, src, parser.Options{Expand: true, IncludeDirs: dirs})
|
||||
f, errs := parser.ParseWithOptions(path, src, parser.Options{Expand: true, IncludeDirs: dirs, Predefines: platformPredefinesFor(string(targetArch), goos)})
|
||||
for _, e := range errs {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", path, e)
|
||||
}
|
||||
@@ -789,6 +789,29 @@ e.g. --map wideCopyAVX2=wideCopyAVX512 pairs the two regardless of suffix.
|
||||
return 1
|
||||
}
|
||||
|
||||
// platformPredefines mirrors the go command's assembler invocation, which
|
||||
// defines GOOS_<goos> and GOARCH_<arch> as -D macros: GOROOT headers
|
||||
// (go_tls.h, asm_riscv64.h) select their platform blocks with #ifdef on
|
||||
// exactly those names, so an assembler without them cannot see the platform
|
||||
// definitions at all.
|
||||
func platformPredefines(goarch, goos string) map[string]string {
|
||||
return map[string]string{
|
||||
"GOARCH_" + goarch: "1",
|
||||
"GOOS_" + goos: "1",
|
||||
}
|
||||
}
|
||||
|
||||
// platformPredefinesFor resolves the ambient GOOS the way a build would: a
|
||||
// file whose name carries one (sys_darwin_arm64.s) is compiled for that GOOS
|
||||
// and nothing else.
|
||||
func platformPredefinesFor(goarch string, fileGoos string) map[string]string {
|
||||
goos := fileGoos
|
||||
if goos == "" {
|
||||
goos = runtime.GOOS
|
||||
}
|
||||
return platformPredefines(goarch, goos)
|
||||
}
|
||||
|
||||
// assembleFile assembles a parsed file for the given architecture and returns the image.
|
||||
func assembleFile(targetArch arch.Arch, f *ast.File) (*asm.Image, error) {
|
||||
switch targetArch {
|
||||
@@ -813,17 +836,17 @@ func assemblePath(path string, forced arch.Arch, dirs includeDirs) (*asm.Image,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, errs := parser.ParseWithOptions(path, src, parser.Options{Expand: true, IncludeDirs: dirs})
|
||||
target := forced
|
||||
if target == arch.Unknown {
|
||||
target = arch.FromFilename(path)
|
||||
}
|
||||
f, errs := parser.ParseWithOptions(path, src, parser.Options{Expand: true, IncludeDirs: dirs, Predefines: platformPredefinesFor(string(target), "")})
|
||||
for _, e := range errs {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", path, e)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return nil, fmt.Errorf("parse errors")
|
||||
}
|
||||
target := forced
|
||||
if target == arch.Unknown {
|
||||
target = arch.FromFilename(path)
|
||||
}
|
||||
return assembleFile(target, f)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user