【问题标题】:Why does Go source contain many .go files? How do they get compiled?为什么 Go 源码包含很多 .go 文件?它们是如何编译的?
【发布时间】:2017-12-09 23:44:01
【问题描述】:

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

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

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

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

Golang 使用什么编译器来生成最终的执行文件?!他们从哪里获得?

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

新更新

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

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

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

我认为这称为cg


mean 一个旧版本的 Go 编译器(1.4 版)用于编译新版本的 Go 编译器。???!

go-go1.4.3/src/go/token/token.go 这是 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$ 制作

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编译器?

【问题讨论】:

  • 麻烦你了,所以 go 是一个自托管编译器,那么在github.com/golang/go 执行和运行.go 文件呢?
  • 另请注意,github.com/golang/go 中的大部分内容是标准库,而不是编译器。
  • 哇,哪里有可用的编译器源? @阿德里安
  • 同一个仓库。它是编译器、工具、标准库、测试和文档,应有尽有。

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


【解决方案1】:

根据 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 代码以使其具有惯用性。

【讨论】:

  • 麻烦你了,如果 go 是自托管编译器,那么使用 ASM 执行和解析 .go 文件?
  • 用Go写的Go编译器是用来自己编译的,但是原来的Go编译器是用C写的,用C编译器编译的。
  • 我对 Go 编译器有点困惑,因为我从第一个版本的分支中看到了 Go 代码......不过,你应该看看 github.com/golang/go ,并阅读 @ 987654324@! .
  • golang.org/doc/…,怎么能看到go的gc原编译器?是开源的吗?
  • @Nahad 查看这个文件它是编译器入口点github.com/golang/go/blob/release-branch.go1.4/src/cmd/gc/… gc 目录是编译器体系结构独立部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
  • 2021-07-20
  • 1970-01-01
  • 2020-04-29
相关资源
最近更新 更多