Giter VIP home page Giter VIP logo

kaleidoscope17's Introduction

kaleidoscope17

Kaleidoscope17 is an implementation of Kaleidoscope in LLVM tutorial.
This project tries to rewrite the original Kaleidoscope with modern C++17.
Now, this project only covers until chapter "3. Kaleidoscope: Code generation to LLVM IR".
So, this currently cannot execute given codes.

Requirements

  • LLVM (>= 7.0)
  • cmake (>= 3.8)
  • python (>= 3.6)

Usage

kaleidoscope17 provides two types of interface: interpreter, source code file.

Interpreter

You just can access the interpreter interface by running the binary without any argument.
The following example shows a case when we define an add function there.

>> ./kaleidoscope17
>> Kaleidoscope >> def f(a, b) a + b;
parsed a function definition.

-- parsed result
FunctionAST{PrototypeAST{f(a, b)}BinaryExprAST(VarExprAST(a) + VarExprAST(b))}

-- generated LLVM IR

define double @f(double %a, double %b) {
entry:
  %add_f = fadd double %a, %b
  ret double %add_f
}

Source code file

You also can use this compiler with your source code files.
If you take the keyword "debug" additionally, you can see the parsed result and the generated LLVM IR from your code.

# the given line in this source code is
# def g(v, u) v - g(u, 4.0);

-- parsed result
FunctionAST{PrototypeAST{g(v, u)}BinaryExprAST(VarExprAST(v) - CallExprAST{g(VarExprAST(u), NumExprAST(4))})}

-- generated LLVM IR

define double @g(double %v, double %u) {
entry:
  %call_f = call double @g(double %u, double 4.000000e+00)
  %sub_f = fsub double %v, %call_f
  ret double %sub_f
}

Build

You can build this project with cmake. Here is an example.

mkdir build
cd build

# this example uses Ninja as the generator but of course
# you can choose normal "Unix Makefiles" instead.
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH={path-to-install-llvm} ..
ninja all

# run tests this will call python script inside
ctest

This project is going to require LLVM (not yet), therefore you need to specify the installed directory by setting CMAKE_PREFIX_PATH to cmake.
if you need the detailed, please check the official guide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.