mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-09 20:01:05 +00:00
fix: addressed assembly text build mechanism (#9)
Use `build.assembly_text` for `--asm` output
This commit is contained in:
@@ -8,9 +8,6 @@ use std::path::Path;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use polkavm_common::program::ProgramBlob;
|
||||
use polkavm_disassembler::{Disassembler, DisassemblyFormat};
|
||||
|
||||
use crate::solc::combined_json::contract::Contract as CombinedJsonContract;
|
||||
use crate::solc::standard_json::output::contract::Contract as StandardJsonOutputContract;
|
||||
|
||||
@@ -56,7 +53,6 @@ impl Contract {
|
||||
overwrite: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let file_name = Self::short_path(self.path.as_str());
|
||||
let bytescode = self.build.bytecode;
|
||||
|
||||
if output_assembly {
|
||||
let file_name = format!(
|
||||
@@ -72,33 +68,7 @@ impl Contract {
|
||||
"Refusing to overwrite an existing file {file_path:?} (use --overwrite to force)."
|
||||
);
|
||||
} else {
|
||||
let program_blob = ProgramBlob::parse(bytescode.as_slice()).map_err(|error| {
|
||||
anyhow::anyhow!(format!("Failed to parse program blob: {}", error))
|
||||
})?;
|
||||
|
||||
let mut disassembler = Disassembler::new(&program_blob, DisassemblyFormat::Guest)
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(format!(
|
||||
"Failed to create disassembler for contract '{:?}'\n\nDue to:\n{}",
|
||||
&file_path, error
|
||||
))
|
||||
})?;
|
||||
|
||||
let mut disassembled_code = Vec::new();
|
||||
disassembler
|
||||
.disassemble_into(&mut disassembled_code)
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(format!(
|
||||
"Failed to disassemble contract '{:?}'\n\nDue to:\n{}\n\nGas details:{:?}\n",
|
||||
&file_path, error, disassembler.display_gas()
|
||||
))
|
||||
})?;
|
||||
|
||||
let assembly_text = String::from_utf8(disassembled_code)
|
||||
.map_err(|error| anyhow::anyhow!(format!(
|
||||
"Failed to convert disassembled code to string for contract '{:?}'\n\nDue to:\n{}",
|
||||
&file_path, error
|
||||
)))?;
|
||||
let assembly_text = self.build.assembly_text;
|
||||
|
||||
File::create(&file_path)
|
||||
.map_err(|error| {
|
||||
@@ -125,7 +95,7 @@ impl Contract {
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!("File {:?} creating error: {}", file_path, error)
|
||||
})?
|
||||
.write_all(bytescode.as_slice())
|
||||
.write_all(self.build.bytecode.as_slice())
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!("File {:?} writing error: {}", file_path, error)
|
||||
})?;
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "npx jest --verbose --testPathPattern="
|
||||
|
||||
"test": "npx jest --verbose --testPathIgnorePatterns=zkasm.test.ts"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Matter Labs",
|
||||
|
||||
@@ -6,9 +6,6 @@ use std::str::FromStr;
|
||||
|
||||
use self::arguments::Arguments;
|
||||
|
||||
use polkavm_common::program::ProgramBlob;
|
||||
use polkavm_disassembler::{Disassembler, DisassemblyFormat};
|
||||
|
||||
/// The rayon worker stack size.
|
||||
const RAYON_WORKER_STACK_SIZE: usize = 16 * 1024 * 1024;
|
||||
|
||||
@@ -193,41 +190,17 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
);
|
||||
} else if arguments.output_assembly || arguments.output_binary {
|
||||
for (path, contract) in build.contracts.into_iter() {
|
||||
let bytescode = contract.build.bytecode;
|
||||
|
||||
if arguments.output_assembly {
|
||||
let program_blob = ProgramBlob::parse(bytescode.as_slice()).map_err(|error| {
|
||||
anyhow::anyhow!(format!("Failed to parse program blob: {}", error))
|
||||
})?;
|
||||
|
||||
let mut disassembler = Disassembler::new(&program_blob, DisassemblyFormat::Guest)
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(format!(
|
||||
"Failed to create disassembler for contract '{}'\n\nDue to:\n{}",
|
||||
path, error
|
||||
))
|
||||
})?;
|
||||
|
||||
let mut disassembled_code = Vec::new();
|
||||
disassembler
|
||||
.disassemble_into(&mut disassembled_code)
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(format!(
|
||||
"Failed to disassemble contract '{}'\n\nDue to:\n{}\n\nGas details:{:?}\n",
|
||||
path, error, disassembler.display_gas()
|
||||
))
|
||||
})?;
|
||||
|
||||
let assembly_text = String::from_utf8(disassembled_code)
|
||||
.map_err(|error| anyhow::anyhow!(format!(
|
||||
"Failed to convert disassembled code to string for contract '{}'\n\nDue to:\n{}",
|
||||
path, error
|
||||
)))?;
|
||||
let assembly_text = contract.build.assembly_text;
|
||||
|
||||
println!("Contract `{}` assembly:\n\n{}", path, assembly_text);
|
||||
}
|
||||
if arguments.output_binary {
|
||||
println!("Contract `{}` bytecode: 0x{}", path, hex::encode(bytescode));
|
||||
println!(
|
||||
"Contract `{}` bytecode: 0x{}",
|
||||
path,
|
||||
hex::encode(contract.build.bytecode)
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user