Aditya Chatterjee's Blog, page 90

May 10, 2022

Bootstraping a Compiler

Bootstrapping a compiler involves producing a self-compiling compiler, that is, we write a compiler using language A that produces code for target machine B and can still compile itself.

Table of contents.Introduction.Notation.Summary.References.Introduction.

As we saw in previous articles, we built a compiler for the Kaleidoscope programming language and supported many programming language functionalities, JIT compilation, and much more. We did all this using a high-level programming lan...

 •  0 comments  •  flag
Share on Twitter
Published on May 10, 2022 11:42

Compiling LLVM IR to Object Code

We have seen how to implement the Kaleidoscope programming language, from source code to an LLVM IR to optimization to implementing a JIT compiler and implementing further extensions. In this article, we will compile the LLVM IR into object code.

Table of contents.Introduction.The target machine.Object code.Tying it together.Summary.References.Prerequisites.

Variable Mutation in Kaleidoscope

Introduction.

In this article, we compile our code into object code. Object code is the output w...

 •  0 comments  •  flag
Share on Twitter
Published on May 10, 2022 11:27

Variable Mutation in Kaleidoscope

Mutation in programming languages involves the ability to change an object. In this article, we further extend our language, we add to it the ability to define new variables and mutate them.

Table of contents.Introduction.Adjusting existing variables for mutation.New assignment operator.User-defined local variables.Summary.References.Prerequisites.

LLVM Memory.

Introduction.

In this article, we will discuss mutable variables in the Kaleidoscope programming language. We will add two feat...

 •  0 comments  •  flag
Share on Twitter
Published on May 10, 2022 11:10

How to compile a compiler? [Bootstrapping]

In this article, we will learn the process and types of bootstrapping. Bootstrapping involves using compilers to compile other compilers or themselves.

Table of contents.Introduction.Full bootstrap.Using an interpreter.Incremental bootstrapping.Summary.References.Prerequisites.

Bootstraping a compiler

Introduction.

The idea of bootstrapping involves using compilers to compile compilers or themselves. For this, we need a solid foundation or a machine that we will use to run compilers on....

 •  0 comments  •  flag
Share on Twitter
Published on May 10, 2022 10:54

LLVM Memory and SSA

In this article, we learn all about SSA and LLVM memory and how the two are related.

Table of contents.Introduction.Mutable variables.LLVM Memory.Summary.References.Prerequisites.

User-defined Operators in Kaleidoscope.

Introduction.

In previous articles, we learned how to build and represent AST, generating LLVM IR, optimizing the code and JIT compilation.

SSA is s property of IR (Intermediate representation) that requires each variable to only be assigned once and each variable to be d...

 •  0 comments  •  flag
Share on Twitter
Published on May 10, 2022 10:43

User-defined Operators in Kaleidoscope

User-defined operators take in a set of operands as input and return a result. We want to support functionalities such as division, logical negation, comparisons, etc.

Table of contents.Introduction.Supporting Binary operators.Supporting Unary Operators.Summary.References.Prerequisites.

LLVM Control Flow: for loops.

Introduction.

Until now the language - Kaleidoscope generates optimized LLVM IR and supports JIT and control flow, we will further extend it to also include operators such as...

 •  0 comments  •  flag
Share on Twitter
Published on May 10, 2022 10:40

May 9, 2022

If-then-else in LLVM Control Flow

Control flow statements are statements used to change the flow of execution of the program. In this article, we extend Kaleidoscope to include control flow operations such as if-then-else statements.

Table of contents.Introduction.If-Then-Else.Lexer extensions.AST extensions.Parser extensions.LLVM IR extensions.Code generation extensions.Summary.References.Prerequisites.Implementing JIT(Just In Time) Compilation.Introduction.

In programming languages, control flow statements are ...

 •  0 comments  •  flag
Share on Twitter
Published on May 09, 2022 13:46

For loops in LLVM Control Flow

In programming, we use loops to repeat a sequence of instructions until a specified condition is met. In this article, we further extend Kaleidoscope to support for loops.

Table of contents.Introduction.The for expression.Lexer extensions.AST extensions.Parser extensions.LLVM IR extensions.Code generation extensions.Summary.References.Prerequisites.

LLVM Control Flow: If-then-else.

Introduction.

In the prerequisite article, we learned how to extend support for if-then-else statements...

 •  0 comments  •  flag
Share on Twitter
Published on May 09, 2022 13:35

Majority element in sorted array

In this article, we will be learning how to find the majority element in a sorted array. This involve using Linear Search, Binary Search and a constant time algorithm.

ContentsIntroduction to the ProblemInputsOutputSample Input and OutputApproaches to solve the problemApproach 1: Linear SearchCode for Approach 1OutputTime and Space Complexity of the ApproachApproach 2: Using Binary SearchCode for Approach 2OutputTime and Space Complexity of the ApproachApproach 3: O(1) ti...
 •  0 comments  •  flag
Share on Twitter
Published on May 09, 2022 12:25

May 8, 2022

Implementing JIT (Just In Time) Compilation

JIT (Just in Time) compilation involves transforming bytecode into machine executable instructions bytecode. In this article, we will implement a JIT to our Kaleidoscope interpreter.

Table of contents.Introduction.The JIT compiler.Summary.Prerequisites.LLVM Compiler optimizationsIntroduction.

A JIT(Just-In-Time) compiler is a compiler that converts bytecode into instructions that can be executed by the target machine. JIT compilers are mainly used in cases where we want to improve or o...

 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2022 13:03