Skip to content

Commit

Permalink
Refactor for support of multiple targets (#16)
Browse files Browse the repository at this point in the history
Initial support of the EVM target (#9)
  • Loading branch information
hedgar2017 authored Mar 6, 2024
1 parent 0dc0215 commit f1ae37a
Show file tree
Hide file tree
Showing 92 changed files with 5,770 additions and 1,195 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-commo
git = "https://github.com/matter-labs-forks/inkwell"
branch = "llvm-15"
default-features = false
features = ["llvm15-0", "no-libffi-linking", "target-eravm"]
features = ["llvm15-0", "no-libffi-linking", "target-eravm", "target-evm"]
6 changes: 6 additions & 0 deletions src/const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//!
//! The LLVM context constants.
//!

/// The LLVM framework version.
pub const LLVM_VERSION: semver::Version = semver::Version::new(15, 0, 4);
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//! The LLVM function block EVM legacy assembly data.
//!

pub mod key;

///
/// The LLVM function block EVM legacy assembly data.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! The LLVM IR generator function block key.
//!

use crate::eravm::context::code_type::CodeType;
use crate::context::code_type::CodeType;

///
/// The LLVM IR generator function block key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//!

pub mod evmla_data;
pub mod key;

use self::evmla_data::EVMLAData;

Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions src/context/function/evmla_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//!
//! The LLVM function EVM legacy assembly data.
//!

use std::collections::BTreeMap;

use crate::context::function::block::key::Key as BlockKey;
use crate::context::function::block::Block;

///
/// The LLVM function EVM legacy assembly data.
///
/// Describes some data that is only relevant to the EVM legacy assembly.
///
#[derive(Debug)]
pub struct EVMLAData<'ctx> {
/// The ordinary blocks with numeric tags.
/// Is only used by the Solidity EVM compiler.
pub blocks: BTreeMap<BlockKey, Vec<Block<'ctx>>>,
/// The function stack size.
pub stack_size: usize,
}

impl<'ctx> EVMLAData<'ctx> {
///
/// A shortcut constructor.
///
pub fn new(stack_size: usize) -> Self {
Self {
blocks: BTreeMap::new(),
stack_size,
}
}

///
/// Inserts a function block.
///
pub fn insert_block(&mut self, key: BlockKey, block: Block<'ctx>) {
if let Some(blocks) = self.blocks.get_mut(&key) {
blocks.push(block);
} else {
self.blocks.insert(key, vec![block]);
}
}
}
8 changes: 8 additions & 0 deletions src/context/function/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//!
//! The common LLVM function entities.
//!

pub mod block;
pub mod declaration;
pub mod evmla_data;
pub mod r#return;
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,50 @@
//! The LLVM IR generator function return entity.
//!

use crate::eravm::context::pointer::Pointer;
use crate::context::pointer::Pointer;
use crate::context::traits::address_space::IAddressSpace;

///
/// The LLVM IR generator function return entity.
///
#[derive(Debug, Clone, Copy)]
pub enum Return<'ctx> {
pub enum Return<'ctx, AS>
where
AS: IAddressSpace
+ Clone
+ Copy
+ PartialEq
+ Eq
+ Into<inkwell::AddressSpace>
+ std::fmt::Debug,
{
/// The function does not return a value.
None,
/// The function returns a primitive value.
Primitive {
/// The primitive value pointer allocated at the function entry.
pointer: Pointer<'ctx>,
pointer: Pointer<'ctx, AS>,
},
/// The function returns a compound value.
/// In this case, the return pointer is allocated on the stack by the callee.
Compound {
/// The structure pointer allocated at the function entry.
pointer: Pointer<'ctx>,
pointer: Pointer<'ctx, AS>,
/// The function return type size.
size: usize,
},
}

impl<'ctx> Return<'ctx> {
impl<'ctx, AS> Return<'ctx, AS>
where
AS: IAddressSpace
+ Clone
+ Copy
+ PartialEq
+ Eq
+ Into<inkwell::AddressSpace>
+ std::fmt::Debug,
{
///
/// A shortcut constructor.
///
Expand All @@ -37,21 +56,21 @@ impl<'ctx> Return<'ctx> {
///
/// A shortcut constructor.
///
pub fn primitive(pointer: Pointer<'ctx>) -> Self {
pub fn primitive(pointer: Pointer<'ctx, AS>) -> Self {
Self::Primitive { pointer }
}

///
/// A shortcut constructor.
///
pub fn compound(pointer: Pointer<'ctx>, size: usize) -> Self {
pub fn compound(pointer: Pointer<'ctx, AS>, size: usize) -> Self {
Self::Compound { pointer, size }
}

///
/// Returns the pointer to the function return value.
///
pub fn return_pointer(&self) -> Option<Pointer<'ctx>> {
pub fn return_pointer(&self) -> Option<Pointer<'ctx, AS>> {
match self {
Return::None => None,
Return::Primitive { pointer } => Some(pointer.to_owned()),
Expand Down
File renamed without changes.
Loading

0 comments on commit f1ae37a

Please sign in to comment.