为什么 Go 源代码包含许多 .go 文件?它们是如何编译的?

0 compiler-construction gcc compilation cross-compiling go

我想知道编译器是如何工作的!

https://github.com/golang/go 这个源码包含 88% 的.go文件。

所以这应该有另一个编译器来执行.go文件。

示例:https : //github.com/golang/go/blob/964639cc338db650ccadeafb7424bc8ebb2c0f6c/src/go/ast/ast.go

Golang 使用什么编译器生成最终的执行文件?!以及它们的来源?

可能是 Golang 生成 ac 代码,然后使用 GCC 或 ...?

新更新

我不想 go1.4 然后在使用 c。

github.com/golang/go 88% 的来源是.go文件。.goGo Source 的编译文件是什么?我想看看最终的 GO 编译器?

https://github.com/golang/go/search?l=c

我认为这称为cg.


意思是旧版本的 Go 编译器(1.4 版)用于编译新版本的 Go 编译器。???!

go-go1.4.3/src/go/token/token.go 这是去令牌,词法分析器,是在 GO 上写的

FUNC: "func", GO: "go", GOTO: "goto", IF: "if", IMPORT: "import",

那么执行.go文件的主编译器在哪里?

go-go1.4.3/src/runtime/compiler.go

// Copyright 2012 The Go Authors.  All rights reserved.
package runtime
// Compiler is the name of the compiler toolchain that built the
// running binary.  Known toolchains are:
//
//  gc      The 5g/6g/8g compiler suite at code.google.com/p/go.
//  gccgo   The gccgo front end, part of the GCC compiler suite.
//
const Compiler = "gc"
Run Code Online (Sandbox Code Playgroud)

go-go1.4.3/src/cmd/gc$ make

go tool dist install -v
make: go: Command not found
../../Make.dist:13: recipe for target 'install' failed
make: *** [install] Error 127
Run Code Online (Sandbox Code Playgroud)

make gc 为什么需要 Go?!


GO语言的最新版本如何工作?!这意味着如何为跨平台生成输出?这个使用生成代码到C然后使用c编译器?

Typ*_*ats 7

根据https://golang.org/doc/go1.5#implementationhttps://www.infoq.com/news/2015/01/golang-15-bootstrapped,Go 最初是用 C 实现的,但后来变成了自我托管在 1.5 版。引导是用自身编译编译器的过程。Go 开发人员编写了一个 C -> Go 转译器将原始的 C 编译器转换为 Go,然后他们手工编辑 Go 代码以使其符合习惯。