You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/advent-2019/go-compilers.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title = "Tour of Go Compilers"
6
6
linktitle = "Tour of Go Compilers"
7
7
+++
8
8
9
-
On a high level, compilers are viewed as a single a single, solid, single-step-worker entity. A Gopher, aka Go programmer, interacts with the Go compiler via the abstractions of `go build` or `go install` commands. However, compilers, in their ideal form, consist of three layers creatively named: frontend, middle-end, and backend. The single `go {build,install}` command embarks on journey through the three layers to convert the raw Go source code into machine code.
9
+
On a high level, compilers are viewed as a single, solid, single-step-worker entity. A Gopher, aka Go programmer, interacts with the Go compiler via the abstractions of `go build` or `go install` commands. However, compilers, in their ideal form, consist of three layers creatively named: frontend, middle-end, and backend. The single `go {build,install}` command embarks on a journey through the three layers to convert the raw Go source code into machine code.
10
10
11
11
The frontend ingests the source code, perform lexical, syntactical, and semantical analyses to verify all the language level constraints are met and sensical. The frontend then generates what is known as intermediate representation (IR) to handout to the middle-end. The middle-end does not know the syntax of the language nor does it know the machine language. The middle-end is responsible for optimization via symbolic manipulation. The backend converts the IR into machine code suitable for the intended architecture.
12
12
@@ -64,7 +64,7 @@ Further Reading:
64
64
65
65
- Iskander Sharipov in a [neat blogpost](https://quasilyte.dev/blog/post/go_ssa_rules/) goes through the SSA optimization rules used in the Go compiler.
66
66
67
-
- The $GOROOT/src/cmd/compile directory tree contains the [Introduction to the Go compiler](https://github.com/golang/go/blob/master/src/cmd/compile/README.md) and [Introduction to the Go compiler's SSA backend](https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/README.md) READMEs for those interested in the inner lives of the Go SSA-based compiler.
67
+
- The `$GOROOT/src/cmd/compile` directory tree contains the [Introduction to the Go compiler](https://github.com/golang/go/blob/master/src/cmd/compile/README.md) and [Introduction to the Go compiler's SSA backend](https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/README.md) READMEs for those interested in the inner lives of the Go SSA-based compiler.
68
68
69
69
-[Go: Overview of the Compiler](https://medium.com/a-journey-with-go/go-overview-of-the-compiler-4e5a153ca889) by Vincent Blanchon.
@@ -201,21 +201,21 @@ As it stands, gccgo & gollvm have a few limitations and/or concerns:
201
201
202
202
### Gopherjs
203
203
204
-
Before the Go compiler (gc) learning how to target wasm [in Go 1.11](https://github.com/golang/go/wiki/WebAssembly), the only way to write Go code targeting JavaScript runtimes was via [gopherjs](https://github.com/gopherjs/gopherjs). The commandable effort results in a [list where the majority of stdlib package are supported](https://github.com/gopherjs/gopherjs/blob/master/doc/packages.md). Not only are there [bindings](https://github.com/gopherjs/gopherjs/wiki/Bindings) for some of the most common JavaScript libraries and frameworks, there's [Vecty](https://github.com/gopherjs/vecty) for anyone who would like to write their app in Go end-to-end. If you would like to have a peek at something familiar and digestable, you can take a look at the [TodoMVC implementation with Gopherjs](https://github.com/gopherjs/todomvc).
204
+
Before the Go compiler (gc) learning how to target wasm [in Go 1.11](https://github.com/golang/go/wiki/WebAssembly), the only way to write Go code targeting JavaScript runtimes was via [gopherjs](https://github.com/gopherjs/gopherjs). The commandable effort results in a [list where the majority of stdlib package are supported](https://github.com/gopherjs/gopherjs/blob/master/doc/packages.md). Not only are there [bindings](https://github.com/gopherjs/gopherjs/wiki/Bindings) for some of the most common JavaScript libraries and frameworks, there's [Vecty](https://github.com/gopherjs/vecty) for anyone who would like to write their app in Go end-to-end. If you would like to have a peek at something familiar and digestable, you can take a look at the [TodoMVC implementation with Gopherjs](https://github.com/gopherjs/todomvc).
205
205
206
206
### TinyGo
207
207
208
-
Go programmers who are also into programming microcontrolleres and are tired of C/C++ and assembly have the [TinyGo](https://tinygo.org/) project to the rescude. TinyGo is a Go compiler whose tagline is "Go compiler for small places." The compiler relies on LLVM to do the heavy lifting, and supports a decent amount of [the language features](https://tinygo.org/lang-support/) and [the standard library](https://tinygo.org/lang-support/stdlib/). Now you can use Go in your next Arduino Uno project.
208
+
Go programmers who are also into programming microcontrolleres and are tired of C/C++ and assembly have the [TinyGo](https://tinygo.org/) project to the rescue. TinyGo is a Go compiler whose tagline is "Go compiler for small places." The compiler relies on LLVM to do the heavy lifting, and supports a decent amount of [the language features](https://tinygo.org/lang-support/) and [the standard library](https://tinygo.org/lang-support/stdlib/). Now you can use Go in your next Arduino Uno project.
209
209
210
210
### TARDIS Go
211
211
212
-
This is perhaps the most fun compiler. The [TARDIS Go](https://github.com/tardisgo/tardisgo) compiler generates the SSA form of the Go code, then uses the SSA to generate Haxe code conforming to the behavior of the Go code. Wait there's more. The Haxe toolchain can then be invoked to translate the Haxe code to C++, C#, Java, or JavaScript, thus allowing Go packages to be used on the respective platforms (.e.g. JVM).
212
+
This is perhaps the most fun compiler. The [TARDIS Go](https://github.com/tardisgo/tardisgo) compiler generates the SSA form of the Go code, then uses the SSA to generate Haxe code conforming to the behavior of the Go code. Wait there's more. The Haxe toolchain can then be invoked to translate the Haxe code to C++, C#, Java, or JavaScript, thus allowing Go packages to be used on the respective platforms (e.g. JVM).
213
213
214
214
The [demo page](https://tardisgo.github.io/) of the project is still running the same JavaScript code generated from Haxe that's in turn generated from Go via TARDIS Go. Sadly, the project hasn't been updated since 2016, thus its implementation of the Go runtime is at Go 1.4. It would be nice to see the project resurrected and extended to add Go as Haxe target, thus enabling interoperability across all the supported languages and enriching the entire ecosystem.
215
215
216
216
## In Sum
217
217
218
-
This list is definitely not exhaustive nor should it. Different compilers serve different goals. New implmentations put both the spec and the implementations to the test, more tests means more eyeballs, and "given enough eyeballs, all bugs are shallow." Even compilers that aim at unconventional targets, namely TARDIS Go, managed to [find](https://github.com/golang/go/issues/12196)[three](https://github.com/golang/go/issues/7166)[bugs](https://github.com/golang/go/issues/10127) in Go toolchain.
218
+
This list is definitely not exhaustive nor should it. Different compilers serve different goals. New implementations put both the spec and the implementations to the test, more tests means more eyeballs, and "given enough eyeballs, all bugs are shallow." Even compilers that aim at unconventional targets, namely TARDIS Go, managed to [find](https://github.com/golang/go/issues/12196)[three](https://github.com/golang/go/issues/7166)[bugs](https://github.com/golang/go/issues/10127) in Go toolchain.
219
219
220
220
Ian Lance Taylor himself has an answer to the question in his Quora response to the prompt [Why are there multiple compilers and interpreters for each programming language?](https://www.quora.com/Why-are-there-multiple-compilers-and-interpreters-for-each-programming-language-How-do-you-go-about-choosing-the-best-interpreter-or-compiler-for-your-project/answer/Ian-Lance-Taylor)
0 commit comments