Remove code offsets from Function (#3412)
* Remove code offsets from Function * Remove reloc_jt and fix wasmtime-cranelift
This commit is contained in:
@@ -11,10 +11,7 @@ pub use self::memorysink::{
|
||||
TrapSink,
|
||||
};
|
||||
pub use self::stack_map::StackMap;
|
||||
use crate::ir::{
|
||||
ConstantOffset, ExternalName, Function, Inst, JumpTable, Opcode, SourceLoc, TrapCode,
|
||||
};
|
||||
use crate::isa::TargetIsa;
|
||||
use crate::ir::{ConstantOffset, ExternalName, Opcode, SourceLoc, TrapCode};
|
||||
use core::fmt;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -153,9 +150,6 @@ pub trait CodeSink {
|
||||
/// Add a relocation referencing a constant.
|
||||
fn reloc_constant(&mut self, _: Reloc, _: ConstantOffset);
|
||||
|
||||
/// Add a relocation referencing a jump table.
|
||||
fn reloc_jt(&mut self, _: Reloc, _: JumpTable);
|
||||
|
||||
/// Add trap information for the current offset.
|
||||
fn trap(&mut self, _: TrapCode, _: SourceLoc);
|
||||
|
||||
@@ -173,42 +167,3 @@ pub trait CodeSink {
|
||||
// Default implementation doesn't need to do anything.
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit a function to `sink`, given an instruction emitter function.
|
||||
///
|
||||
/// This function is called from the `TargetIsa::emit_function()` implementations with the
|
||||
/// appropriate instruction emitter.
|
||||
pub fn emit_function<CS, EI>(func: &Function, emit_inst: EI, sink: &mut CS, isa: &dyn TargetIsa)
|
||||
where
|
||||
CS: CodeSink,
|
||||
EI: Fn(&Function, Inst, &mut CS, &dyn TargetIsa),
|
||||
{
|
||||
for block in func.layout.blocks() {
|
||||
debug_assert_eq!(func.offsets[block], sink.offset());
|
||||
for inst in func.layout.block_insts(block) {
|
||||
emit_inst(func, inst, sink, isa);
|
||||
}
|
||||
}
|
||||
|
||||
sink.begin_jumptables();
|
||||
|
||||
// Output jump tables.
|
||||
for (jt, jt_data) in func.jump_tables.iter() {
|
||||
let jt_offset = func.jt_offsets[jt];
|
||||
for block in jt_data.iter() {
|
||||
let rel_offset: i32 = func.offsets[*block] as i32 - jt_offset as i32;
|
||||
sink.put4(rel_offset as u32)
|
||||
}
|
||||
}
|
||||
|
||||
sink.begin_rodata();
|
||||
|
||||
// Output constants.
|
||||
for (_, constant_data) in func.dfg.constants.iter() {
|
||||
for byte in constant_data.iter() {
|
||||
sink.put1(*byte)
|
||||
}
|
||||
}
|
||||
|
||||
sink.end_codegen();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user