Skip to content

Commit

Permalink
fix: include legacyAssembly output
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Sep 30, 2024
1 parent dd4fd70 commit b06e805
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/artifacts/solc/src/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct ConfigurableContractArtifact {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub assembly: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub legacy_assembly: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub opcodes: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub method_identifiers: Option<BTreeMap<String, String>>,
Expand Down
48 changes: 47 additions & 1 deletion crates/compilers/src/artifact_output/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl ConfigurableArtifacts {
storage_layout,
transient_storage_layout,
assembly,
legacy_assembly,
gas_estimates,
metadata,
ir,
Expand Down Expand Up @@ -133,6 +134,9 @@ impl ConfigurableArtifacts {
if assembly || self.additional_files.assembly {
selection.push(EvmOutputSelection::Assembly.into());
}
if legacy_assembly || self.additional_files.legacy_assembly {
selection.push(EvmOutputSelection::LegacyAssembly.into());
}
if ewasm || self.additional_files.ewasm {
selection.push(EwasmOutputSelection::All.into());
}
Expand Down Expand Up @@ -207,6 +211,7 @@ impl ArtifactOutput for ConfigurableArtifacts {
let mut artifact_function_debug_data = None;
let mut artifact_method_identifiers = None;
let mut artifact_assembly = None;
let mut artifact_legacy_assembly = None;
let mut artifact_storage_layout = None;
let mut artifact_transient_storage_layout = None;
let mut generated_sources = None;
Expand Down Expand Up @@ -264,7 +269,7 @@ impl ArtifactOutput for ConfigurableArtifacts {
deployed_bytecode,
method_identifiers,
gas_estimates,
legacy_assembly: _,
legacy_assembly,
} = evm;

if self.additional_values.function_debug_data {
Expand All @@ -290,13 +295,18 @@ impl ArtifactOutput for ConfigurableArtifacts {
if self.additional_values.assembly {
artifact_assembly = assembly;
}

if self.additional_values.legacy_assembly {
artifact_legacy_assembly = legacy_assembly;
}
}

ConfigurableContractArtifact {
abi,
bytecode: artifact_bytecode,
deployed_bytecode: artifact_deployed_bytecode,
assembly: artifact_assembly,
legacy_assembly: artifact_legacy_assembly,
opcodes,
function_debug_data: artifact_function_debug_data,
method_identifiers: artifact_method_identifiers,
Expand Down Expand Up @@ -343,6 +353,7 @@ impl ArtifactOutput for ConfigurableArtifacts {
ir_optimized,
ewasm,
assembly,
legacy_assembly,
source_map,
generated_sources,
bytecode: _,
Expand All @@ -365,6 +376,12 @@ impl ArtifactOutput for ConfigurableArtifacts {
if assembly && artifact.assembly.is_none() {
return Ok(true);
}
if assembly && artifact.assembly.is_none() {
return Ok(true);
}
if legacy_assembly && artifact.legacy_assembly.is_none() {
return Ok(true);
}
if source_map && artifact.get_source_map_str().is_none() {
return Ok(true);
}
Expand All @@ -387,6 +404,8 @@ impl ArtifactOutput for ConfigurableArtifacts {
let artifact = &artifact_file.artifact;
self.additional_files.process_abi(artifact.abi.as_ref(), file)?;
self.additional_files.process_assembly(artifact.assembly.as_deref(), file)?;
self.additional_files
.process_legacy_assembly(artifact.legacy_assembly.clone(), file)?;
self.additional_files
.process_bytecode(artifact.bytecode.as_ref().map(|b| &b.object), file)?;
self.additional_files.process_deployed_bytecode(
Expand Down Expand Up @@ -424,6 +443,7 @@ pub struct ExtraOutputValues {
pub storage_layout: bool,
pub transient_storage_layout: bool,
pub assembly: bool,
pub legacy_assembly: bool,
pub gas_estimates: bool,
pub metadata: bool,
pub ir: bool,
Expand Down Expand Up @@ -458,6 +478,7 @@ impl ExtraOutputValues {
storage_layout: true,
transient_storage_layout: true,
assembly: true,
legacy_assembly: true,
gas_estimates: true,
metadata: true,
ir: true,
Expand Down Expand Up @@ -500,6 +521,7 @@ impl ExtraOutputValues {
ContractOutputSelection::Evm(evm) => match evm {
EvmOutputSelection::All => {
config.assembly = true;
config.legacy_assembly = true;
config.gas_estimates = true;
config.method_identifiers = true;
config.generated_sources = true;
Expand All @@ -509,6 +531,9 @@ impl ExtraOutputValues {
EvmOutputSelection::Assembly => {
config.assembly = true;
}
EvmOutputSelection::LegacyAssembly => {
config.legacy_assembly = true;
}
EvmOutputSelection::MethodIdentifiers => {
config.method_identifiers = true;
}
Expand Down Expand Up @@ -555,6 +580,7 @@ pub struct ExtraOutputFiles {
pub ir_optimized: bool,
pub ewasm: bool,
pub assembly: bool,
pub legacy_assembly: bool,
pub source_map: bool,
pub generated_sources: bool,
pub bytecode: bool,
Expand Down Expand Up @@ -582,6 +608,7 @@ impl ExtraOutputFiles {
ir_optimized: true,
ewasm: true,
assembly: true,
legacy_assembly: true,
source_map: true,
generated_sources: true,
bytecode: true,
Expand Down Expand Up @@ -612,6 +639,7 @@ impl ExtraOutputFiles {
ContractOutputSelection::Evm(evm) => match evm {
EvmOutputSelection::All => {
config.assembly = true;
config.legacy_assembly = true;
config.generated_sources = true;
config.source_map = true;
config.bytecode = true;
Expand All @@ -620,6 +648,9 @@ impl ExtraOutputFiles {
EvmOutputSelection::Assembly => {
config.assembly = true;
}
EvmOutputSelection::LegacyAssembly => {
config.legacy_assembly = true;
}
EvmOutputSelection::ByteCode(BytecodeOutputSelection::GeneratedSources) => {
config.generated_sources = true;
}
Expand Down Expand Up @@ -713,6 +744,21 @@ impl ExtraOutputFiles {
Ok(())
}

fn process_legacy_assembly(
&self,
asm: Option<serde_json::Value>,
file: &Path,
) -> Result<(), SolcError> {
if self.legacy_assembly {
if let Some(legacy_asm) = asm {
let file = file.with_extension("legacyAssembly");
fs::write(&file, legacy_asm.as_str().unwrap_or_default())
.map_err(|err| SolcError::io(err, file))?
}
}
Ok(())
}

fn process_generated_sources(
&self,
generated_sources: Option<&Vec<GeneratedSource>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/compilers/src/compilers/solc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl ParsedSource for SolData {
_paths: &crate::ProjectPathsConfig<C>,
_include_paths: &mut BTreeSet<PathBuf>,
) -> Result<Vec<PathBuf>> {
return Ok(self.imports.iter().map(|i| i.data().path().to_path_buf()).collect_vec());
Ok(self.imports.iter().map(|i| i.data().path().to_path_buf()).collect_vec())
}

fn language(&self) -> Self::Language {
Expand Down
3 changes: 3 additions & 0 deletions crates/compilers/tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ fn can_compile_configured() {
ir: true,
ir_optimized: true,
opcodes: true,
legacy_assembly: true,
..Default::default()
},
..Default::default()
Expand All @@ -202,6 +203,8 @@ fn can_compile_configured() {
assert!(artifact.ir.is_some());
assert!(artifact.ir_optimized.is_some());
assert!(artifact.opcodes.is_some());
assert!(artifact.opcodes.is_some());
assert!(artifact.legacy_assembly.is_some());
}

#[test]
Expand Down

0 comments on commit b06e805

Please sign in to comment.