mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-25 00:07:58 +00:00
add crate for custom isa extensions
Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//! Custom RISC-V extension in PolkaVM that are partially supported.
|
||||
//! We use inline assembly to emit partially supported instructions.
|
||||
|
||||
use inkwell::{context::Context, module::Module, support::LLVMString};
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bswap.rs"));
|
||||
|
||||
/// Returns a LLVM module containing a `__bswap` function, which
|
||||
/// - Takes a `i256` value argument
|
||||
/// - Byte swaps it using `rev8` from the `zbb` extension
|
||||
/// - Returns the `i256` value
|
||||
///
|
||||
/// Returns `Error` if the module fails to validate, which should never happen.
|
||||
pub fn module<'context>(
|
||||
context: &'context Context,
|
||||
module_name: &str,
|
||||
) -> Result<Module<'context>, LLVMString> {
|
||||
let module = context.create_module(module_name);
|
||||
|
||||
module.set_inline_assembly(ASSEMBLY);
|
||||
module.verify()?;
|
||||
|
||||
Ok(module)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn assembly_contains_rev8_instruction() {
|
||||
assert!(crate::ASSEMBLY.contains("rev8"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_is_valid() {
|
||||
inkwell::targets::Target::initialize_riscv(&Default::default());
|
||||
let context = inkwell::context::Context::create();
|
||||
|
||||
assert!(crate::module(&context, "polkavm_bswap").is_ok());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user