From ASTs to Machine Code with LLVM

Dimitri Racordon
{"title":"From ASTs to Machine Code with LLVM","authors":"Dimitri Racordon","doi":"10.1145/3464432.3464777","DOIUrl":null,"url":null,"abstract":"A compiler is a program that translates source code written in a particular language into another language. Internally, the whole process is typically split into multiple stages that handle one particular aspect of this translation. One of these consists of translating the high-level representation of the program, typically an abstract syntax tree, into a simpler form that is suitable for analysis, optimizations, and code generation. This tutorial paper focuses on this process, and uses LLVM to compile programs into optimized machine code. LLVM is a language-agnostic compiler toolchain that handles program optimization and code generation. It is based on its own internal representation, called LLVM IR, which is then transformed into machine code. We give a brief introduction to LLVM IR, and describe a few patterns to translate high-level language constructs expressed as abstract syntax trees. We implement these patterns in a compiler for a toy programming language, named Cocodol, which supports dynamic typing, unbounded loops, and higher-order functions.","PeriodicalId":421912,"journal":{"name":"Companion Proceedings of the 5th International Conference on the Art, Science, and Engineering of Programming","volume":"11 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2021-03-22","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"1","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Companion Proceedings of the 5th International Conference on the Art, Science, and Engineering of Programming","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/3464432.3464777","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 1

Abstract

A compiler is a program that translates source code written in a particular language into another language. Internally, the whole process is typically split into multiple stages that handle one particular aspect of this translation. One of these consists of translating the high-level representation of the program, typically an abstract syntax tree, into a simpler form that is suitable for analysis, optimizations, and code generation. This tutorial paper focuses on this process, and uses LLVM to compile programs into optimized machine code. LLVM is a language-agnostic compiler toolchain that handles program optimization and code generation. It is based on its own internal representation, called LLVM IR, which is then transformed into machine code. We give a brief introduction to LLVM IR, and describe a few patterns to translate high-level language constructs expressed as abstract syntax trees. We implement these patterns in a compiler for a toy programming language, named Cocodol, which supports dynamic typing, unbounded loops, and higher-order functions.
用LLVM从ast到机器码
编译器是将用一种特定语言编写的源代码翻译成另一种语言的程序。在内部,整个过程通常分为多个阶段,每个阶段处理翻译的一个特定方面。其中之一包括将程序的高级表示(通常是抽象语法树)转换为适合于分析、优化和代码生成的更简单的形式。本教程主要关注这个过程,并使用LLVM将程序编译成优化的机器码。LLVM是一个语言无关的编译器工具链,用于处理程序优化和代码生成。它基于自己的内部表示,称为LLVM IR,然后将其转换为机器码。我们简要介绍了LLVM IR,并描述了一些模式来翻译表达为抽象语法树的高级语言结构。我们在一种名为Cocodol的小编程语言的编译器中实现了这些模式,该语言支持动态类型、无界循环和高阶函数。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信