Files
revive/crates/stdlib/src/lib.rs
T
Cyrill Leutwiler cffa14a4d2 Emerge Yul recompiler (#1)
Provide a modified (and incomplete) version of ZKSync zksolc that can compile the most basic contracts
2024-03-12 12:06:02 +01:00

37 lines
1.2 KiB
Rust

//! This crate vendors EVM related standard library functionality and provides a LLVM module,
//! exporting the standard library functions.
//!
//! The standard library code is inherited and adapted from [0].
//!
//! [0]: [https://github.com/matter-labs/era-compiler-llvm/blob/v1.4.1/llvm/lib/Target/EraVM/eravm-stdlib.ll]
//!
use inkwell::{context::Context, memory_buffer::MemoryBuffer, module::Module, support::LLVMString};
include!(concat!(env!("OUT_DIR"), "/stdlib.rs"));
/// Creates a LLVM module from [BITCODE].
///
/// The module exports a bunch of EVM related "stdlib" functions.
///
/// Returns `Error` if the bitcode fails to parse, which should never happen.
pub fn module<'context>(
context: &'context Context,
module_name: &str,
) -> Result<Module<'context>, LLVMString> {
let buf = MemoryBuffer::create_from_memory_range(BITCODE, module_name);
Module::parse_bitcode_from_buffer(&buf, context)
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
inkwell::targets::Target::initialize_riscv(&Default::default());
let context = inkwell::context::Context::create();
let module = crate::module(&context, "stdlib").unwrap();
assert!(module.get_function("__signextend").is_some());
}
}