Skip to content

Commit 549dc76

Browse files
authored
fix: include evm.legacyAssembly output (#206)
adding support for `legacyAssembly` artifact output, foundry-rs/foundry#8977
1 parent dd4fd70 commit 549dc76

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

crates/artifacts/solc/src/configurable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct ConfigurableContractArtifact {
2323
#[serde(default, skip_serializing_if = "Option::is_none")]
2424
pub assembly: Option<String>,
2525
#[serde(default, skip_serializing_if = "Option::is_none")]
26+
pub legacy_assembly: Option<serde_json::Value>,
27+
#[serde(default, skip_serializing_if = "Option::is_none")]
2628
pub opcodes: Option<String>,
2729
#[serde(default, skip_serializing_if = "Option::is_none")]
2830
pub method_identifiers: Option<BTreeMap<String, String>>,

crates/compilers/src/artifact_output/configurable.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl ConfigurableArtifacts {
9696
storage_layout,
9797
transient_storage_layout,
9898
assembly,
99+
legacy_assembly,
99100
gas_estimates,
100101
metadata,
101102
ir,
@@ -133,6 +134,9 @@ impl ConfigurableArtifacts {
133134
if assembly || self.additional_files.assembly {
134135
selection.push(EvmOutputSelection::Assembly.into());
135136
}
137+
if legacy_assembly || self.additional_files.legacy_assembly {
138+
selection.push(EvmOutputSelection::LegacyAssembly.into());
139+
}
136140
if ewasm || self.additional_files.ewasm {
137141
selection.push(EwasmOutputSelection::All.into());
138142
}
@@ -207,6 +211,7 @@ impl ArtifactOutput for ConfigurableArtifacts {
207211
let mut artifact_function_debug_data = None;
208212
let mut artifact_method_identifiers = None;
209213
let mut artifact_assembly = None;
214+
let mut artifact_legacy_assembly = None;
210215
let mut artifact_storage_layout = None;
211216
let mut artifact_transient_storage_layout = None;
212217
let mut generated_sources = None;
@@ -264,7 +269,7 @@ impl ArtifactOutput for ConfigurableArtifacts {
264269
deployed_bytecode,
265270
method_identifiers,
266271
gas_estimates,
267-
legacy_assembly: _,
272+
legacy_assembly,
268273
} = evm;
269274

270275
if self.additional_values.function_debug_data {
@@ -290,13 +295,18 @@ impl ArtifactOutput for ConfigurableArtifacts {
290295
if self.additional_values.assembly {
291296
artifact_assembly = assembly;
292297
}
298+
299+
if self.additional_values.legacy_assembly {
300+
artifact_legacy_assembly = legacy_assembly;
301+
}
293302
}
294303

295304
ConfigurableContractArtifact {
296305
abi,
297306
bytecode: artifact_bytecode,
298307
deployed_bytecode: artifact_deployed_bytecode,
299308
assembly: artifact_assembly,
309+
legacy_assembly: artifact_legacy_assembly,
300310
opcodes,
301311
function_debug_data: artifact_function_debug_data,
302312
method_identifiers: artifact_method_identifiers,
@@ -343,6 +353,7 @@ impl ArtifactOutput for ConfigurableArtifacts {
343353
ir_optimized,
344354
ewasm,
345355
assembly,
356+
legacy_assembly,
346357
source_map,
347358
generated_sources,
348359
bytecode: _,
@@ -365,6 +376,12 @@ impl ArtifactOutput for ConfigurableArtifacts {
365376
if assembly && artifact.assembly.is_none() {
366377
return Ok(true);
367378
}
379+
if assembly && artifact.assembly.is_none() {
380+
return Ok(true);
381+
}
382+
if legacy_assembly && artifact.legacy_assembly.is_none() {
383+
return Ok(true);
384+
}
368385
if source_map && artifact.get_source_map_str().is_none() {
369386
return Ok(true);
370387
}
@@ -387,6 +404,8 @@ impl ArtifactOutput for ConfigurableArtifacts {
387404
let artifact = &artifact_file.artifact;
388405
self.additional_files.process_abi(artifact.abi.as_ref(), file)?;
389406
self.additional_files.process_assembly(artifact.assembly.as_deref(), file)?;
407+
self.additional_files
408+
.process_legacy_assembly(artifact.legacy_assembly.clone(), file)?;
390409
self.additional_files
391410
.process_bytecode(artifact.bytecode.as_ref().map(|b| &b.object), file)?;
392411
self.additional_files.process_deployed_bytecode(
@@ -424,6 +443,7 @@ pub struct ExtraOutputValues {
424443
pub storage_layout: bool,
425444
pub transient_storage_layout: bool,
426445
pub assembly: bool,
446+
pub legacy_assembly: bool,
427447
pub gas_estimates: bool,
428448
pub metadata: bool,
429449
pub ir: bool,
@@ -458,6 +478,7 @@ impl ExtraOutputValues {
458478
storage_layout: true,
459479
transient_storage_layout: true,
460480
assembly: true,
481+
legacy_assembly: true,
461482
gas_estimates: true,
462483
metadata: true,
463484
ir: true,
@@ -500,6 +521,7 @@ impl ExtraOutputValues {
500521
ContractOutputSelection::Evm(evm) => match evm {
501522
EvmOutputSelection::All => {
502523
config.assembly = true;
524+
config.legacy_assembly = true;
503525
config.gas_estimates = true;
504526
config.method_identifiers = true;
505527
config.generated_sources = true;
@@ -509,6 +531,9 @@ impl ExtraOutputValues {
509531
EvmOutputSelection::Assembly => {
510532
config.assembly = true;
511533
}
534+
EvmOutputSelection::LegacyAssembly => {
535+
config.legacy_assembly = true;
536+
}
512537
EvmOutputSelection::MethodIdentifiers => {
513538
config.method_identifiers = true;
514539
}
@@ -555,6 +580,7 @@ pub struct ExtraOutputFiles {
555580
pub ir_optimized: bool,
556581
pub ewasm: bool,
557582
pub assembly: bool,
583+
pub legacy_assembly: bool,
558584
pub source_map: bool,
559585
pub generated_sources: bool,
560586
pub bytecode: bool,
@@ -582,6 +608,7 @@ impl ExtraOutputFiles {
582608
ir_optimized: true,
583609
ewasm: true,
584610
assembly: true,
611+
legacy_assembly: true,
585612
source_map: true,
586613
generated_sources: true,
587614
bytecode: true,
@@ -612,6 +639,7 @@ impl ExtraOutputFiles {
612639
ContractOutputSelection::Evm(evm) => match evm {
613640
EvmOutputSelection::All => {
614641
config.assembly = true;
642+
config.legacy_assembly = true;
615643
config.generated_sources = true;
616644
config.source_map = true;
617645
config.bytecode = true;
@@ -620,6 +648,9 @@ impl ExtraOutputFiles {
620648
EvmOutputSelection::Assembly => {
621649
config.assembly = true;
622650
}
651+
EvmOutputSelection::LegacyAssembly => {
652+
config.legacy_assembly = true;
653+
}
623654
EvmOutputSelection::ByteCode(BytecodeOutputSelection::GeneratedSources) => {
624655
config.generated_sources = true;
625656
}
@@ -713,6 +744,21 @@ impl ExtraOutputFiles {
713744
Ok(())
714745
}
715746

747+
fn process_legacy_assembly(
748+
&self,
749+
asm: Option<serde_json::Value>,
750+
file: &Path,
751+
) -> Result<(), SolcError> {
752+
if self.legacy_assembly {
753+
if let Some(legacy_asm) = asm {
754+
let file = file.with_extension("legacyAssembly");
755+
fs::write(&file, legacy_asm.as_str().unwrap_or_default())
756+
.map_err(|err| SolcError::io(err, file))?
757+
}
758+
}
759+
Ok(())
760+
}
761+
716762
fn process_generated_sources(
717763
&self,
718764
generated_sources: Option<&Vec<GeneratedSource>>,

crates/compilers/src/compilers/solc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl ParsedSource for SolData {
265265
_paths: &crate::ProjectPathsConfig<C>,
266266
_include_paths: &mut BTreeSet<PathBuf>,
267267
) -> Result<Vec<PathBuf>> {
268-
return Ok(self.imports.iter().map(|i| i.data().path().to_path_buf()).collect_vec());
268+
Ok(self.imports.iter().map(|i| i.data().path().to_path_buf()).collect_vec())
269269
}
270270

271271
fn language(&self) -> Self::Language {

crates/compilers/tests/project.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ fn can_compile_configured() {
188188
ir: true,
189189
ir_optimized: true,
190190
opcodes: true,
191+
legacy_assembly: true,
191192
..Default::default()
192193
},
193194
..Default::default()
@@ -202,6 +203,8 @@ fn can_compile_configured() {
202203
assert!(artifact.ir.is_some());
203204
assert!(artifact.ir_optimized.is_some());
204205
assert!(artifact.opcodes.is_some());
206+
assert!(artifact.opcodes.is_some());
207+
assert!(artifact.legacy_assembly.is_some());
205208
}
206209

207210
#[test]

0 commit comments

Comments
 (0)