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: isize,
|
||||
relocs: &'a mut dyn RelocSink,
|
||||
traps: &'a mut dyn TrapSink,
|
||||
}
|
||||
|
||||
impl<'a> MemoryCodeSink<'a> {
|
||||
@@ -48,13 +47,11 @@ impl<'a> MemoryCodeSink<'a> {
|
||||
pub unsafe fn new(
|
||||
data: *mut u8,
|
||||
relocs: &'a mut dyn RelocSink,
|
||||
traps: &'a mut dyn TrapSink,
|
||||
) -> Self {
|
||||
Self {
|
||||
data,
|
||||
offset: 0,
|
||||
relocs,
|
||||
traps,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,11 +103,6 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
|
||||
let ofs = self.offset as CodeOffset;
|
||||
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
|
||||
|
||||
@@ -11,7 +11,7 @@ pub use self::memorysink::{
|
||||
TrapSink,
|
||||
};
|
||||
pub use self::stack_map::StackMap;
|
||||
use crate::ir::{ExternalName, SourceLoc, TrapCode};
|
||||
use crate::ir::{ExternalName, SourceLoc};
|
||||
use core::fmt;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
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.
|
||||
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::licm::do_licm;
|
||||
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::remove_constant_phis::do_remove_constant_phis;
|
||||
use crate::result::CodegenResult;
|
||||
@@ -194,16 +194,21 @@ impl Context {
|
||||
stack_maps: &mut dyn StackMapSink,
|
||||
) -> CodeInfo {
|
||||
let _tt = timing::binemit();
|
||||
let mut sink = MemoryCodeSink::new(mem, relocs, traps);
|
||||
let mut sink = MemoryCodeSink::new(mem, relocs);
|
||||
let result = self
|
||||
.mach_compile_result
|
||||
.as_ref()
|
||||
.expect("only using mach backend now");
|
||||
result.buffer.emit(&mut sink);
|
||||
let info = sink.info();
|
||||
// New backends do not emit StackMaps through the `CodeSink` because its interface
|
||||
// requires `Value`s; instead, the `StackMap` objects are directly accessible via
|
||||
// `result.buffer.stack_maps()`.
|
||||
for &MachTrap {
|
||||
offset,
|
||||
srcloc,
|
||||
code,
|
||||
} in result.buffer.traps()
|
||||
{
|
||||
traps.trap(offset, srcloc, code);
|
||||
}
|
||||
for &MachStackMap {
|
||||
offset_end,
|
||||
ref stack_map,
|
||||
|
||||
@@ -88,7 +88,7 @@ pub mod verifier;
|
||||
pub mod write;
|
||||
|
||||
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;
|
||||
|
||||
mod bitset;
|
||||
|
||||
@@ -1449,7 +1449,6 @@ impl MachBufferFinalized {
|
||||
// to add the appropriate relocations in this case.
|
||||
|
||||
let mut next_reloc = 0;
|
||||
let mut next_trap = 0;
|
||||
for (idx, byte) in self.data.iter().enumerate() {
|
||||
while next_reloc < self.relocs.len()
|
||||
&& 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the list of trap records for this code.
|
||||
pub fn traps(&self) -> &[MachTrap] {
|
||||
&self.traps[..]
|
||||
}
|
||||
|
||||
/// Get the stack map metadata for this code.
|
||||
pub fn stack_maps(&self) -> &[MachStackMap] {
|
||||
&self.stack_maps[..]
|
||||
@@ -1521,14 +1519,14 @@ struct MachReloc {
|
||||
}
|
||||
|
||||
/// A trap record resulting from a compilation.
|
||||
struct MachTrap {
|
||||
pub struct MachTrap {
|
||||
/// The offset at which the trap instruction occurs, *relative to the
|
||||
/// containing section*.
|
||||
offset: CodeOffset,
|
||||
pub offset: CodeOffset,
|
||||
/// The original source location.
|
||||
srcloc: SourceLoc,
|
||||
pub srcloc: SourceLoc,
|
||||
/// The trap code.
|
||||
code: TrapCode,
|
||||
pub code: TrapCode,
|
||||
}
|
||||
|
||||
/// A call site record resulting from a compilation.
|
||||
@@ -2074,7 +2072,6 @@ mod test {
|
||||
#[derive(Default)]
|
||||
struct TestCodeSink {
|
||||
offset: CodeOffset,
|
||||
traps: Vec<(CodeOffset, TrapCode)>,
|
||||
relocs: Vec<(CodeOffset, Reloc)>,
|
||||
}
|
||||
impl CodeSink for TestCodeSink {
|
||||
@@ -2084,9 +2081,6 @@ mod test {
|
||||
fn reloc_external(&mut self, _: SourceLoc, r: Reloc, _: &ExternalName, _: Addend) {
|
||||
self.relocs.push((self.offset, r));
|
||||
}
|
||||
fn trap(&mut self, t: TrapCode, _: SourceLoc) {
|
||||
self.traps.push((self.offset, t));
|
||||
}
|
||||
}
|
||||
|
||||
let mut sink = TestCodeSink::default();
|
||||
@@ -2094,7 +2088,10 @@ mod test {
|
||||
|
||||
assert_eq!(sink.offset, 4);
|
||||
assert_eq!(
|
||||
sink.traps,
|
||||
buf.traps()
|
||||
.iter()
|
||||
.map(|trap| (trap.offset, trap.code))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![
|
||||
(1, TrapCode::HeapOutOfBounds),
|
||||
(2, TrapCode::IntegerOverflow),
|
||||
|
||||
Reference in New Issue
Block a user