# llvm_study **Repository Path**: fenixchen/llvm_study ## Basic Information - **Project Name**: llvm_study - **Description**: LLVM study - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-02-07 - **Last Updated**: 2023-03-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # tutorial https://www.llvm.org/docs/tutorial/MyFirstLanguageFrontend/index.html # Chapter1 语言介绍和词法分析 https://www.llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl01.html Kaleidoscope language and Lexer - This shows where we are going and the basic functionality that we want to build. ```c # Compute the x'th fibonacci number. def fib(x) if x < 3 then 1 else fib(x-1)+fib(x-2) # This expression will compute the 40th number. fib(40) ``` ## 词法分析 A lexer is also the first part of building a parser for a language, and we use a simple C++ lexer which is easy to understand. toy1.cpp # Chapter2 语法树和解析器 https://www.llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl02.html With the lexer in place, we can talk about parsing techniques and basic AST construction. This tutorial describes recursive descent parsing and operator precedence parsing. 抽象语法树 The Abstract Syntax Tree (AST) # Chapter3 IR代码生成 https://www.llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl03.html Code generation to LLVM IR - with the AST ready, we show how easy it is to generate LLVM IR, and show a simple way to incorporate LLVM into your project. # Chapter4 JIT和优化 Adding JIT and Optimizer Support - One great thing about LLVM is its support for JIT compilation, so we’ll dive right into it and show you the 3 lines it takes to add JIT support. Later chapters show how to generate .o files. # Chapter5 语言控制流 Extending the Language: Control Flow - With the basic language up and running, we show how to extend it with control flow operations (‘if’ statement and a ‘for’ loop). This gives us a chance to talk about SSA construction and control flow. # Chapter6 自定义操作符 Extending the Language: User-defined Operators - This chapter extends the language to let users define arbitrary unary and binary operators - with assignable precedence! This allows us to build a significant piece of the “language” as library routines. # Chapter7 自定义本地变量 Extending the Language: Mutable Variables - This chapter talks about adding user-defined local variables along with an assignment operator. This shows how easy it is to construct SSA form in LLVM: LLVM does not require your front-end to construct SSA form in order to use it! # Chapter8 生成OBJ文件 Compiling to Object Files - This chapter explains how to take LLVM IR and compile it down to object files, like a static compiler does. # Chapter9 调试信息 Debug Information - A real language needs to support debuggers, so we add debug information that allows setting breakpoints in Kaleidoscope functions, print out argument variables, and call functions! # Chapter 10 结论和扩展 Conclusion and other tidbits - This chapter wraps up the series by discussing ways to extend the language and includes pointers to info on “special topics” like adding garbage collection support, exceptions, debugging, support for “spaghetti stacks”, etc. By the end of the tutorial, we’ll have written a bit less than 1000 lines of (non-comment, non-blank) lines of code. With this small amount of code, we’ll have built up a nice little compiler for a non-trivial language including a hand-written lexer, parser, AST, as well as code generation support - both static and JIT! The breadth of this is a great testament to the strengths of LLVM and shows why it is such a popular target for language designers and others who need high performance code generation. # Tutorial: Creating an LLVM Backend for the Cpu0 Architecture http://jonathan2251.github.io/lbd/index.html # LLVM Architecture http://www.aosabook.org/en/llvm.html # Writing an LLVM Backend https://www.llvm.org/docs/WritingAnLLVMBackend.html # LLVM基本概念入门 https://zhuanlan.zhihu.com/p/140462815 # LLVM 后端实践笔记 0:序 https://zhuanlan.zhihu.com/p/351848328