为什么Go源包含许多.go文件?他们如何编译?

时间:2017-12-09 23:44:02

标签: gcc go compilation compiler-construction cross-compiling

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

https://github.com/golang/go 此来源包含88%.go个文件。

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

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

Golang使用什么编译器来生成最终的Generate Execute文件?!他们来源的地方?

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

新更新

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

88%的github.com/golang/go来源是.go文件。什么编译Go Source的.go文件?我想看看Final GO Compiler?

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"

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

make gc为什么需要Go?!

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

1 个答案:

答案 0 :(得分:4)

根据https://golang.org/doc/go1.5#implementationhttps://www.infoq.com/news/2015/01/golang-15-bootstrapped,Go最初是在C中实现的,但在1.5版本中自行托管。 Bootstrapping是用自己编译编译器的过程。 Go开发人员写了一个C - >转至转换器将原始的C编译器转换为Go,然后他们手动编辑Go代码,使其成为惯用语。