All Projects → TheDan64 → Inkwell

TheDan64 / Inkwell

Licence: apache-2.0
It's a New Kind of Wrapper for Exposing LLVM (Safely)

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Inkwell

Codegen
Experimental wrapper over LLVM for generating and compiling code at run-time.
Stars: ✭ 362 (-50.55%)
Mutual labels:  llvm, jit, codegen
Twitchio
TwitchIO - An Async Bot/API wrapper for Twitch made in Python.
Stars: ✭ 268 (-63.39%)
Mutual labels:  api, wrapper
dmr c
dmr_C is a C parser and JIT compiler with LLVM, Eclipse OMR and NanoJIT backends
Stars: ✭ 45 (-93.85%)
Mutual labels:  llvm, jit
Awesome Graal
A curated list of awesome resources for Graal, GraalVM, Truffle and related topics
Stars: ✭ 302 (-58.74%)
Mutual labels:  llvm, jit
Batch-First
A JIT compiled chess engine which traverses the search tree in batches in a best-first manner, allowing for neural network batching, asynchronous GPU use, and vectorized CPU computations.
Stars: ✭ 27 (-96.31%)
Mutual labels:  llvm, jit
jitmap
LLVM-jitted bitmaps
Stars: ✭ 25 (-96.58%)
Mutual labels:  llvm, jit
Node Zendesk
a zendesk API client library for use with node.js
Stars: ✭ 288 (-60.66%)
Mutual labels:  api, wrapper
Zenpy
Python wrapper for the Zendesk API
Stars: ✭ 222 (-69.67%)
Mutual labels:  api, wrapper
Flapigen Rs
Tool for connecting programs or libraries written in Rust with other languages
Stars: ✭ 473 (-35.38%)
Mutual labels:  wrapper, codegen
Easy Just In Time
LLVM Optimization to extract a function, embedded in its intermediate representation in the binary, and execute it using the LLVM Just-In-Time compiler.
Stars: ✭ 361 (-50.68%)
Mutual labels:  llvm, jit
adorad
Fast, Expressive, & High-Performance Programming Language for those who dare
Stars: ✭ 54 (-92.62%)
Mutual labels:  llvm, jit
Python Poloniex
Poloniex API wrapper for Python 2.7 & 3
Stars: ✭ 557 (-23.91%)
Mutual labels:  api, wrapper
vox
Vox language compiler. AOT / JIT / Linker. Zero dependencies
Stars: ✭ 288 (-60.66%)
Mutual labels:  jit, codegen
halo
😇 Wholly Adaptive LLVM Optimizer
Stars: ✭ 22 (-96.99%)
Mutual labels:  llvm, jit
FastLua
Lua trace JIT compiler using LLVM-C
Stars: ✭ 22 (-96.99%)
Mutual labels:  llvm, jit
Pycoingecko
Python wrapper for the CoinGecko API
Stars: ✭ 270 (-63.11%)
Mutual labels:  api, wrapper
Api struct
API wrapper builder with response serialization
Stars: ✭ 224 (-69.4%)
Mutual labels:  api, wrapper
Openapi Codegen
OpenAPI 3.0 CodeGen plus Node.js minus the Java and emojis
Stars: ✭ 224 (-69.4%)
Mutual labels:  api, codegen
Canvasapi
Python API wrapper for Instructure's Canvas LMS. Easily manage courses, users, gradebooks, and more.
Stars: ✭ 306 (-58.2%)
Mutual labels:  api, wrapper
Mull
Practical mutation testing tool for C and C++
Stars: ✭ 536 (-26.78%)
Mutual labels:  llvm, jit

Inkwell(s)

Crates.io Build Status codecov lines of code Join the chat at https://gitter.im/inkwell-rs/Lobby Minimum rustc 1.42

It's a New Kind of Wrapper for Exposing LLVM (Safely)

Inkwell aims to help you pen your own programming languages by safely wrapping llvm-sys. It provides a more strongly typed interface than the underlying LLVM C API so that certain types of errors can be caught at compile time instead of at LLVM's runtime. This means we are trying to replicate LLVM IR's strong typing as closely as possible. The ultimate goal is to make LLVM safer from the rust end and a bit easier to learn (via documentation) and use.

Requirements

  • Rust 1.42+
  • Rust Stable, Beta, or Nightly
  • LLVM 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, or 11.0

Usage

You'll need to point your Cargo.toml to an existing preview crate on crates.io or the master branch with a corresponding LLVM feature flag:

[dependencies]
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm11-0"] }

Supported versions:

LLVM Version Cargo Feature Flag
3.6.x llvm3-6
3.7.x llvm3-7
3.8.x llvm3-8
3.9.x llvm3-9
4.0.x llvm4-0
5.0.x llvm5-0
6.0.x llvm6-0
7.0.x llvm7-0
8.0.x llvm8-0
9.0.x llvm9-0
10.0.x llvm10-0
11.0.x llvm11-0

Please be aware that we may make breaking changes on master from time to time since we are pre-v1.0.0, in compliance with semver. Please prefer a crates.io release whenever possible!

Documentation

Documentation is automatically deployed here based on master. These docs are not yet 100% complete and only show the latest supported LLVM version due to a rustdoc issue. See #2 for more info.

Examples

Tari's llvm-sys example written in safe code1 with Inkwell:

use inkwell::OptimizationLevel;
use inkwell::builder::Builder;
use inkwell::context::Context;
use inkwell::execution_engine::{ExecutionEngine, JitFunction};
use inkwell::module::Module;
use inkwell::targets::{InitializationConfig, Target};
use std::error::Error;

/// Convenience type alias for the `sum` function.
///
/// Calling this is innately `unsafe` because there's no guarantee it doesn't
/// do `unsafe` operations internally.
type SumFunc = unsafe extern "C" fn(u64, u64, u64) -> u64;

struct CodeGen<'ctx> {
    context: &'ctx Context,
    module: Module<'ctx>,
    builder: Builder<'ctx>,
    execution_engine: ExecutionEngine<'ctx>,
}

impl<'ctx> CodeGen<'ctx> {
    fn jit_compile_sum(&self) -> Option<JitFunction<SumFunc>> {
        let i64_type = self.context.i64_type();
        let fn_type = i64_type.fn_type(&[i64_type.into(), i64_type.into(), i64_type.into()], false);
        let function = self.module.add_function("sum", fn_type, None);
        let basic_block = self.context.append_basic_block(function, "entry");

        self.builder.position_at_end(basic_block);

        let x = function.get_nth_param(0)?.into_int_value();
        let y = function.get_nth_param(1)?.into_int_value();
        let z = function.get_nth_param(2)?.into_int_value();

        let sum = self.builder.build_int_add(x, y, "sum");
        let sum = self.builder.build_int_add(sum, z, "sum");

        self.builder.build_return(Some(&sum));

        unsafe { self.execution_engine.get_function("sum").ok() }
    }
}


fn main() -> Result<(), Box<dyn Error>> {
    let context = Context::create();
    let module = context.create_module("sum");
    let execution_engine = module.create_jit_execution_engine(OptimizationLevel::None)?;
    let codegen = CodeGen {
        context: &context,
        module,
        builder: context.create_builder(),
        execution_engine,
    };

    let sum = codegen.jit_compile_sum().ok_or("Unable to JIT compile `sum`")?;

    let x = 1u64;
    let y = 2u64;
    let z = 3u64;

    unsafe {
        println!("{} + {} + {} = {}", x, y, z, sum.call(x, y, z));
        assert_eq!(sum.call(x, y, z), x + y + z);
    }

    Ok(())
}

1 There are two uses of unsafe in this example because the actual act of compiling and executing code on the fly is innately unsafe. For one, there is no way of verifying we are calling get_function() with the right function signature. It is also unsafe to call the function we get because there's no guarantee the code itself doesn't do unsafe things internally (the same reason you need unsafe when calling into C).

LLVM's Kaleidoscope Tutorial

Can be found in the examples directory.

Contributing

Check out our Contributing Guide

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].