var conv typeConv
conv.Init(p.PtrSize, p.IntSize)
- p.loadDefines(f)
p.typedefs = map[string]bool{}
p.typedefList = nil
numTypedefs := -1
// loadDefines coerces gcc into spitting out the #defines in use
// in the file f and saves relevant renamings in f.Name[name].Define.
-func (p *Package) loadDefines(f *File) {
+// Returns true if env:CC is Clang
+func (f *File) loadDefines(gccOptions []string) bool {
var b bytes.Buffer
b.WriteString(builtinProlog)
b.WriteString(f.Preamble)
- stdout := p.gccDefines(b.Bytes())
+ stdout := gccDefines(b.Bytes(), gccOptions)
+ var gccIsClang bool
for _, line := range strings.Split(stdout, "\n") {
if len(line) < 9 || line[0:7] != "#define" {
continue
}
if key == "__clang__" {
- p.GccIsClang = true
+ gccIsClang = true
}
if n := f.Name[key]; n != nil {
n.Define = val
}
}
+ return gccIsClang
}
// guessKinds tricks gcc into revealing the kind of each
}
// gccMachine returns the gcc -m flag to use, either "-m32", "-m64" or "-marm".
-func (p *Package) gccMachine() []string {
+func gccMachine() []string {
switch goarch {
case "amd64":
if goos == "darwin" {
}
c = append(c, p.GccOptions...)
- c = append(c, p.gccMachine()...)
+ c = append(c, gccMachine()...)
if goos == "aix" {
c = append(c, "-maix64")
c = append(c, "-mcmodel=large")
// and returns the corresponding standard output, which is the
// #defines that gcc encountered while processing the input
// and its included files.
-func (p *Package) gccDefines(stdin []byte) string {
+func gccDefines(stdin []byte, gccOptions []string) string {
base := append(gccBaseCmd, "-E", "-dM", "-xc")
- base = append(base, p.gccMachine()...)
- stdout, _ := runGcc(stdin, append(append(base, p.GccOptions...), "-"))
+ base = append(base, gccMachine()...)
+ stdout, _ := runGcc(stdin, append(append(base, gccOptions...), "-"))
return stdout
}
"runtime"
"sort"
"strings"
+ "sync"
"cmd/internal/edit"
"cmd/internal/notsha256"
// Use the beginning of the notsha256 of the input to disambiguate.
h := notsha256.New()
io.WriteString(h, *importPath)
+ var once sync.Once
+ var wg sync.WaitGroup
fs := make([]*File, len(goFiles))
for i, input := range goFiles {
if *srcDir != "" {
fatalf("%s", err)
}
- // Apply trimpath to the file path. The path won't be read from after this point.
- input, _ = objabi.ApplyRewrites(input, *trimpath)
- if strings.ContainsAny(input, "\r\n") {
- // ParseGo, (*Package).writeOutput, and printer.Fprint in SourcePos mode
- // all emit line directives, which don't permit newlines in the file path.
- // Bail early if we see anything newline-like in the trimmed path.
- fatalf("input path contains newline character: %q", input)
- }
- goFiles[i] = input
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ // Apply trimpath to the file path. The path won't be read from after this point.
+ input, _ = objabi.ApplyRewrites(input, *trimpath)
+ if strings.ContainsAny(input, "\r\n") {
+ // ParseGo, (*Package).writeOutput, and printer.Fprint in SourcePos mode
+ // all emit line directives, which don't permit newlines in the file path.
+ // Bail early if we see anything newline-like in the trimmed path.
+ fatalf("input path contains newline character: %q", input)
+ }
+ goFiles[i] = input
- f := new(File)
- f.Edit = edit.NewBuffer(b)
- f.ParseGo(input, b)
- f.ProcessCgoDirectives()
- fs[i] = f
+ f := new(File)
+ f.Edit = edit.NewBuffer(b)
+ f.ParseGo(input, b)
+ f.ProcessCgoDirectives()
+ gccIsClang := f.loadDefines(p.GccOptions)
+ once.Do(func() {
+ p.GccIsClang = gccIsClang
+ })
+
+ fs[i] = f
+ }()
}
+ wg.Wait()
+
cPrefix = fmt.Sprintf("_%x", h.Sum(nil)[0:6])
if *objDir == "" {