llvm-context: remove the linear memory pointer indirection (#211)

This commit is contained in:
xermicus
2025-02-13 13:21:43 +01:00
committed by GitHub
parent f3a86588f3
commit cb268850a9
8 changed files with 74 additions and 68 deletions
+3 -7
View File
@@ -8,10 +8,10 @@
#define EVM_WORD_SIZE 32
#define ALIGN(size) ((size + EVM_WORD_SIZE - 1) & ~(EVM_WORD_SIZE - 1))
#define MAX_MEMORY_SIZE (64 * 1024)
static char __memory[MAX_MEMORY_SIZE];
static uint32_t __memory_size = 0;
char __memory[MAX_MEMORY_SIZE];
uint32_t __memory_size = 0;
void * __sbrk_internal(uint32_t offset, uint32_t size) {
void * __sbrk_internal(uint32_t offset, uint32_t size) {
if (offset >= MAX_MEMORY_SIZE || size > MAX_MEMORY_SIZE) {
return NULL;
}
@@ -27,10 +27,6 @@ void * __sbrk_internal(uint32_t offset, uint32_t size) {
return (void *)&__memory[__memory_size];
}
uint32_t __msize() {
return __memory_size;
}
void * memset(void *b, int c, size_t len) {
uint8_t *dest = b;
while (len-- > 0) *dest++ = c;
+7 -12
View File
@@ -1,18 +1,14 @@
//! This crate vendors the [PolkaVM][0] C API and provides a LLVM module for interacting
//! with the `pallet-revive` runtime API.
//! At present, the revive pallet requires blobs to export `call` and `deploy`,
//! and offers a bunch of [runtime API methods][1]. The provided [module] implements
//! those exports and imports.
//! [0]: [https://crates.io/crates/polkavm]
//! [1]: [https://docs.rs/pallet-contracts/26.0.0/pallet_contracts/api_doc/index.html]
use inkwell::{context::Context, memory_buffer::MemoryBuffer, module::Module, support::LLVMString};
include!(concat!(env!("OUT_DIR"), "/polkavm_imports.rs"));
pub static SBRK: &str = "__sbrk_internal";
/// The emulated EVM heap memory global symbol.
pub static MEMORY: &str = "__memory";
pub static MEMORY_SIZE: &str = "__msize";
/// The emulated EVM heap memory size global symbol.
pub static MEMORY_SIZE: &str = "__memory_size";
pub static SBRK: &str = "__sbrk_internal";
pub static ADDRESS: &str = "address";
@@ -82,9 +78,8 @@ pub static WEIGHT_TO_FEE: &str = "weight_to_fee";
/// All imported runtime API symbols.
/// Useful for configuring common attributes and linkage.
pub static IMPORTS: [&str; 35] = [
pub static IMPORTS: [&str; 34] = [
SBRK,
MEMORY_SIZE,
ADDRESS,
BALANCE,
BALANCE_OF,