Remove unnecessary fields from CodeInfo
This commit is contained in:
@@ -55,12 +55,7 @@ impl<'a> MemoryCodeSink<'a> {
|
|||||||
Self {
|
Self {
|
||||||
data,
|
data,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
info: CodeInfo {
|
info: CodeInfo { total_size: 0 },
|
||||||
code_size: 0,
|
|
||||||
jumptables_size: 0,
|
|
||||||
rodata_size: 0,
|
|
||||||
total_size: 0,
|
|
||||||
},
|
|
||||||
relocs,
|
relocs,
|
||||||
traps,
|
traps,
|
||||||
}
|
}
|
||||||
@@ -140,16 +135,7 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
|
|||||||
self.traps.trap(ofs, srcloc, code);
|
self.traps.trap(ofs, srcloc, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn begin_jumptables(&mut self) {
|
|
||||||
self.info.code_size = self.offset();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn begin_rodata(&mut self) {
|
|
||||||
self.info.jumptables_size = self.offset() - self.info.code_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn end_codegen(&mut self) {
|
fn end_codegen(&mut self) {
|
||||||
self.info.rodata_size = self.offset() - (self.info.jumptables_size + self.info.code_size);
|
|
||||||
self.info.total_size = self.offset();
|
self.info.total_size = self.offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,31 +96,10 @@ impl fmt::Display for Reloc {
|
|||||||
/// precedes the boundary between the sections.
|
/// precedes the boundary between the sections.
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct CodeInfo {
|
pub struct CodeInfo {
|
||||||
/// Number of bytes of machine code (the code starts at offset 0).
|
|
||||||
pub code_size: CodeOffset,
|
|
||||||
|
|
||||||
/// Number of bytes of jumptables.
|
|
||||||
pub jumptables_size: CodeOffset,
|
|
||||||
|
|
||||||
/// Number of bytes of rodata.
|
|
||||||
pub rodata_size: CodeOffset,
|
|
||||||
|
|
||||||
/// Number of bytes in total.
|
/// Number of bytes in total.
|
||||||
pub total_size: CodeOffset,
|
pub total_size: CodeOffset,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CodeInfo {
|
|
||||||
/// Offset of any relocatable jump tables, or equal to rodata if there are no jump tables.
|
|
||||||
pub fn jumptables(&self) -> CodeOffset {
|
|
||||||
self.code_size
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Offset of any copyable read-only data, or equal to total_size if there are no rodata.
|
|
||||||
pub fn rodata(&self) -> CodeOffset {
|
|
||||||
self.code_size + self.jumptables_size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Abstract interface for adding bytes to the code segment.
|
/// Abstract interface for adding bytes to the code segment.
|
||||||
///
|
///
|
||||||
/// A `CodeSink` will receive all of the machine code for a function. It also accepts relocations
|
/// A `CodeSink` will receive all of the machine code for a function. It also accepts relocations
|
||||||
@@ -147,12 +126,6 @@ pub trait CodeSink {
|
|||||||
/// Add trap information for the current offset.
|
/// Add trap information for the current offset.
|
||||||
fn trap(&mut self, _: TrapCode, _: SourceLoc);
|
fn trap(&mut self, _: TrapCode, _: SourceLoc);
|
||||||
|
|
||||||
/// Machine code output is complete, jump table data may follow.
|
|
||||||
fn begin_jumptables(&mut self);
|
|
||||||
|
|
||||||
/// Jump table output is complete, raw read-only data may follow.
|
|
||||||
fn begin_rodata(&mut self);
|
|
||||||
|
|
||||||
/// Read-only data output is complete, we're done.
|
/// Read-only data output is complete, we're done.
|
||||||
fn end_codegen(&mut self);
|
fn end_codegen(&mut self);
|
||||||
|
|
||||||
|
|||||||
@@ -68,10 +68,6 @@ impl CodeSink for TestCodeSink {
|
|||||||
|
|
||||||
fn trap(&mut self, _code: TrapCode, _srcloc: SourceLoc) {}
|
fn trap(&mut self, _code: TrapCode, _srcloc: SourceLoc) {}
|
||||||
|
|
||||||
fn begin_jumptables(&mut self) {}
|
|
||||||
|
|
||||||
fn begin_rodata(&mut self) {}
|
|
||||||
|
|
||||||
fn end_codegen(&mut self) {}
|
fn end_codegen(&mut self) {}
|
||||||
|
|
||||||
fn add_call_site(&mut self, _opcode: Opcode, _srcloc: SourceLoc) {}
|
fn add_call_site(&mut self, _opcode: Opcode, _srcloc: SourceLoc) {}
|
||||||
|
|||||||
@@ -1460,8 +1460,6 @@ impl MachBufferFinalized {
|
|||||||
sink.put1(*byte);
|
sink.put1(*byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
sink.begin_jumptables();
|
|
||||||
sink.begin_rodata();
|
|
||||||
sink.end_codegen();
|
sink.end_codegen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2091,8 +2089,6 @@ mod test {
|
|||||||
fn trap(&mut self, t: TrapCode, _: SourceLoc) {
|
fn trap(&mut self, t: TrapCode, _: SourceLoc) {
|
||||||
self.traps.push((self.offset, t));
|
self.traps.push((self.offset, t));
|
||||||
}
|
}
|
||||||
fn begin_jumptables(&mut self) {}
|
|
||||||
fn begin_rodata(&mut self) {}
|
|
||||||
fn end_codegen(&mut self) {}
|
fn end_codegen(&mut self) {}
|
||||||
fn add_call_site(&mut self, op: Opcode, _: SourceLoc) {
|
fn add_call_site(&mut self, op: Opcode, _: SourceLoc) {
|
||||||
self.callsites.push((self.offset, op));
|
self.callsites.push((self.offset, op));
|
||||||
|
|||||||
@@ -367,12 +367,8 @@ pub struct MachCompileResult {
|
|||||||
impl MachCompileResult {
|
impl MachCompileResult {
|
||||||
/// Get a `CodeInfo` describing section sizes from this compilation result.
|
/// Get a `CodeInfo` describing section sizes from this compilation result.
|
||||||
pub fn code_info(&self) -> CodeInfo {
|
pub fn code_info(&self) -> CodeInfo {
|
||||||
let code_size = self.buffer.total_size();
|
|
||||||
CodeInfo {
|
CodeInfo {
|
||||||
code_size,
|
total_size: self.buffer.total_size(),
|
||||||
jumptables_size: 0,
|
|
||||||
rodata_size: 0,
|
|
||||||
total_size: code_size,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,5 @@ impl binemit::CodeSink for SizeSink {
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
fn trap(&mut self, _code: ir::TrapCode, _srcloc: ir::SourceLoc) {}
|
fn trap(&mut self, _code: ir::TrapCode, _srcloc: ir::SourceLoc) {}
|
||||||
fn begin_jumptables(&mut self) {}
|
|
||||||
fn begin_rodata(&mut self) {}
|
|
||||||
fn end_codegen(&mut self) {}
|
fn end_codegen(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,8 +91,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
print_all(
|
print_all(
|
||||||
isa,
|
isa,
|
||||||
&mem,
|
&mem,
|
||||||
code_info.code_size,
|
code_info.total_size,
|
||||||
code_info.jumptables_size + code_info.rodata_size,
|
|
||||||
&relocs,
|
&relocs,
|
||||||
&traps,
|
&traps,
|
||||||
&stack_maps,
|
&stack_maps,
|
||||||
|
|||||||
@@ -193,14 +193,12 @@ pub fn print_all(
|
|||||||
isa: &dyn TargetIsa,
|
isa: &dyn TargetIsa,
|
||||||
mem: &[u8],
|
mem: &[u8],
|
||||||
code_size: u32,
|
code_size: u32,
|
||||||
rodata_size: u32,
|
|
||||||
relocs: &PrintRelocs,
|
relocs: &PrintRelocs,
|
||||||
traps: &PrintTraps,
|
traps: &PrintTraps,
|
||||||
stack_maps: &PrintStackMaps,
|
stack_maps: &PrintStackMaps,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
print_bytes(&mem);
|
print_bytes(&mem);
|
||||||
print_disassembly(isa, &mem[0..code_size as usize])?;
|
print_disassembly(isa, &mem[0..code_size as usize])?;
|
||||||
print_readonly_data(&mem[code_size as usize..(code_size + rodata_size) as usize]);
|
|
||||||
println!("\n{}\n{}\n{}", &relocs.text, &traps.text, &stack_maps.text);
|
println!("\n{}\n{}\n{}", &relocs.text, &traps.text, &stack_maps.text);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -218,25 +216,3 @@ pub fn print_bytes(mem: &[u8]) {
|
|||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_readonly_data(mem: &[u8]) {
|
|
||||||
if mem.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("\nFollowed by {} bytes of read-only data:", mem.len());
|
|
||||||
|
|
||||||
for (i, byte) in mem.iter().enumerate() {
|
|
||||||
if i % 16 == 0 {
|
|
||||||
if i != 0 {
|
|
||||||
println!();
|
|
||||||
}
|
|
||||||
print!("{:4}: ", i);
|
|
||||||
}
|
|
||||||
if i % 4 == 0 {
|
|
||||||
print!(" ");
|
|
||||||
}
|
|
||||||
print!("{:02x} ", byte);
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
for (def_index, func) in dummy_environ.info.function_bodies.iter() {
|
for (def_index, func) in dummy_environ.info.function_bodies.iter() {
|
||||||
context.func = func.clone();
|
context.func = func.clone();
|
||||||
|
|
||||||
let mut saved_sizes = None;
|
let mut saved_size = None;
|
||||||
let func_index = num_func_imports + def_index.index();
|
let func_index = num_func_imports + def_index.index();
|
||||||
let mut mem = vec![];
|
let mut mem = vec![];
|
||||||
let mut relocs = PrintRelocs::new(options.print);
|
let mut relocs = PrintRelocs::new(options.print);
|
||||||
@@ -285,10 +285,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
}
|
}
|
||||||
|
|
||||||
if options.disasm {
|
if options.disasm {
|
||||||
saved_sizes = Some((
|
saved_size = Some(code_info.total_size);
|
||||||
code_info.code_size,
|
|
||||||
code_info.jumptables_size + code_info.rodata_size,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,16 +322,8 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
vprintln!(options.verbose, "");
|
vprintln!(options.verbose, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((code_size, rodata_size)) = saved_sizes {
|
if let Some(total_size) = saved_size {
|
||||||
print_all(
|
print_all(isa, &mem, total_size, &relocs, &traps, &stack_maps)?;
|
||||||
isa,
|
|
||||||
&mem,
|
|
||||||
code_size,
|
|
||||||
rodata_size,
|
|
||||||
&relocs,
|
|
||||||
&traps,
|
|
||||||
&stack_maps,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.clear();
|
context.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user