Using the GO frontend

The llgo compiler is the LLVM-based frontend for Go written in Go language only. Using this frontend, we can generate the LLVM assembly code from a program written in Go.

Getting ready

You need to download the llgo binaries or build llgo from the source code and add the binaries in the PATH file location as configured.

How to do it…

Do the following steps:

  1. Create a Go source file, for example, that will be used for generating the LLVM assembly using llgo. Create test.go:
    |$ cat test.go
    |package main
    |import "fmt"
    |func main() {
    | fmt.Println("Test Message")
    |}
    
  2. Now, use llgo to get the LLVM assembly:
    $llgo -dump test.go
    ; ModuleID = 'main'
    target datalayout = "e-p:64:64:64..."
    target triple = "x86_64-unknown-linux"
    %0 = type { ...

Get LLVM Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.