custom ir

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Cyrill Leutwiler
2024-02-02 09:10:03 +01:00
parent 7a094f17c0
commit d238d8f39e
48 changed files with 4399 additions and 603 deletions
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "revive-compilation-target"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
inkwell = { workspace = true }
@@ -0,0 +1,15 @@
use inkwell::{builder::Builder, module::Module, values::FunctionValue};
/// [Environment] describes EVM runtime functionality.
pub trait Environment<'ctx> {
const STACK_SIZE: u32 = 1024 * 32;
const CALLDATA_SIZE: u32 = 0x10000;
const RETURNDATA_SIZE: u32 = 0x10000;
const MEMORY_SIZE: u32 = 0x100000;
/// Build a module containing all required runtime exports and imports.
///
/// The `start` function is the entrypoint to the contract logic.
/// The returned `Module` is expected to call `start` somewhere.
fn call_start(&'ctx self, builder: &Builder<'ctx>, start: FunctionValue<'ctx>) -> Module<'ctx>;
}
+2
View File
@@ -0,0 +1,2 @@
pub mod environment;
pub mod target;
+27
View File
@@ -0,0 +1,27 @@
use inkwell::{
context::Context,
module::Module,
targets::{CodeModel, RelocMode},
OptimizationLevel,
};
pub trait Target<'ctx> {
const TARGET_NAME: &'ctx str;
const TARGET_TRIPLE: &'ctx str;
const TARGET_FEATURES: &'ctx str;
const CPU: &'ctx str;
const RELOC_MODE: RelocMode = RelocMode::Default;
const CODE_MODEL: CodeModel = CodeModel::Default;
fn initialize_llvm() {
inkwell::targets::Target::initialize_riscv(&Default::default());
}
fn context(&self) -> &Context;
fn libraries(&'ctx self) -> Vec<Module<'ctx>>;
fn link(&self, blob: &[u8]) -> Vec<u8>;
fn optimization_level(&self) -> OptimizationLevel;
}