-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[move] Added bytecode map generation during bytecode disassembly #20797
Changes from 4 commits
1ec008b
a6fe15a
e339c34
6f6cccf
dbdb6a3
dad8d93
27fe3be
8111262
8dce534
04679b2
b619864
dd15c7c
9ae1dd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
use super::reroot_path; | ||||||||||||||||||||||||||||||||||
use clap::*; | ||||||||||||||||||||||||||||||||||
use move_bytecode_source_map::utils::serialize_to_json_string; | ||||||||||||||||||||||||||||||||||
use move_compiler::compiled_unit::NamedCompiledModule; | ||||||||||||||||||||||||||||||||||
use move_disassembler::disassembler::Disassembler; | ||||||||||||||||||||||||||||||||||
use move_package::{compilation::compiled_package::CompiledUnitWithSource, BuildConfig}; | ||||||||||||||||||||||||||||||||||
|
@@ -24,6 +25,9 @@ pub struct Disassemble { | |||||||||||||||||||||||||||||||||
#[clap(long = "Xdebug")] | ||||||||||||||||||||||||||||||||||
/// Also print the raw disassembly using Rust's Debug output, at the end. | ||||||||||||||||||||||||||||||||||
pub debug: bool, | ||||||||||||||||||||||||||||||||||
#[clap(long = "bytecode-map")] | ||||||||||||||||||||||||||||||||||
/// Print the "bytecode map" (source map for disassembled bytecode) | ||||||||||||||||||||||||||||||||||
pub bytecode_map: bool, | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
impl Disassemble { | ||||||||||||||||||||||||||||||||||
|
@@ -34,6 +38,7 @@ impl Disassemble { | |||||||||||||||||||||||||||||||||
package_name, | ||||||||||||||||||||||||||||||||||
module_or_script_name, | ||||||||||||||||||||||||||||||||||
debug, | ||||||||||||||||||||||||||||||||||
bytecode_map, | ||||||||||||||||||||||||||||||||||
} = self; | ||||||||||||||||||||||||||||||||||
// Make sure the package is built | ||||||||||||||||||||||||||||||||||
let package = config.compile_package(&rerooted_path, &mut Vec::new())?; | ||||||||||||||||||||||||||||||||||
|
@@ -66,7 +71,15 @@ impl Disassemble { | |||||||||||||||||||||||||||||||||
source_path, | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
println!("{}", Disassembler::from_unit(&unit.unit).disassemble()?); | ||||||||||||||||||||||||||||||||||
let mut d = Disassembler::from_unit(&unit.unit); | ||||||||||||||||||||||||||||||||||
if bytecode_map { | ||||||||||||||||||||||||||||||||||
d.generate_bytecode_map(); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
let (disassemble_string, bcode_map) = d.disassemble()?; | ||||||||||||||||||||||||||||||||||
if bytecode_map { | ||||||||||||||||||||||||||||||||||
println!("{}", serialize_to_json_string(&bcode_map)?); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
println!("{}", disassemble_string); | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think places like this will be nicer with the two function approach as this will also allow removing the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, it allowed me to remove this function but it also means that having a global flag is no longer necessary (and somewhat awkward even) |
||||||||||||||||||||||||||||||||||
if debug { | ||||||||||||||||||||||||||||||||||
println!("\n{:#?}", &unit.unit.module) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how I feel about this. I'd probably prefer something like adding a new function, e.g.,
disasssemble_with_source_map
(or something like that) that would also generate the source map during disassembly, and then keeping this function the same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!