Remove trap from CodeSink
And introduce MachBufferFinalized::traps() in the place.
This commit is contained in:
@@ -35,7 +35,6 @@ pub struct MemoryCodeSink<'a> {
|
|||||||
/// Offset is isize because its major consumer needs it in that form.
|
/// Offset is isize because its major consumer needs it in that form.
|
||||||
offset: isize,
|
offset: isize,
|
||||||
relocs: &'a mut dyn RelocSink,
|
relocs: &'a mut dyn RelocSink,
|
||||||
traps: &'a mut dyn TrapSink,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MemoryCodeSink<'a> {
|
impl<'a> MemoryCodeSink<'a> {
|
||||||
@@ -48,13 +47,11 @@ impl<'a> MemoryCodeSink<'a> {
|
|||||||
pub unsafe fn new(
|
pub unsafe fn new(
|
||||||
data: *mut u8,
|
data: *mut u8,
|
||||||
relocs: &'a mut dyn RelocSink,
|
relocs: &'a mut dyn RelocSink,
|
||||||
traps: &'a mut dyn TrapSink,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data,
|
data,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
relocs,
|
relocs,
|
||||||
traps,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,11 +103,6 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
|
|||||||
let ofs = self.offset as CodeOffset;
|
let ofs = self.offset as CodeOffset;
|
||||||
self.relocs.reloc_external(ofs, srcloc, rel, name, addend);
|
self.relocs.reloc_external(ofs, srcloc, rel, name, addend);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trap(&mut self, code: TrapCode, srcloc: SourceLoc) {
|
|
||||||
let ofs = self.offset as CodeOffset;
|
|
||||||
self.traps.trap(ofs, srcloc, code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `RelocSink` implementation that does nothing, which is convenient when
|
/// A `RelocSink` implementation that does nothing, which is convenient when
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub use self::memorysink::{
|
|||||||
TrapSink,
|
TrapSink,
|
||||||
};
|
};
|
||||||
pub use self::stack_map::StackMap;
|
pub use self::stack_map::StackMap;
|
||||||
use crate::ir::{ExternalName, SourceLoc, TrapCode};
|
use crate::ir::{ExternalName, SourceLoc};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
#[cfg(feature = "enable-serde")]
|
#[cfg(feature = "enable-serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -110,7 +110,4 @@ pub trait CodeSink {
|
|||||||
|
|
||||||
/// Add a relocation referencing an external symbol plus the addend at the current offset.
|
/// Add a relocation referencing an external symbol plus the addend at the current offset.
|
||||||
fn reloc_external(&mut self, _: SourceLoc, _: Reloc, _: &ExternalName, _: Addend);
|
fn reloc_external(&mut self, _: SourceLoc, _: Reloc, _: &ExternalName, _: Addend);
|
||||||
|
|
||||||
/// Add trap information for the current offset.
|
|
||||||
fn trap(&mut self, _: TrapCode, _: SourceLoc);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use crate::isa::TargetIsa;
|
|||||||
use crate::legalizer::simple_legalize;
|
use crate::legalizer::simple_legalize;
|
||||||
use crate::licm::do_licm;
|
use crate::licm::do_licm;
|
||||||
use crate::loop_analysis::LoopAnalysis;
|
use crate::loop_analysis::LoopAnalysis;
|
||||||
use crate::machinst::{MachCompileResult, MachStackMap};
|
use crate::machinst::{MachCompileResult, MachStackMap, MachTrap};
|
||||||
use crate::nan_canonicalization::do_nan_canonicalization;
|
use crate::nan_canonicalization::do_nan_canonicalization;
|
||||||
use crate::remove_constant_phis::do_remove_constant_phis;
|
use crate::remove_constant_phis::do_remove_constant_phis;
|
||||||
use crate::result::CodegenResult;
|
use crate::result::CodegenResult;
|
||||||
@@ -194,16 +194,21 @@ impl Context {
|
|||||||
stack_maps: &mut dyn StackMapSink,
|
stack_maps: &mut dyn StackMapSink,
|
||||||
) -> CodeInfo {
|
) -> CodeInfo {
|
||||||
let _tt = timing::binemit();
|
let _tt = timing::binemit();
|
||||||
let mut sink = MemoryCodeSink::new(mem, relocs, traps);
|
let mut sink = MemoryCodeSink::new(mem, relocs);
|
||||||
let result = self
|
let result = self
|
||||||
.mach_compile_result
|
.mach_compile_result
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("only using mach backend now");
|
.expect("only using mach backend now");
|
||||||
result.buffer.emit(&mut sink);
|
result.buffer.emit(&mut sink);
|
||||||
let info = sink.info();
|
let info = sink.info();
|
||||||
// New backends do not emit StackMaps through the `CodeSink` because its interface
|
for &MachTrap {
|
||||||
// requires `Value`s; instead, the `StackMap` objects are directly accessible via
|
offset,
|
||||||
// `result.buffer.stack_maps()`.
|
srcloc,
|
||||||
|
code,
|
||||||
|
} in result.buffer.traps()
|
||||||
|
{
|
||||||
|
traps.trap(offset, srcloc, code);
|
||||||
|
}
|
||||||
for &MachStackMap {
|
for &MachStackMap {
|
||||||
offset_end,
|
offset_end,
|
||||||
ref stack_map,
|
ref stack_map,
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub mod verifier;
|
|||||||
pub mod write;
|
pub mod write;
|
||||||
|
|
||||||
pub use crate::entity::packed_option;
|
pub use crate::entity::packed_option;
|
||||||
pub use crate::machinst::buffer::{MachCallSite, MachSrcLoc};
|
pub use crate::machinst::buffer::{MachCallSite, MachSrcLoc, MachTrap};
|
||||||
pub use crate::machinst::TextSectionBuilder;
|
pub use crate::machinst::TextSectionBuilder;
|
||||||
|
|
||||||
mod bitset;
|
mod bitset;
|
||||||
|
|||||||
@@ -1449,7 +1449,6 @@ impl MachBufferFinalized {
|
|||||||
// to add the appropriate relocations in this case.
|
// to add the appropriate relocations in this case.
|
||||||
|
|
||||||
let mut next_reloc = 0;
|
let mut next_reloc = 0;
|
||||||
let mut next_trap = 0;
|
|
||||||
for (idx, byte) in self.data.iter().enumerate() {
|
for (idx, byte) in self.data.iter().enumerate() {
|
||||||
while next_reloc < self.relocs.len()
|
while next_reloc < self.relocs.len()
|
||||||
&& self.relocs[next_reloc].offset == idx as CodeOffset
|
&& self.relocs[next_reloc].offset == idx as CodeOffset
|
||||||
@@ -1458,16 +1457,15 @@ impl MachBufferFinalized {
|
|||||||
sink.reloc_external(reloc.srcloc, reloc.kind, &reloc.name, reloc.addend);
|
sink.reloc_external(reloc.srcloc, reloc.kind, &reloc.name, reloc.addend);
|
||||||
next_reloc += 1;
|
next_reloc += 1;
|
||||||
}
|
}
|
||||||
while next_trap < self.traps.len() && self.traps[next_trap].offset == idx as CodeOffset
|
|
||||||
{
|
|
||||||
let trap = &self.traps[next_trap];
|
|
||||||
sink.trap(trap.code, trap.srcloc);
|
|
||||||
next_trap += 1;
|
|
||||||
}
|
|
||||||
sink.put1(*byte);
|
sink.put1(*byte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the list of trap records for this code.
|
||||||
|
pub fn traps(&self) -> &[MachTrap] {
|
||||||
|
&self.traps[..]
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the stack map metadata for this code.
|
/// Get the stack map metadata for this code.
|
||||||
pub fn stack_maps(&self) -> &[MachStackMap] {
|
pub fn stack_maps(&self) -> &[MachStackMap] {
|
||||||
&self.stack_maps[..]
|
&self.stack_maps[..]
|
||||||
@@ -1521,14 +1519,14 @@ struct MachReloc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A trap record resulting from a compilation.
|
/// A trap record resulting from a compilation.
|
||||||
struct MachTrap {
|
pub struct MachTrap {
|
||||||
/// The offset at which the trap instruction occurs, *relative to the
|
/// The offset at which the trap instruction occurs, *relative to the
|
||||||
/// containing section*.
|
/// containing section*.
|
||||||
offset: CodeOffset,
|
pub offset: CodeOffset,
|
||||||
/// The original source location.
|
/// The original source location.
|
||||||
srcloc: SourceLoc,
|
pub srcloc: SourceLoc,
|
||||||
/// The trap code.
|
/// The trap code.
|
||||||
code: TrapCode,
|
pub code: TrapCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A call site record resulting from a compilation.
|
/// A call site record resulting from a compilation.
|
||||||
@@ -2074,7 +2072,6 @@ mod test {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TestCodeSink {
|
struct TestCodeSink {
|
||||||
offset: CodeOffset,
|
offset: CodeOffset,
|
||||||
traps: Vec<(CodeOffset, TrapCode)>,
|
|
||||||
relocs: Vec<(CodeOffset, Reloc)>,
|
relocs: Vec<(CodeOffset, Reloc)>,
|
||||||
}
|
}
|
||||||
impl CodeSink for TestCodeSink {
|
impl CodeSink for TestCodeSink {
|
||||||
@@ -2084,9 +2081,6 @@ mod test {
|
|||||||
fn reloc_external(&mut self, _: SourceLoc, r: Reloc, _: &ExternalName, _: Addend) {
|
fn reloc_external(&mut self, _: SourceLoc, r: Reloc, _: &ExternalName, _: Addend) {
|
||||||
self.relocs.push((self.offset, r));
|
self.relocs.push((self.offset, r));
|
||||||
}
|
}
|
||||||
fn trap(&mut self, t: TrapCode, _: SourceLoc) {
|
|
||||||
self.traps.push((self.offset, t));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sink = TestCodeSink::default();
|
let mut sink = TestCodeSink::default();
|
||||||
@@ -2094,7 +2088,10 @@ mod test {
|
|||||||
|
|
||||||
assert_eq!(sink.offset, 4);
|
assert_eq!(sink.offset, 4);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sink.traps,
|
buf.traps()
|
||||||
|
.iter()
|
||||||
|
.map(|trap| (trap.offset, trap.code))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
vec![
|
vec![
|
||||||
(1, TrapCode::HeapOutOfBounds),
|
(1, TrapCode::HeapOutOfBounds),
|
||||||
(2, TrapCode::IntegerOverflow),
|
(2, TrapCode::IntegerOverflow),
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ impl binemit::CodeSink for SizeSink {
|
|||||||
_addend: binemit::Addend,
|
_addend: binemit::Addend,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
fn trap(&mut self, _code: ir::TrapCode, _srcloc: ir::SourceLoc) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_precise_output(text: &str, context: &Context) -> Result<()> {
|
fn check_precise_output(text: &str, context: &Context) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user