Wednesday, June 25, 2025

Dynamic Memory Allocation

I made a Linux C Compiler. It is a software compiler, it compiles C code into GAS assembly language.

I followed ISO C17 standard to make the compiler following the rules of the standard.

I also followed system V ABI calling conventions. You can call other libraries compiled with other compilers and call them in your code.

I also followed Intel x64 ISA for writing assembly code.

It has dynamic memory allocation. You can use malloc, free, calloc, realloc in your programs and the compiler will handle void pointers and void types.

The compiler supports static memory allocation, automatic memory allocation and dynamic memory allocation.

I tested my compiler against C tests for making sure it works, the testing is incremental so it works with past tests as well.

If you want to look at the code:

Wednesday, June 11, 2025

Testing my compiler against Test Suite of compiling C tests

I added Multidimensional Arrays in C and Pointers to my Compiler. I added Subscripting, pointer arithmetic, Derefencing and Addressing, Compound Initializers and Static Arrays.

I tested the Compiler against C tests for validating correct assembly code.

The tests run from the beginning to the end, so every feature is tested and validated.


This is one of the tests of the compiler, pointer difference validation:

This is the final assembly language file, it is real x86 code and when it runs it produces correct results.

If you want to look at the code:

Compiler Code




Friday, May 30, 2025

Code Generation of Floating point numbers

I made a Code Generator, The code generator supports floating point numbers. 

I used SSE2 instructions for generating assembly code for instructions that use doubles.


It translates from the Intermediate Representation into assembly for x86 architectures.

I also kept System V Calling conventions. In this way I can call functions from the math.h library and they work.


The code generator supports type conversions between floating point numbers and integers.

If you want to look at the code:

Compiler Code



Sunday, May 25, 2025

Type System Part 2

I made a Type System for C in Python. It has unsigned integers and signed integers (longs and ints).


It has a symbol table that is generated at type checking pass and it has a constant propagation system. The static type checker looks for and annotates all the types in expressions. Checks for errors.

In assembly all the types are converted to assembly types for x86, and instructions are selected for each type.

If you want to look at the code:


Tuesday, May 13, 2025

Type System

I added a Type System to my C Compiler. It has support for adding multiple types to the compiler and make static type checking.

I added support for long integer types. 

Type conversions between longs and ints, It converts implicit casts into explicit casts.

It annotates each expression with its corresponding return type and uses it to know the corresponding intermediate representation.

In the back end I added support for multiple operand sizes.

If you want to look at the code:

Compiler Code


Tuesday, April 29, 2025

Semantic Analysis

I added Semantic Analysis to my C compiler. The pass has variable resolution and loop labeling. 

In variable resolution the compiler resolves each variable with unique identifiers where needed.

In Loop Labeling each break or continue statement is labeled with its corresponding loop. so we can generate TAC code to the end of the loop.

It also checks for errors in invalid lvalues, non declared variables and doubly defined variables.

It works after the parser but before the TAC Generator.

The compiler supports for Loops, while Loops, Ifs and Conditional Expressions:

If you want to look at the code:

C Compiler Code


Tuesday, April 22, 2025

C Compiler

I made a C Compiler in Python.

These are the compiler passes I made for the compiler:


I used GCC for preprocessing and assembling in Linux.

The compiler outputs assembly GCC GAS assembler.

The compiler has multiple passes. It has an intermediate representation TAC (Three Address Code).

In that way it can support mulitple frontends and multiple bakends.

I made the TAC AST, the parser AST, the assembly AST and I fixed up instructions in assembly.

This is the output of the compiler:


I debugged the assembly code in GDB.


If you want to look at the code: