This repo contains the source code for a simple toy programming language written in C++23. The goal of this project is to study and understand how Sea of Nodes (SoN) can be used as an alternative to SSA for intermediate representation. Compilation goes through the following steps:
Source code > Lexing > (Parsing + SoN generation + peephole/optimizing SoN) > Dead code eliminationHere is a list of the passes implemented in the peephole stage so far:
- Constant folding for the following nodes:
- arithmetic:
+,-,*,/ - bit logic:
&,^,| - unary:
-const(x)toconst(-x) - identity comparisons:
a == atotrue,a != atofalse, same thing for<,<=,>,>=
- arithmetic:
- Strength reduction:
a + ais transformed intoa * 2
- Memory reordering:
- Two consecutive reads can be computed independently and reordered as needed
- A read/write can be parallel to another write as long as they both do not touch the same location and index
- A C++23 compiler that supports
std::printandstatic operator(). - CMake 3.25 or later.
- vcpkg to manage project dependencies. Make sure to set the
VCPKG_ROOTenvironment variable as described in the official docs.
mkdir build
cd build
# This is on Windows, depending on the OS/shell replace %VCPKG_ROOT% with how you access an environment variable
cmake .. -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake
cmake --build .