官术网_书友最值得收藏!

  • LLVM Essentials
  • Suyog Sarda Mayur Pandey
  • 325字
  • 2021-07-30 09:55:53

Chapter 2. Building LLVM IR

A high level programming language facilitates human interaction with the target machine. Most of the popular high level languages today have certain basic elements such as variables, loops, if-else decision making statements, blocks, functions, and so on. A variable holds value of data types; a basic block gives an idea of the scope of the variable. An if-else decision statement helps in selection of a path of code. A function makes a block of code reusable. High level languages may vary in type checking, type casting, variable declarations, complex data types, and so on. However, almost every other language has the basic building blocks listed earlier in this section.

A language may have its own parser which tokenizes the statement and extracts meaningful information such as identifier, its data type; a function name, its declaration, definition and calls; a loop condition, and so on. This meaningful information may be stored in a data structure where the flow of the code can be easily retrieved. Abstract Syntax Tree (AST) is a popular tree representation of the source code. The AST's can be used for further transformation and analysis.

A language parser can be written in various ways with various tools such as lex, yacc, and so on, or can even be handwritten. Writing an efficient parser is an art in itself. But this is not what we intend to cover in this chapter. We would like to focus more on LLVM IR and how a high-level language after parsing can be converted to LLVM IR using LLVM libraries.

This chapter will cover how to construct basic working LLVM sample code, which includes the following:

  • Creating an LLVM module
  • Emitting a function in a module
  • Adding a block to a function
  • Emitting a global variable
  • Emitting a return statement
  • Emitting function arguments
  • Emitting a simple arithmetic statement in a basic block
  • Emitting if-else condition IR
  • Emitting LLVM IR for loops
主站蜘蛛池模板: 汝阳县| 礼泉县| 庆云县| 永年县| 长宁县| 阿坝县| 神农架林区| 项城市| 和田县| 武冈市| 三原县| 枞阳县| 重庆市| 盐山县| 富宁县| 无为县| 青海省| 东山县| 错那县| 安平县| 灵川县| 静海县| 泽库县| 安阳县| 余江县| 山丹县| 巢湖市| 三穗县| 治多县| 南宫市| 黑龙江省| 邛崃市| 安新县| 涡阳县| 鄂州市| 阿坝县| 蒙阴县| 常熟市| 镇沅| 南开区| 宁波市|