mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-23 08:28:00 +00:00
experimental: support for debug info (#118)
Signed-off-by: wpt967 <matt.aw@parity.io> Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
@@ -13,41 +13,52 @@ use self::ir_type::IRType;
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct DebugConfig {
|
||||
/// The directory to dump the IRs to.
|
||||
pub output_directory: PathBuf,
|
||||
pub output_directory: Option<PathBuf>,
|
||||
/// Whether debug info should be emitted.
|
||||
pub emit_debug_info: bool,
|
||||
}
|
||||
|
||||
impl DebugConfig {
|
||||
/// A shortcut constructor.
|
||||
pub fn new(output_directory: PathBuf) -> Self {
|
||||
Self { output_directory }
|
||||
pub const fn new(output_directory: Option<PathBuf>, emit_debug_info: bool) -> Self {
|
||||
Self {
|
||||
output_directory,
|
||||
emit_debug_info,
|
||||
}
|
||||
}
|
||||
|
||||
/// Dumps the Yul IR.
|
||||
pub fn dump_yul(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Dumps the EVM legacy assembly IR.
|
||||
pub fn dump_evmla(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EVMLA);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EVMLA);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Dumps the Ethereal IR.
|
||||
pub fn dump_ethir(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EthIR);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EthIR);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -58,12 +69,15 @@ impl DebugConfig {
|
||||
contract_path: &str,
|
||||
module: &inkwell::module::Module,
|
||||
) -> anyhow::Result<()> {
|
||||
let llvm_code = module.print_to_string().to_string();
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let llvm_code = module.print_to_string().to_string();
|
||||
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, Some("unoptimized"), IRType::LLVM);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, llvm_code)?;
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name =
|
||||
Self::full_file_name(contract_path, Some("unoptimized"), IRType::LLVM);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, llvm_code)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -74,32 +88,39 @@ impl DebugConfig {
|
||||
contract_path: &str,
|
||||
module: &inkwell::module::Module,
|
||||
) -> anyhow::Result<()> {
|
||||
let llvm_code = module.print_to_string().to_string();
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let llvm_code = module.print_to_string().to_string();
|
||||
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, Some("optimized"), IRType::LLVM);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, llvm_code)?;
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name =
|
||||
Self::full_file_name(contract_path, Some("optimized"), IRType::LLVM);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, llvm_code)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Dumps the assembly.
|
||||
pub fn dump_assembly(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Assembly);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Assembly);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Dumps the code object.
|
||||
pub fn dump_object(&self, contract_path: &str, code: &[u8]) -> anyhow::Result<()> {
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::SO);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::SO);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, code)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -112,10 +133,12 @@ impl DebugConfig {
|
||||
contract_suffix: Option<&str>,
|
||||
stage_json: &Vec<u8>,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut file_path = self.output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, contract_suffix, IRType::JSON);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, stage_json)?;
|
||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||
let mut file_path = output_directory.to_owned();
|
||||
let full_file_name = Self::full_file_name(contract_path, contract_suffix, IRType::JSON);
|
||||
file_path.push(full_file_name);
|
||||
std::fs::write(file_path, stage_json)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user