{"id":19645441,"url":"https://github.com/corani/go-llvm-playground","last_synced_at":"2025-02-26T23:44:09.292Z","repository":{"id":80471582,"uuid":"325431356","full_name":"corani/go-llvm-playground","owner":"corani","description":null,"archived":false,"fork":false,"pushed_at":"2021-01-06T08:42:18.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-09-08T15:44:04.903Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/corani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-30T02:08:35.000Z","updated_at":"2024-06-19T07:53:36.836Z","dependencies_parsed_at":null,"dependency_job_id":"878f8a4e-3116-44e5-a242-f81070356a76","html_url":"https://github.com/corani/go-llvm-playground","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corani%2Fgo-llvm-playground","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corani%2Fgo-llvm-playground/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corani%2Fgo-llvm-playground/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corani%2Fgo-llvm-playground/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/corani","download_url":"https://codeload.github.com/corani/go-llvm-playground/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240952979,"owners_count":19884020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T14:33:59.533Z","updated_at":"2025-02-26T23:44:09.275Z","avatar_url":"https://github.com/corani.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go LLVM Playground\n\nHere I'm collecting some sample code I wrote while playing around with the Golang bindings for\nLLVM, as they may help others get started.\n\n## LLVM C Bindings\n\n### Setup\n\nI'm using Ubuntu 18.04 and Go 1.14.9 on a system that I've used for development for some time\nalready, so I've no idea which dependencies are required, as most of them were installed already.\n\n1. Get the LLVM bindings:\n   `go get -d github.com/llvm/llvm-project/llvm/bindings/go/llvm`\n\n   Note: This pulls down the entire LLVM project, which is rather large. This will take a while!\n\n2. Build the LLVM bindings:\n   ```bash\n   cd $GOPATH/src/github.com/llvm/llvm-project/llvm/bindings/go\n   ./build.sh -DLLVM_TARGETS_TO_BUILD=host\n   ```\n\n   Note: This builds the entire LLVM project, so this will take a while (and use a few GB of disk)\n\nThe above will generate a `llvm_config.go` file in the `llvm` package with the CGO flags baked in.\n\nNote: I had to install cmake from the [Kitware APT Repository](https://apt.kitware.com), as the\nversion in the Ubuntu repository was too old.\n\nNote: I had to *uninstall* ninja-build, as I couldn't get this to build the project without errors\nabout missing libraries.\n\n### Examples\n\n- [src/add/main.go](src/add/main.go)\n\n  Export a simple Go function to the C namespace, generate a new module using LLVM that defines\n  a `main` function with two local variables. Invoke the Go function from the `main` function and\n  return the result.\n\n  Use the LLVM JIT compiler to execute the `main` function from within Go and print the result.\n\n- [src/hello/main.go](src/hello/main.go)\n\n  Generate a new module using LLVM that defines a global constant for \"Hello, world!\" and a\n  `main` function that prints the string using `puts`. Write the LL, ASM and OBJ code for this\n  module to the current working directory, then link the object file into an executable.\n\n  I have not found a way to generate an executable directly from the LLVM bindings, so I had to\n  call out to `gcc` to do this.\n\n- [src/expr/](src/expr/)\n\n  The world's worst expression parser/compiler. Read an expression (which can only exist of one\n  positive integer followed by a `+` or `-` followed by another positive integer, all without any\n  whitespace) from a file and compile a program that executes the expression and prints the result.\n\n### Resources\n\n- The \"Add\" example borrows heavily from [An introduction to LLVM in Go](https://felixangell.com/blogs/an-introduction-to-llvm-in-go).\n- The \"Hello\" example takes some inspiration from [llvm-hello-world](https://github.com/dfellis/llvm-hello-world).\n\n## LLIR\n\nA library for interacting with LLVM IR in pure Go.\n\n### Setup\n\n`go get -u github.com/llir/llvm/...`\n\n### Examples\n\n- [src/hello-ir/main.go](src/hello-ir/main.go)\n\n  Generate a new module using the Go `llir/llvm` library that defines a global constant\n  \"Hello, world!\" and a `main` function that prints the string using `puts`. Write the LL for\n  this module to the current working directory.\n\n  To create an executable, the easiest way is to use clang:\n\n  ```bash\n  $ go run main.go\n  $ clang -i hello hello.ll\n  ```\n\n### Resources\n\n- [LLVM IR and Go](https://blog.gopheracademy.com/advent-2018/llvm-ir-and-go/).\n- [llir/llvm documentation](https://llir.github.io/document/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorani%2Fgo-llvm-playground","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorani%2Fgo-llvm-playground","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorani%2Fgo-llvm-playground/lists"}