• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    Go
  • License
    The Unlicense
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Live coding a basic Go compiler with LLVM in 20 minutes

go2ll-talk

The code presented at Sheffield Go, 7th March.

Slides link

To run, just say make.

To take a look at the output of the program, run go run ., or build it and run it as you would any go program.

What's going on?

The goal of this talk was to show you how you could use some existing tooling to make a binary from Go code.

Of course, this isn't possible in 20 minutes, so we take some liberties:

  1. We use Go's x/tools/ssa (static single assignment) package, which enables us to turn Go's langauge semantics into a fairly simple data structure we can work with. (This is called the Intermediate Representation, or "IR").

  2. We use LLVM, which is a compiler framework which also uses static single assignment for its IR.

  3. The goal of this program then is to translate from one IR to the other.

To show some output, we use printf, which we steal from libc, C's runtime. We compile the resulting intermediate clang, the C frontend, which happens to be able to compile .ll (LLVM's "assembly" format).

This compiler is not at all general. It supports only the + operator and calling the println function (which is actually libc's printf function). So it can't do very much. But hopefully that simplicity is also what allows some newcomers to understand it.

go2ll

In the near future I plan to publish go2ll, which is a slightly more sophisticated frontend. It will only ever be a toy, because, for example, it is unlikely to implement garbage collection and goroutines. This means it won't be good for abitrary Go programs. On the other hand, I can still think of a few interesting uses, such as for speeding up CPU intensive compute kernels. I have already been able to demonstrate 30-40% speedups in already fairly well tuned code such as that for computing SHA1 and strconv.ParseFloat.

More Repositories

1

pyfiglet

An implementation of figlet written in Python
Python
1,348
star
2

goupx

Fix golang compiled binaries on x86_64 so that they can be packed with UPX
Go
334
star
3

docker-show-context

Show where time is wasted during the context upload of `docker build`
Go
331
star
4

pyprof2calltree

Profile python programs and view them with kcachegrind
Python
156
star
5

goimports-update-ignore

Generate .goimportsignore and make goimports fast
Go
65
star
6

go-ffmpeg-video-encoding

Basic bindings for ffmpeg video encoding
Go
22
star
7

perf

Linux Perf subsystem bindings for Go
Go
21
star
8

go2ll

Extremely experimental toy go compiler
Go
19
star
9

waitsilence

an executable which blocks until it receives nothing on stdin for a specified time
Go
18
star
10

zerocopy

go zerocopy.Reader interface and implementation
Go
13
star
11

sharedextents

Show proportion of physical extents shared between two files
Go
12
star
12

fienode

Discover identical CoW copies, analogous to an inode
Go
11
star
13

go-clz4

fast cgo implementation of lz4
C
10
star
14

cartographer

Quickly find non-determinism bugs caused by loops over maps
Go
9
star
15

sha1-visualizer

Visualize SHA1 bit differences
JavaScript
7
star
16

usv

Go
7
star
17

iptables-block-dns

Block distractions by dropping DNS packets
Shell
5
star
18

git-minecraft-smudge

(defunct) Abusing git's filter mechanism for fun and profit.
Go
4
star
19

httpcache

{non,}Transparent MITM http{,s} proxy
Go
4
star
20

binview

A fun pointless visualization of arbitrary binary files
Python
3
star
21

pp2g

Crude python to go translator
Python
3
star
22

__autoversion__

Python
3
star
23

git-alot

Track the status of many git repositories
Python
3
star
24

go-hexcolor

golang Hex string color model
Go
2
star
25

jump

Jump to AWS machines
Go
2
star
26

gooda

C
2
star
27

minty

Python
2
star
28

wscat

cat. For websockets.
Go
2
star
29

bumphunter.pw

Simple implementation of the BumpHunter algorithm
Python
1
star
30

static-fusermount

Makefile
1
star
31

pwa

Python
1
star
32

inf

Infinity
Python
1
star
33

barrier

Signalling primitive for golang
Go
1
star
34

go-memhelper

Helper functions for avoiding OOM with many goroutines doing memory-heavy things
Go
1
star
35

ptrace-read

Go
1
star
36

httpservecache

Golang HTTP server caching middleware using groupcache
Go
1
star
37

fastwalk

Go
1
star
38

https-redirect

Redirect traffic from port 80 to 443
Go
1
star
39

keyboard

Keyboard offers a universal keyboard shortcut binding interface for various backends.
Go
1
star
40

runlocal

communicate commands to be run from remote to local over x-forwarding
Go
1
star
41

go-ping

Go
1
star