mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Bringing in remote trunk
This commit is contained in:
commit
a9c0185225
50 changed files with 1047 additions and 1080 deletions
|
@ -29,6 +29,7 @@ use inkwell::values::{
|
|||
};
|
||||
use inkwell::OptimizationLevel;
|
||||
use inkwell::{AddressSpace, IntPredicate};
|
||||
use roc_builtins::bitcode;
|
||||
use roc_collections::all::{ImMap, MutSet};
|
||||
use roc_module::low_level::LowLevel;
|
||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||
|
@ -50,6 +51,15 @@ pub enum OptLevel {
|
|||
Optimize,
|
||||
}
|
||||
|
||||
impl Into<OptimizationLevel> for OptLevel {
|
||||
fn into(self) -> OptimizationLevel {
|
||||
match self {
|
||||
OptLevel::Normal => OptimizationLevel::None,
|
||||
OptLevel::Optimize => OptimizationLevel::Aggressive,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq)]
|
||||
pub struct Scope<'a, 'ctx> {
|
||||
symbols: ImMap<Symbol, (Layout<'a>, PointerValue<'ctx>)>,
|
||||
|
@ -172,8 +182,9 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
|
|||
}
|
||||
|
||||
pub fn module_from_builtins<'ctx>(ctx: &'ctx Context, module_name: &str) -> Module<'ctx> {
|
||||
let memory_buffer =
|
||||
MemoryBuffer::create_from_memory_range(include_bytes!("builtins.bc"), module_name);
|
||||
let bitcode_bytes = bitcode::get_bytes();
|
||||
|
||||
let memory_buffer = MemoryBuffer::create_from_memory_range(&bitcode_bytes, module_name);
|
||||
|
||||
let module = Module::parse_bitcode_from_buffer(&memory_buffer, ctx)
|
||||
.unwrap_or_else(|err| panic!("Unable to import builtins bitcode. LLVM error: {:?}", err));
|
||||
|
|
Binary file not shown.
|
@ -28,24 +28,23 @@ impl<T: Sized> Into<Result<T, String>> for RocCallResult<T> {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! run_jit_function {
|
||||
($execution_engine: expr, $main_fn_name: expr, $ty:ty, $transform:expr) => {{
|
||||
($lib: expr, $main_fn_name: expr, $ty:ty, $transform:expr) => {{
|
||||
let v: std::vec::Vec<roc_problem::can::Problem> = std::vec::Vec::new();
|
||||
run_jit_function!($execution_engine, $main_fn_name, $ty, $transform, v)
|
||||
run_jit_function!($lib, $main_fn_name, $ty, $transform, v)
|
||||
}};
|
||||
|
||||
($execution_engine: expr, $main_fn_name: expr, $ty:ty, $transform:expr, $errors:expr) => {{
|
||||
($lib: expr, $main_fn_name: expr, $ty:ty, $transform:expr, $errors:expr) => {{
|
||||
use inkwell::context::Context;
|
||||
use inkwell::execution_engine::JitFunction;
|
||||
use roc_gen::run_roc::RocCallResult;
|
||||
|
||||
unsafe {
|
||||
let main: JitFunction<unsafe extern "C" fn() -> RocCallResult<$ty>> = $execution_engine
|
||||
.get_function($main_fn_name)
|
||||
let main: libloading::Symbol<unsafe extern "C" fn() -> RocCallResult<$ty>> = $lib
|
||||
.get($main_fn_name.as_bytes())
|
||||
.ok()
|
||||
.ok_or(format!("Unable to JIT compile `{}`", $main_fn_name))
|
||||
.expect("errored");
|
||||
|
||||
match main.call().into() {
|
||||
match main().into() {
|
||||
Ok(success) => {
|
||||
// only if there are no exceptions thrown, check for errors
|
||||
assert_eq!(
|
||||
|
@ -68,26 +67,25 @@ macro_rules! run_jit_function {
|
|||
/// It explicitly allocates a buffer that the roc main function can write its result into.
|
||||
#[macro_export]
|
||||
macro_rules! run_jit_function_dynamic_type {
|
||||
($execution_engine: expr, $main_fn_name: expr, $bytes:expr, $transform:expr) => {{
|
||||
($lib: expr, $main_fn_name: expr, $bytes:expr, $transform:expr) => {{
|
||||
let v: std::vec::Vec<roc_problem::can::Problem> = std::vec::Vec::new();
|
||||
run_jit_function_dynamic_type!($execution_engine, $main_fn_name, $bytes, $transform, v)
|
||||
run_jit_function_dynamic_type!($lib, $main_fn_name, $bytes, $transform, v)
|
||||
}};
|
||||
|
||||
($execution_engine: expr, $main_fn_name: expr, $bytes:expr, $transform:expr, $errors:expr) => {{
|
||||
($lib: expr, $main_fn_name: expr, $bytes:expr, $transform:expr, $errors:expr) => {{
|
||||
use inkwell::context::Context;
|
||||
use inkwell::execution_engine::JitFunction;
|
||||
use roc_gen::run_roc::RocCallResult;
|
||||
|
||||
unsafe {
|
||||
let main: JitFunction<unsafe extern "C" fn(*const u8)> = $execution_engine
|
||||
.get_function($main_fn_name)
|
||||
let main: libloading::Symbol<unsafe extern "C" fn(*const u8)> = $lib
|
||||
.get($main_fn_name.as_bytes())
|
||||
.ok()
|
||||
.ok_or(format!("Unable to JIT compile `{}`", $main_fn_name))
|
||||
.expect("errored");
|
||||
|
||||
let layout = std::alloc::Layout::array::<u8>($bytes).unwrap();
|
||||
let result = std::alloc::alloc(layout);
|
||||
main.call(result);
|
||||
main(result);
|
||||
|
||||
let flag = *result;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue