Skip to content

Commit

Permalink
[solidity] Add CLI option '-g' to generate debug information.
Browse files Browse the repository at this point in the history
Add command line option '-g' to generate source level debug information
in the output code. This only works with the LLVM-IR code generator.

Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen
settings structure, to record the setting of the '-g' CLI option.
  • Loading branch information
wpt967 committed Oct 4, 2024
1 parent 77fe683 commit c54a5b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/llvm-context/src/optimizer/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use itertools::Itertools;

use self::size_level::SizeLevel;

/// The LLVM optimizer settings.
/// The LLVM optimizer and code-gen settings.
#[derive(Debug, Serialize, Deserialize, Clone, Eq)]
pub struct Settings {
/// The middle-end optimization level.
Expand All @@ -28,6 +28,9 @@ pub struct Settings {
pub is_verify_each_enabled: bool,
/// Whether the LLVM `debug logging` option is enabled.
pub is_debug_logging_enabled: bool,

/// Whether to generate source-level debug information.
pub emit_debug_info: bool,
}

impl Settings {
Expand All @@ -47,6 +50,8 @@ impl Settings {

is_verify_each_enabled: false,
is_debug_logging_enabled: false,

emit_debug_info: false,
}
}

Expand All @@ -58,6 +63,8 @@ impl Settings {

is_verify_each_enabled: bool,
is_debug_logging_enabled: bool,

emit_debug_info: bool,
) -> Self {
Self {
level_middle_end,
Expand All @@ -69,6 +76,8 @@ impl Settings {

is_verify_each_enabled,
is_debug_logging_enabled,

emit_debug_info,
}
}

Expand Down Expand Up @@ -220,6 +229,11 @@ impl Settings {
pub fn is_system_request_memoization_disabled(&self) -> bool {
self.is_system_request_memoization_disabled
}

/// Whether source-level debug information should be emitted.
pub fn emit_debug_info(&self) -> bool {
return self.emit_debug_info;
}
}

impl PartialEq for Settings {
Expand Down
5 changes: 5 additions & 0 deletions crates/solidity/src/resolc/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ pub struct Arguments {
#[structopt(long = "suppress-warnings")]
pub suppress_warnings: Option<Vec<String>>,

/// Generate source based debug information in the output code file. This only has an effect
/// with the LLVM-IR code generator and is ignored otherwise.
#[structopt(short = 'g')]
pub emit_source_debug_info: bool,

/// Dump all IRs to files in the specified directory.
/// Only for testing and debugging.
#[structopt(long = "debug-output-dir")]
Expand Down
1 change: 1 addition & 0 deletions crates/solidity/src/resolc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn main_inner() -> anyhow::Result<()> {
}
optimizer_settings.is_verify_each_enabled = arguments.llvm_verify_each;
optimizer_settings.is_debug_logging_enabled = arguments.llvm_debug_logging;
optimizer_settings.emit_debug_info = arguments.emit_source_debug_info;

let include_metadata_hash = match arguments.metadata_hash {
Some(metadata_hash) => {
Expand Down

0 comments on commit c54a5b9

Please sign in to comment.