{"id":13413512,"url":"https://github.com/llir/llvm","last_synced_at":"2025-05-14T09:07:06.138Z","repository":{"id":20938860,"uuid":"24227197","full_name":"llir/llvm","owner":"llir","description":"Library for interacting with LLVM IR in pure Go.","archived":false,"fork":false,"pushed_at":"2024-12-06T18:03:01.000Z","size":1729,"stargazers_count":1220,"open_issues_count":18,"forks_count":80,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-12T15:56:23.033Z","etag":null,"topics":["go","golang","llvm","llvm-ir"],"latest_commit_sha":null,"homepage":"https://llir.github.io/document/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/llir.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-19T11:18:44.000Z","updated_at":"2025-04-02T12:51:32.000Z","dependencies_parsed_at":"2024-06-18T12:31:03.843Z","dependency_job_id":"f4b2d7ae-e9de-47c6-bf68-7dc7d19a1f77","html_url":"https://github.com/llir/llvm","commit_stats":{"total_commits":1678,"total_committers":14,"mean_commits":"119.85714285714286","dds":0.06674612634088195,"last_synced_commit":"f0912dd3bef26c6498c896afea9faa0736594d35"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llir%2Fllvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llir%2Fllvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llir%2Fllvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llir%2Fllvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/llir","download_url":"https://codeload.github.com/llir/llvm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"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":["go","golang","llvm","llvm-ir"],"created_at":"2024-07-30T20:01:42.054Z","updated_at":"2025-05-14T09:07:06.087Z","avatar_url":"https://github.com/llir.png","language":"Go","readme":"# llvm\n\n[![Build Status](https://github.com/llir/llvm/actions/workflows/go.yml/badge.svg?branch=master)](https://github.com/llir/llvm/actions/workflows/go.yml)\n[![Coverage Status](https://coveralls.io/repos/github/llir/llvm/badge.svg?branch=master)](https://coveralls.io/github/llir/llvm?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/llir/llvm)](https://goreportcard.com/report/github.com/llir/llvm)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/llir/llvm)\n\nLibrary for interacting with [LLVM IR](http://llvm.org/docs/LangRef.html) in pure Go.\n\n## Introduction\n\n* [Introductory blog post \"LLVM IR and Go\"](https://blog.gopheracademy.com/advent-2018/llvm-ir-and-go/)\n* [Our Document](https://llir.github.io/document/)\n\n## Installation\n\n```bash\ngo get github.com/llir/llvm/...\n```\n\n## Versions\n\nMap between `llir/llvm` tagged releases and LLVM release versions.\n\n* [llir/llvm v0.3.7](https://github.com/llir/llvm/tree/v0.3.7): LLVM 15.0 (yet to be released)\n* [llir/llvm v0.3.6](https://github.com/llir/llvm/tree/v0.3.6): LLVM 14.0\n* [llir/llvm v0.3.5](https://github.com/llir/llvm/tree/v0.3.5): LLVM 13.0\n* [llir/llvm v0.3.4](https://github.com/llir/llvm/tree/v0.3.4): LLVM 12.0\n* [llir/llvm v0.3.3](https://github.com/llir/llvm/tree/v0.3.3): LLVM 11.0\n* [llir/llvm v0.3.2](https://github.com/llir/llvm/tree/v0.3.2): LLVM 10.0\n* [llir/llvm v0.3.0](https://github.com/llir/llvm/tree/v0.3.0): LLVM 9.0\n\n## Users\n\n* [decomp](https://github.com/decomp/decomp): LLVM IR to Go decompiler by [@decomp](https://github.com/decomp).\n* [geode](https://github.com/geode-lang/geode): Geode to LLVM IR compiler by [@nickwanninger](https://github.com/nickwanninger).\n* [leaven](https://github.com/andybalholm/leaven): LLVM IR to Go decompiler by [@andybalholm](https://github.com/andybalholm).\n* [slate](https://github.com/nektro/slate): Slate to LLVM IR compiler by [@nektro](https://github.com/nektro).\n* [tre](https://github.com/zegl/tre): Go to LLVM IR compiler by [@zegl](https://github.com/zegl).\n* [uc](https://github.com/mewmew/uc): µC to LLVM IR compiler by [@sangisos](https://github.com/sangisos) and [@mewmew](https://github.com/mewmew).\n* [B++](https://github.com/Nv7-Github/Bpp): B++ to LLVM IR compiler by [@Nv7-Github](https://github.com/Nv7-Github).\n\n## Usage\n\n### Input example, parsing LLVM IR assembly\n\n[Example usage in GoDoc](https://pkg.go.dev/github.com/llir/llvm/asm#example-package).\n\n```go\n// This example parses an LLVM IR assembly file and pretty-prints the data types\n// of the parsed module to standard output.\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/kr/pretty\"\n\t\"github.com/llir/llvm/asm\"\n)\n\nfunc main() {\n\t// Parse the LLVM IR assembly file `foo.ll`.\n\tm, err := asm.ParseFile(\"foo.ll\")\n\tif err != nil {\n\t\tlog.Fatalf(\"%+v\", err)\n\t}\n\t// Pretty-print the data types of the parsed LLVM IR module.\n\tpretty.Println(m)\n}\n```\n\n### Output examples, producing LLVM IR assembly\n\n#### Hello, World\n\n[Example usage in GoDoc](https://pkg.go.dev/github.com/llir/llvm/ir#example-package-Hello).\n\n```go\n// This example produces LLVM IR generating \"Hello, World\" output.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/llir/llvm/ir\"\n\t\"github.com/llir/llvm/ir/constant\"\n\t\"github.com/llir/llvm/ir/types\"\n)\n\nfunc main() {\n\t// Create a new LLVM IR module.\n\tm := ir.NewModule()\n\thello := constant.NewCharArrayFromString(\"Hello, world!\\n\\x00\")\n\tstr := m.NewGlobalDef(\"str\", hello)\n\t// Add external function declaration of puts.\n\tputs := m.NewFunc(\"puts\", types.I32, ir.NewParam(\"\", types.NewPointer(types.I8)))\n\tmain := m.NewFunc(\"main\", types.I32)\n\tentry := main.NewBlock(\"\")\n\t// Cast *[15]i8 to *i8.\n\tzero := constant.NewInt(types.I64, 0)\n\tgep := constant.NewGetElementPtr(hello.Typ, str, zero, zero)\n\tentry.NewCall(puts, gep)\n\tentry.NewRet(constant.NewInt(types.I32, 0))\n\tfmt.Println(m)\n}\n```\n\n#### Pseudo Random-Number Generator\n\n[Example usage in GoDoc](https://pkg.go.dev/github.com/llir/llvm/ir#example-package).\n\n```go\n// This example produces LLVM IR code equivalent to the following C code, which\n// implements a pseudo-random number generator.\n//\n//    int abs(int x);\n//\n//    int seed = 0;\n//\n//    // ref: https://en.wikipedia.org/wiki/Linear_congruential_generator\n//    //    a = 0x15A4E35\n//    //    c = 1\n//    int rand(void) {\n//       seed = seed*0x15A4E35 + 1;\n//       return abs(seed);\n//    }\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/llir/llvm/ir\"\n\t\"github.com/llir/llvm/ir/constant\"\n\t\"github.com/llir/llvm/ir/types\"\n)\n\nfunc main() {\n\t// Create convenience types and constants.\n\ti32 := types.I32\n\tzero := constant.NewInt(i32, 0)\n\ta := constant.NewInt(i32, 0x15A4E35) // multiplier of the PRNG.\n\tc := constant.NewInt(i32, 1)         // increment of the PRNG.\n\n\t// Create a new LLVM IR module.\n\tm := ir.NewModule()\n\n\t// Create an external function declaration and append it to the module.\n\t//\n\t//    int abs(int x);\n\tabs := m.NewFunc(\"abs\", i32, ir.NewParam(\"x\", i32))\n\n\t// Create a global variable definition and append it to the module.\n\t//\n\t//    int seed = 0;\n\tseed := m.NewGlobalDef(\"seed\", zero)\n\n\t// Create a function definition and append it to the module.\n\t//\n\t//    int rand(void) { ... }\n\trand := m.NewFunc(\"rand\", i32)\n\n\t// Create an unnamed entry basic block and append it to the `rand` function.\n\tentry := rand.NewBlock(\"\")\n\n\t// Create instructions and append them to the entry basic block.\n\ttmp1 := entry.NewLoad(i32, seed)\n\ttmp2 := entry.NewMul(tmp1, a)\n\ttmp3 := entry.NewAdd(tmp2, c)\n\tentry.NewStore(tmp3, seed)\n\ttmp4 := entry.NewCall(abs, tmp3)\n\tentry.NewRet(tmp4)\n\n\t// Print the LLVM IR assembly of the module.\n\tfmt.Println(m)\n}\n```\n\n### Analysis example, processing LLVM IR\n\n[Example usage in GoDoc](https://pkg.go.dev/github.com/llir/llvm/ir#example-package-Callgraph).\n\n```go\n// This example program analyses an LLVM IR module to produce a callgraph in\n// Graphviz DOT format.\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/llir/llvm/asm\"\n\t\"github.com/llir/llvm/ir\"\n)\n\nfunc main() {\n\t// Parse LLVM IR assembly file.\n\tm, err := asm.ParseFile(\"foo.ll\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// Produce callgraph of module.\n\tcallgraph := genCallgraph(m)\n\t// Output callgraph in Graphviz DOT format.\n\tfmt.Println(callgraph)\n}\n\n// genCallgraph returns the callgraph in Graphviz DOT format of the given LLVM\n// IR module.\nfunc genCallgraph(m *ir.Module) string {\n\tbuf := \u0026strings.Builder{}\n\tbuf.WriteString(\"digraph {\\n\")\n\t// For each function of the module.\n\tfor _, f := range m.Funcs {\n\t\t// Add caller node.\n\t\tcaller := f.Ident()\n\t\tfmt.Fprintf(buf, \"\\t%q\\n\", caller)\n\t\t// For each basic block of the function.\n\t\tfor _, block := range f.Blocks {\n\t\t\t// For each non-branching instruction of the basic block.\n\t\t\tfor _, inst := range block.Insts {\n\t\t\t\t// Type switch on instruction to find call instructions.\n\t\t\t\tswitch inst := inst.(type) {\n\t\t\t\tcase *ir.InstCall:\n\t\t\t\t\tcallee := inst.Callee.Ident()\n\t\t\t\t\t// Add edges from caller to callee.\n\t\t\t\t\tfmt.Fprintf(buf, \"\\t%q -\u003e %q\\n\", caller, callee)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Terminator of basic block.\n\t\t\tswitch term := block.Term.(type) {\n\t\t\tcase *ir.TermRet:\n\t\t\t\t// do something.\n\t\t\t\t_ = term\n\t\t\t}\n\t\t}\n\t}\n\tbuf.WriteString(\"}\")\n\treturn buf.String()\n}\n```\n\n## License\n\nThe `llir/llvm` project is dual-licensed to the [public domain](UNLICENSE) and under a [zero-clause BSD license](LICENSE). You may choose either license to govern your use of `llir/llvm`.\n","funding_links":[],"categories":["开源类库","Go","Open source library","其他杂项","Miscellaneous","Repositories","Microsoft Office","杂项","Uncategorized"],"sub_categories":["编译器","Translator","暂未分类","Strings","Uncategorized","Advanced Console UIs","未分类的","暂未分类这些库被放在这里是因为其他类别似乎都不适合。"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllir%2Fllvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fllir%2Fllvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllir%2Fllvm/lists"}