{"id":14991176,"url":"https://github.com/evian-zhang/llvm-ir-tutorial","last_synced_at":"2025-05-16T04:04:22.374Z","repository":{"id":43054665,"uuid":"280558047","full_name":"Evian-Zhang/llvm-ir-tutorial","owner":"Evian-Zhang","description":"LLVM IR入门指南","archived":false,"fork":false,"pushed_at":"2024-01-31T01:15:44.000Z","size":244,"stargazers_count":1391,"open_issues_count":1,"forks_count":155,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-04-18T11:24:25.951Z","etag":null,"topics":["llvm","llvm-ir"],"latest_commit_sha":null,"homepage":"https://evian-zhang.github.io/llvm-ir-tutorial/","language":"LLVM","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc-by-4.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Evian-Zhang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG/v2.0.0-2023-06-28.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":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-18T01:25:56.000Z","updated_at":"2025-04-18T09:17:23.000Z","dependencies_parsed_at":"2022-07-16T15:47:09.603Z","dependency_job_id":"7b7750e7-f76d-448c-b81d-9b83eac7f37e","html_url":"https://github.com/Evian-Zhang/llvm-ir-tutorial","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evian-Zhang%2Fllvm-ir-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evian-Zhang%2Fllvm-ir-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evian-Zhang%2Fllvm-ir-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evian-Zhang%2Fllvm-ir-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Evian-Zhang","download_url":"https://codeload.github.com/Evian-Zhang/llvm-ir-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464891,"owners_count":22075570,"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":["llvm","llvm-ir"],"created_at":"2024-09-24T14:21:40.010Z","updated_at":"2025-05-16T04:04:22.357Z","avatar_url":"https://github.com/Evian-Zhang.png","language":"LLVM","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLVM IR入门指南\n\n本仓库是我写的LLVM IR入门指南。\n\n推荐前往\u003chttps://Evian-Zhang.github.io/llvm-ir-tutorial\u003e阅读以获得最佳排版及语法高亮体验。PDF版本下载请点击前述网页的右上角。本教程中涉及的大部分代码也都在本GitHub仓库[Evian-Zhang/llvm-ir-tutorial](https://github.com/Evian-Zhang/llvm-ir-tutorial)中。\n\nLLVM是当下最通用的编译器后端之一，无论是想自己动手制作一个编译器，还是为主流的编程语言增加功能，又或者是做软件的静态分析，都离不开LLVM。LLVM IR是LLVM架构中一个重要的组成成分，编译器前端将抽象语法树转变为LLVM IR，而编译器后端则根据LLVM IR进行优化，生成可执行程序。但是，目前对LLVM IR的中文介绍少之又少。因此，我就写了这样的一系列文章，介绍了LLVM的架构，并且从LLVM IR的层面，让大家系统地了解LLVM。\n\n最近（2023年6月），这个GitHub仓库的star数即将达到一千。因此，我打算基于现有的脉络，大范围更新现有的文章，推出LLVM IR入门指南2.0版（如需查看1.0版，请移步[v1分支](https://github.com/Evian-Zhang/llvm-ir-tutorial/tree/v1)）。我这次更新的原因主要有以下几点：\n\n* LLVM版本更新\n\n   LLVM是一个不断演进的，由社区积极维护的项目。本系列文章写作于2020年，会有一些落后的知识点，也会有一些新的技术没有涵盖到。因此，本次更新将针对最新的LLVM 16进行写作。\n* 操作系统变化\n\n   在1.0版中，我是以macOS为操作系统来介绍的。但是，随着Apple Silicon Mac占据主流地位，使用Intel芯片的Mac越来越少。由于文章中会大量地使用LLVM IR编译后的AMD64汇编指令作为解释说明，所以本次更新将从macOS转变为Linux，从而也可以使更多的读者能够在自己的机器中对文章中的代码进行验证。\n* 知识水平提升\n\n   在过去的这三年里，我也学习了很多新的知识。并且，我也写出了不少关于底层二进制相关的系列文章，如：\n\n   * [macOS上的汇编入门](https://github.com/Evian-Zhang/Assembly-on-macOS)\n\n      针对Intel芯片Mac的macOS下AMD64架构汇编入门教程\n   * [在Apple Silicon Mac上入门汇编语言](https://github.com/Evian-Zhang/learn-assembly-on-Apple-Silicon-Mac)\n\n      针对Apple Silicon Mac的macOS下AArch64架构汇编入门教程\n   * [WASM汇编入门教程](https://github.com/Evian-Zhang/wasm-tutorial)\n\n      针对浏览器中的前端新宠儿WebAssembly汇编入门教程\n\n   在这些经验的积累下，我可以更具体、更准确地对文章的内容进行修补。\n\n本人水平有限，写此系列文章仅希望与大家分享学习经验，文章中必有缺漏、错误之处，望方家不吝斧正，与大家共同学习，共同进步，谢谢大家！\n\n## 前置知识\n\n本系列文章所需的前置知识包括\n\n* 掌握Linux基本命令（如使用命令行等）\n* 掌握C语言编程知识\n* 掌握AMD64指令集汇编知识\n\n## 环境\n\n本系列文章使用的环境包括\n\n* CPU\n\n   Intel i9-12900K\n* 操作系统\n\n   Ubuntu 22.04，内核为Linux 5.19.0\n* 编译器\n\n   C语言采用Clang 16编译器。LLVM采用LLVM 16版本。\n\n## 本地生成可阅读版本\n\n本系列文章可以在GitHub Pages \u003chttps://Evian-Zhang.github.io/llvm-ir-tutorial\u003e上阅读并生成PDF。如果想在本地离线阅读，可以按照如下步骤生成可阅读版本。\n\n### 1. 克隆本仓库\n\n```shell\ngit clone https://github.com/Evian-Zhang/llvm-ir-tutorial \u0026\u0026 cd llvm-ir-tutorial\n```\n\n### 2. 准备语法高亮文件\n\n由于MDBook自带的highlightjs并不支持本书的所有语法高亮，所以需要按照其官方文档中[Custom theme](https://rust-lang.github.io/mdBook/format/theme/syntax-highlighting.html#custom-theme)的步骤准备自定义的语法高亮文件：\n\n```shell\ngit clone https://github.com/highlightjs/highlight.js \u0026\u0026 cd highlight.js\nnpm install\nnode tools/build.js \\\n   bash \\\n   c \\\n   llvm \\\n   x86asm \\\n   plaintext \\\n   shell \\\n   rust\ncd ..\nmkdir -p theme\ncp highlight.js/build/highlight.min.js theme/highlight.js\n```\n\n### 3. 使用MDBook生成最终文档\n\n使用MDBook，其可通过`cargo install mdbook`进行安装。\n\n```shell\nmdbook build\n```\n\n生成的文档将位于`book/`目录下。\n\n同时，也可以使用\n\n```shell\nmdbook serve\n```\n\n在本地启动一个服务器，从而可以更方便地在浏览器中阅读。\n\n#### License\n\n\u003csup\u003e\n本仓库遵循\u003ca href=\"https://creativecommons.org/licenses/by/4.0/\"\u003eCC-BY-4.0版权协议\u003c/a\u003e。\n\u003c/sup\u003e\n\n\u003cbr/\u003e\n\n\u003csub\u003e\n作为\u003ca href=\"https://copyleft.org/\"\u003ecopyleft\u003c/a\u003e的支持者之一，我由衷地欢迎大家积极热情地参与到开源社区中。Happy coding!\n\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevian-zhang%2Fllvm-ir-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevian-zhang%2Fllvm-ir-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevian-zhang%2Fllvm-ir-tutorial/lists"}