Giter VIP home page Giter VIP logo

tiny_jit's Introduction

Small and fast JIT/AOT compiler with zero dependencies

Project/language name is still missing.

Project goals

Strong focus on application extensions

  • Maximize user productivity
    • Static typing
    • Great error messages
    • Fast / Incremental compilation
    • Minimize effort needed for installation, setup, integration
      • Minimal dependencies/encapsulate dependency into module or package
      • Runtime as a library/minimal runtime/no runtime
      • Embedding/extern C
      • Code driven compilation, extending compiler from inside of the program being compiled
    • Runtime module loading/runtime module compilation
    • AOT and JIT, plugin support, runtime compilation, embedded compiler, tiered compilation
  • Maximize application performance
    • Static typing

Target platforms:

  • amd64 (Windows, Linux, MacOS)
  • WebAssembly (browsers)
  • ARM (Android, Linux)
  • SPIR-V (Vulkan/OpenCL/OpenGL Шейдеры)

Compiler

Passes

  • Parsing - produces AST
  • Semantic insert - Fills scopes with identifiers
  • Semantic lookup - Resolves symbol references
  • Semantic types - Type checking
  • IR gen - Conversion of AST into linear IR in SSA form
  • Optimization - optimizes machine independent IR
  • IR to LIR - Conversion of high level IR to machine code IR in SSA form (LIR)
  • Live intervals - Collects liveness info about values for use in register allocation
  • Linear Scan Register Allocation - Replaces virtual registers with physical ones
  • Stack layout - Calculates offsets for stack slots
  • Code gen - Converts LIR into machine code

Source code

source directory content:

  • compiler1.d - current implementation/tests. Single file.
  • amd64asm.d - instruction encoding for amd64 architecture.
  • pecoff.d - loading of .lib, .obj files. Generation of .exe files. Linking utilities. Dumping utilities. Works with files in PE/COFF format.
  • ir_test.d - implementation of SSA IR construction algorithm.
  • tinyc.d - port of tinyc compiler/VM from C to D.
  • phi_resolution.d - SSA deconstruction algorithm.
  • /lang - old implementation of compiler. Lacks newer features, but has function calls and loops working.
  • /asmtest - tests for instruction encodings.
  • /ir - IR specific stuff.

What works

  • You can use code in compiler1.d as JIT compiler for amd64:
string source = q{
    void test(i32* array, i32 index, i32 value) {
        array[index] = value;
    }
};

// Error handling is omitted
Driver driver;
driver.initPasses();
ubyte[] codeBuffer = alloc_executable_memory(PAGE_SIZE * 8);

ModuleDeclNode* mod = driver.compileModule(source, codeBuffer);
FunctionDeclNode* funDecl = mod.findFunction("test", &driver.context);
alias FuncT = extern(C) void function(int*, int, int);
FuncT fun = cast(FuncT)funDecl.irData.funcPtr;

int[2] val = [42, 56];
fun(val.ptr, 1, 10);
assert(val[1] == 10);
  • Executable generation:

Roadmap

  • Finish code gen for function calls.
  • Add LIR (Lowlevel IR)
  • Implement loops.
  • Integrate code for executable generation in main code.
  • Add a way for binding with DLLs in a language. DLL import tables are already implemented by pecoff.d file.
  • Link with SDL library
  • Make standalone compiler: read files from disk, write executable.
  • Make a game with SDL
  • Implement modding system

tiny_jit's People

Contributors

mrsmith33 avatar m4gnv5 avatar

Watchers

James Cloos avatar  avatar  avatar

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.