slang-project / SLang-Codegen-LLVM

The LLVM-based backend (code generator) for the SLang programming language compiler
3 stars 0 forks source link
compiler compiler-backend compiler-construction llvm slang

SLang-Codegen-LLVM

Overview

This project is an implementation of the SLang programming language compiler backend using LLVM. You may find an old implementation on the branch v0.1.3.

How to install dependencies and build project

This project is based on CMake. In order to build it, you need to install dependencies and then build the project.

Also consider installation of clang-format and clang-tidy tools to conform to project's coding standard. The version used as of the writing of this manual is 13.0.0.

You can run the corresponding check using CMake targets Format and Tidy.

To run all the unit tests you can use target test, building target SlangCompilerLlvmCodegenUnitTests beforehand.

Visual Studio Code

Cross-platform universal solution for development for this project is to use the Visual Studio Code.

Please, consider installing all recommended extensions for this workspace and take care of the dependencies based on the instructions below.

If considering vcpkg, then you should have properly set VCPKG_ROOT environment variable prior opening project folder. Otherwise, feel free to ignore vcpkg configuration and remove all settings that require the presence of it (for example, CMAKE_TOOLCHAIN_FILE in cmake.configureSettings)

UNIX

After cloning the project, run the tool that installs the vcpkg and sets a global environment variable with a path to it:

tools/install_vcpkg.sh

By default, it installs vcpkg in a folder near project's folder. You may customise this behaviour by providing the install path by your own. You are strongly advised to not install it in any of the project folder or subfolders.

tools/install_vcpkg.sh path/to/vcpkg

As an alternative, you can install all the required dependencies by yourself. Use vcpkg.json and Dockerfile for hints on what you may need to install.

This method is not advised since it introduces inconsistency into project development.

Windows

You are advised to set this option before cloning this project to not make you editor go mad.

git config --global core.autocrlf input

You will also need to have vcpkg package manager installed:

REM Put vcpkg out of project scope
cd ..

REM If fails, remove `/m` option to setup variable just for a user
SETX VCPKG_ROOT "%cd%\vcpkg" /m

git clone https://github.com/microsoft/vcpkg %VCPKG_ROOT%
%VCPKG_ROOT%\bootstrap-vcpkg.bat
%VCPKG_ROOT%\vcpkg integrate install

Visual Studio

Instead of VS Code you may want to work in Visual Studio, which is also supported.

You are advised to use 2019 edition and later with the following individual components installed:

Open this project's folder as a CMake project.

Don't forget to setup command line arguments for debug:

Docker

The project is packed into reproducible build environment with Docker. You may use Dockerfile provided to build your own image to work with project. We are considering publishing the resulting image with dependencies somewhere for quick start on a project.

The following example may be helpful in getting started, but you still need to get Docker by yourself (Ubuntu instruction):

docker build --target install-vcpkg --network "host" -t slang-project/slang-codegen-llvm-deps:0.2.1 .
docker build --cache-from slang-project/slang-codegen-llvm-deps:0.2.1 --network "host" -t slang-project/slang-codegen-llvm:0.2.1 .
docker run --rm slang-project/slang-codegen-llvm:0.2.1 path/to/in.json

How to run project

build/app/SlangCompilerLlvmCodegenDriver path/to/in.slangir