Merge reloc_func and reloc_globalsym into reloc_external.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
//! relocations to a `RelocSink` trait object. Relocations are less frequent than the
|
||||
//! `CodeSink::put*` methods, so the performance impact of the virtual callbacks is less severe.
|
||||
|
||||
use ir::{Ebb, FuncRef, GlobalVar, JumpTable};
|
||||
use ir::{ExternalName, Ebb, JumpTable};
|
||||
use super::{CodeSink, CodeOffset, Reloc};
|
||||
use std::ptr::write_unaligned;
|
||||
|
||||
@@ -51,12 +51,8 @@ pub trait RelocSink {
|
||||
/// Add a relocation referencing an EBB at the current offset.
|
||||
fn reloc_ebb(&mut self, CodeOffset, Reloc, Ebb);
|
||||
|
||||
/// Add a relocation referencing an external function at the current offset.
|
||||
fn reloc_func(&mut self, CodeOffset, Reloc, FuncRef);
|
||||
|
||||
/// Add a relocation referencing an external global variable symbol at the
|
||||
/// current offset.
|
||||
fn reloc_globalsym(&mut self, CodeOffset, Reloc, GlobalVar);
|
||||
/// Add a relocation referencing an external symbol at the current offset.
|
||||
fn reloc_external(&mut self, CodeOffset, Reloc, &ExternalName);
|
||||
|
||||
/// Add a relocation referencing a jump table.
|
||||
fn reloc_jt(&mut self, CodeOffset, Reloc, JumpTable);
|
||||
@@ -100,14 +96,9 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
|
||||
self.relocs.reloc_ebb(ofs, rel, ebb);
|
||||
}
|
||||
|
||||
fn reloc_func(&mut self, rel: Reloc, func: FuncRef) {
|
||||
fn reloc_external(&mut self, rel: Reloc, name: &ExternalName) {
|
||||
let ofs = self.offset();
|
||||
self.relocs.reloc_func(ofs, rel, func);
|
||||
}
|
||||
|
||||
fn reloc_globalsym(&mut self, rel: Reloc, global: GlobalVar) {
|
||||
let ofs = self.offset();
|
||||
self.relocs.reloc_globalsym(ofs, rel, global);
|
||||
self.relocs.reloc_external(ofs, rel, name);
|
||||
}
|
||||
|
||||
fn reloc_jt(&mut self, rel: Reloc, jt: JumpTable) {
|
||||
|
||||
@@ -9,7 +9,7 @@ mod memorysink;
|
||||
pub use self::relaxation::relax_branches;
|
||||
pub use self::memorysink::{MemoryCodeSink, RelocSink};
|
||||
|
||||
use ir::{Ebb, FuncRef, GlobalVar, JumpTable, Function, Inst};
|
||||
use ir::{ExternalName, Ebb, JumpTable, Function, Inst};
|
||||
use regalloc::RegDiversions;
|
||||
|
||||
/// Offset in bytes from the beginning of the function.
|
||||
@@ -44,12 +44,8 @@ pub trait CodeSink {
|
||||
/// Add a relocation referencing an EBB at the current offset.
|
||||
fn reloc_ebb(&mut self, Reloc, Ebb);
|
||||
|
||||
/// Add a relocation referencing an external function at the current offset.
|
||||
fn reloc_func(&mut self, Reloc, FuncRef);
|
||||
|
||||
/// Add a relocation referencing an external global variable symbol at the
|
||||
/// current offset. This is only used for `GlobalVarData::Sym` globals.
|
||||
fn reloc_globalsym(&mut self, Reloc, GlobalVar);
|
||||
/// Add a relocation referencing an external symbol at the current offset.
|
||||
fn reloc_external(&mut self, Reloc, &ExternalName);
|
||||
|
||||
/// Add a relocation referencing a jump table.
|
||||
fn reloc_jt(&mut self, Reloc, JumpTable);
|
||||
|
||||
@@ -35,6 +35,16 @@ pub enum GlobalVarData {
|
||||
},
|
||||
}
|
||||
|
||||
impl GlobalVarData {
|
||||
/// Assume that `self` is an `GlobalVarData::Sym` and return its name.
|
||||
pub fn symbol_name(&self) -> &ExternalName {
|
||||
match *self {
|
||||
GlobalVarData::Sym { ref name } => name,
|
||||
_ => panic!("only symbols have names"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for GlobalVarData {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
|
||||
Reference in New Issue
Block a user