Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ CARGO_BIN_EXE_SOLX = { value = "./target/debug/solx", relative = true, force = f

[alias]
test-slang = "test -p solx-slang -p solx-mlir -p solx --no-default-features --features slang"
build-mlir = "build -p solx --features mlir"
test-mlir = "test -p solx --features mlir"
69 changes: 48 additions & 21 deletions solx-core/src/build/contract/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,48 +60,75 @@ impl Object {
pub const LIBRARY_PLACEHOLDER_LENGTH: usize = 17;

///
/// A shortcut constructor.
/// Creates a passthrough object from pre-assembled bytecode hex.
///
pub fn new(
/// Used when solc produces final bytecode directly (e.g. MLIR passthrough mode).
///
pub fn new_passthrough(
identifier: String,
contract_name: solx_utils::ContractName,
assembly: Option<String>,
bytecode: Option<Vec<u8>>,
debug_info: Option<Vec<u8>>,
evmla: Option<String>,
ethir: Option<String>,
llvm_ir_unoptimized: Option<String>,
llvm_ir: Option<String>,
code_segment: solx_utils::CodeSegment,
bytecode_hex: String,
) -> Self {
Self {
identifier: identifier.clone(),
contract_name,
assembly: None,
bytecode: None,
bytecode_hex: Some(bytecode_hex),
debug_info: None,
evmla: None,
ethir: None,
llvm_ir_unoptimized: None,
llvm_ir: None,
via_ir: false,
code_segment,
immutables: None,
metadata_bytes: None,
dependencies: solx_codegen_evm::Dependencies::new(identifier.as_str()),
unlinked_symbols: BTreeMap::new(),
is_assembled: true,
is_size_fallback: false,
warnings: Vec::new(),
benchmarks: Vec::new(),
}
}

///
/// Creates an object from a codegen build result.
///
pub fn from_build(
identifier: String,
contract_name: solx_utils::ContractName,
build: solx_codegen_evm::Build,
via_ir: bool,
code_segment: solx_utils::CodeSegment,
immutables: Option<BTreeMap<String, BTreeSet<u64>>>,
metadata_bytes: Option<Vec<u8>>,
dependencies: solx_codegen_evm::Dependencies,
is_size_fallback: bool,
warnings: Vec<solx_codegen_evm::Warning>,
benchmarks: Vec<(String, u64)>,
) -> Self {
let bytecode_hex = bytecode.as_ref().map(hex::encode);
let bytecode_hex = build.bytecode.as_ref().map(hex::encode);
Self {
identifier,
contract_name,
assembly,
bytecode,
assembly: build.assembly,
bytecode: build.bytecode,
bytecode_hex,
debug_info,
evmla,
ethir,
llvm_ir_unoptimized,
llvm_ir,
debug_info: build.debug_info,
evmla: build.evmla,
ethir: build.ethir,
llvm_ir_unoptimized: build.llvm_ir_unoptimized,
llvm_ir: build.llvm_ir,
via_ir,
code_segment,
immutables,
metadata_bytes,
dependencies,
unlinked_symbols: BTreeMap::new(),
is_assembled: false,
is_size_fallback,
warnings,
is_size_fallback: build.is_size_fallback,
warnings: build.warnings,
benchmarks,
}
}
Expand Down
88 changes: 88 additions & 0 deletions solx-core/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,94 @@ impl Build {
}
}

///
/// Creates a build directly from solc standard JSON output.
///
/// Used in MLIR passthrough mode where solc produces final bytecode.
///
#[cfg(all(feature = "solc", feature = "mlir"))]
pub fn from_solc_output(
solc_output: solx_standard_json::Output,
messages: Arc<Mutex<Vec<solx_standard_json::OutputError>>>,
) -> Self {
let mut contracts = BTreeMap::new();

for (path, file_contracts) in solc_output.contracts.into_iter() {
for (name, solc_contract) in file_contracts.into_iter() {
let contract_name = solx_utils::ContractName::new(path.clone(), Some(name));

let (
deploy_bytecode_hex,
runtime_bytecode_hex,
method_identifiers,
legacy_assembly,
) = match solc_contract.evm {
Some(evm) => (
evm.bytecode.and_then(|bytecode| bytecode.object),
evm.deployed_bytecode.and_then(|bytecode| bytecode.object),
evm.method_identifiers,
evm.legacy_assembly,
),
None => (None, None, None, None),
};

let deploy_object = deploy_bytecode_hex.map(|hex| {
ContractObject::new_passthrough(
contract_name.full_path.clone(),
contract_name.clone(),
solx_utils::CodeSegment::Deploy,
hex,
)
});

let runtime_object = runtime_bytecode_hex.map(|hex| {
let runtime_identifier = format!(
"{}.{}",
contract_name.full_path,
solx_utils::CodeSegment::Runtime
);
ContractObject::new_passthrough(
runtime_identifier,
contract_name.clone(),
solx_utils::CodeSegment::Runtime,
hex,
)
});

let contract = Contract::new(
contract_name,
deploy_object.map(Ok),
runtime_object.map(Ok),
solc_contract.metadata,
solc_contract.abi,
method_identifiers,
solc_contract.userdoc,
solc_contract.devdoc,
solc_contract.storage_layout,
solc_contract.transient_storage_layout,
legacy_assembly,
solc_contract.ir,
);

contracts.insert(contract.name.full_path.clone(), contract);
}
}

let ast_jsons = if solc_output.sources.is_empty() {
None
} else {
Some(
solc_output
.sources
.into_iter()
.map(|(path, source)| (path, source.ast))
.collect(),
)
};

Self::new(contracts, ast_jsons, messages)
}

///
/// Links the EVM build.
///
Expand Down
Loading
Loading