Skip to content

Commit

Permalink
Merge 541cda2 into 6db265a
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed May 29, 2024
2 parents 6db265a + 541cda2 commit 6de0df3
Show file tree
Hide file tree
Showing 111 changed files with 2,797 additions and 1,792 deletions.
61 changes: 0 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1905,9 +1905,13 @@ pub fn compile(
if let ProgramABI::Fuel(ref mut program_abi) = program_abi {
if let Some(ref mut configurables) = program_abi.configurables {
// Filter out all dead configurables (i.e. ones without offsets in the bytecode)
configurables.retain(|c| compiled.config_const_offsets.contains_key(&c.name));
configurables.retain(|c| {
compiled
.named_data_section_entries_offsets
.contains_key(&c.name)
});
// Set the actual offsets in the JSON object
for (config, offset) in compiled.config_const_offsets {
for (config, offset) in compiled.named_data_section_entries_offsets {
if let Some(idx) = configurables.iter().position(|c| c.name == config) {
configurables[idx].offset = offset;
}
Expand Down
3 changes: 2 additions & 1 deletion forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ethabi = { package = "fuel-ethabi", version = "18.0.0" }
etk-asm = { package = "fuel-etk-asm", version = "0.3.1-dev", features = [
"backtraces",
] }
etk-dasm = { package = "fuel-etk-dasm", version = "0.3.1-dev" }
etk-ops = { package = "fuel-etk-ops", version = "0.3.1-dev" }
fuel-abi-types = { workspace = true }
fuel-vm = { workspace = true, features = ["serde"] }
Expand Down
78 changes: 34 additions & 44 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fuel_abi_types::abi::program as program_abi;
use std::collections::HashSet;

use crate::{
language::ty::{TyConstantDecl, TyFunctionDecl, TyProgram, TyProgramKind},
language::ty::{TyFunctionDecl, TyProgram, TyProgramKind},
transform::AttributesMap,
Engines, TypeId, TypeInfo, TypeParameter,
};
Expand Down Expand Up @@ -188,30 +188,26 @@ fn generate_configurables(
.program
.configurables
.iter()
.map(
|TyConstantDecl {
type_ascription, ..
}| program_abi::TypeDeclaration {
type_id: type_ascription.type_id.index(),
type_field: type_ascription.type_id.get_abi_type_str(
&ctx.to_str_context(engines, false),
engines,
type_ascription.type_id,
),
components: type_ascription.type_id.get_abi_type_components(
ctx,
engines,
types,
type_ascription.type_id,
),
type_parameters: type_ascription.type_id.get_abi_type_parameters(
ctx,
engines,
types,
type_ascription.type_id,
),
},
)
.map(|decl| program_abi::TypeDeclaration {
type_id: decl.type_ascription.type_id.index(),
type_field: decl.type_ascription.type_id.get_abi_type_str(
&ctx.to_str_context(engines, false),
engines,
decl.type_ascription.type_id,
),
components: decl.type_ascription.type_id.get_abi_type_components(
ctx,
engines,
types,
decl.type_ascription.type_id,
),
type_parameters: decl.type_ascription.type_id.get_abi_type_parameters(
ctx,
engines,
types,
decl.type_ascription.type_id,
),
})
.collect::<Vec<_>>();

// Add the new types to `types`
Expand All @@ -221,26 +217,20 @@ fn generate_configurables(
ctx.program
.configurables
.iter()
.map(
|TyConstantDecl {
call_path,
type_ascription,
..
}| program_abi::Configurable {
name: call_path.suffix.to_string(),
application: program_abi::TypeApplication {
name: "".to_string(),
type_id: type_ascription.type_id.index(),
type_arguments: type_ascription.type_id.get_abi_type_arguments(
ctx,
engines,
types,
type_ascription.type_id,
),
},
offset: 0,
.map(|decl| program_abi::Configurable {
name: decl.call_path.suffix.to_string(),
application: program_abi::TypeApplication {
name: "".to_string(),
type_id: decl.type_ascription.type_id.index(),
type_arguments: decl.type_ascription.type_id.get_abi_type_arguments(
ctx,
engines,
types,
decl.type_ascription.type_id,
),
},
)
offset: 0,
})
.collect()
}

Expand Down
25 changes: 10 additions & 15 deletions sway-core/src/asm_generation/asm_builder.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
use super::FinalizedAsm;
use crate::{asm_lang::Label, BuildConfig};
use sway_error::handler::{ErrorEmitted, Handler};
use sway_ir::Function;

use crate::asm_lang::Label;

use super::{
evm::EvmAsmBuilderResult, fuel::fuel_asm_builder::FuelAsmBuilderResult,
miden_vm::MidenVMAsmBuilderResult,
};

pub enum AsmBuilderResult {
Fuel(FuelAsmBuilderResult),
Evm(EvmAsmBuilderResult),
MidenVM(MidenVMAsmBuilderResult),
}
use sway_ir::{ConfigContent, Function};

pub trait AsmBuilder {
fn func_to_labels(&mut self, func: &Function) -> (Label, Label);
fn compile_configurable(&mut self, config: &ConfigContent);
fn compile_function(
&mut self,
handler: &Handler,
function: Function,
) -> Result<(), ErrorEmitted>;
fn finalize(&self) -> AsmBuilderResult;
fn finalize(
self,
handler: &Handler,
build_config: Option<&BuildConfig>,
fallback_fn: Option<Label>,
) -> Result<FinalizedAsm, ErrorEmitted>;
}
81 changes: 54 additions & 27 deletions sway-core/src/asm_generation/evm/evm_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::{collections::HashMap, sync::Arc};

use crate::{
asm_generation::{
asm_builder::{AsmBuilder, AsmBuilderResult},
from_ir::StateAccessType,
ProgramKind,
asm_builder::AsmBuilder, from_ir::StateAccessType, fuel::data_section::DataSection,
instruction_set::InstructionSet, FinalizedAsm, ProgramABI, ProgramKind,
},
asm_lang::Label,
metadata::MetadataManager,
Expand Down Expand Up @@ -108,28 +107,14 @@ impl<'ir, 'eng> AsmBuilder for EvmAsmBuilder<'ir, 'eng> {
self.compile_function(handler, function)
}

fn finalize(&self) -> AsmBuilderResult {
self.finalize()
}
}

#[allow(unused_variables)]
#[allow(dead_code)]
impl<'ir, 'eng> EvmAsmBuilder<'ir, 'eng> {
pub fn new(program_kind: ProgramKind, context: &'ir Context<'eng>) -> Self {
Self {
program_kind,
sections: Vec::new(),
func_label_map: HashMap::new(),
block_label_map: HashMap::new(),
context,
md_mgr: MetadataManager::default(),
label_idx: 0,
cur_section: None,
}
}
fn compile_configurable(&mut self, _config: &ConfigContent) {}

pub fn finalize(&self) -> AsmBuilderResult {
fn finalize(
self,
_handler: &Handler,
_build_config: Option<&crate::BuildConfig>,
_fallback_fn: Option<Label>,
) -> Result<FinalizedAsm, ErrorEmitted> {
let mut global_ops = Vec::new();
let mut global_abi = Vec::new();

Expand All @@ -156,11 +141,29 @@ impl<'ir, 'eng> EvmAsmBuilder<'ir, 'eng> {
ctor.ops.append(&mut global_ops);
global_abi.append(&mut ctor.abi);

AsmBuilderResult::Evm(EvmAsmBuilderResult {
let final_program = EvmFinalProgram {
ops: ctor.ops.clone(),
ops_runtime: ctor.ops,
abi: global_abi,
})
};

Ok(final_program.finalize())
}
}

#[allow(unused_variables)]
#[allow(dead_code)]
impl<'ir, 'eng> EvmAsmBuilder<'ir, 'eng> {
pub fn new(program_kind: ProgramKind, context: &'ir Context<'eng>) -> Self {
Self {
program_kind,
sections: Vec::new(),
func_label_map: HashMap::new(),
block_label_map: HashMap::new(),
context,
md_mgr: MetadataManager::default(),
label_idx: 0,
cur_section: None,
}
}

fn generate_constructor(
Expand Down Expand Up @@ -340,6 +343,7 @@ impl<'ir, 'eng> EvmAsmBuilder<'ir, 'eng> {
indices,
} => self.compile_get_elem_ptr(instr_val, base, elem_ptr_ty, indices),
InstOp::GetLocal(local_var) => self.compile_get_local(instr_val, local_var),
InstOp::GetConfig(_, name) => self.compile_get_config(instr_val, name),
InstOp::IntToPtr(val, _) => self.compile_int_to_ptr(instr_val, val),
InstOp::Load(src_val) => self.compile_load(handler, instr_val, src_val)?,
InstOp::MemCopyBytes {
Expand Down Expand Up @@ -472,6 +476,10 @@ impl<'ir, 'eng> EvmAsmBuilder<'ir, 'eng> {
todo!();
}

fn compile_get_config(&mut self, instr_val: &Value, name: &str) {
todo!();
}

fn compile_gtf(&mut self, instr_val: &Value, index: &Value, tx_field_id: u64) {
todo!();
}
Expand Down Expand Up @@ -708,3 +716,22 @@ impl<'ir, 'eng> EvmAsmBuilder<'ir, 'eng> {
})
}
}

struct EvmFinalProgram {
ops: Vec<etk_asm::ops::AbstractOp>,
abi: Vec<ethabi::operation::Operation>,
}

impl EvmFinalProgram {
fn finalize(self) -> FinalizedAsm {
FinalizedAsm {
data_section: DataSection {
..Default::default()
},
program_section: InstructionSet::Evm { ops: self.ops },
program_kind: ProgramKind::Script,
entries: vec![],
abi: Some(ProgramABI::Evm(self.abi)),
}
}
}
Loading

0 comments on commit 6de0df3

Please sign in to comment.