Browse Source

Track signatures and function references in the source map.

pull/3/head
Jakob Stoklund Olesen 8 years ago
parent
commit
8055ac681c
  1. 36
      lib/reader/src/sourcemap.rs

36
lib/reader/src/sourcemap.rs

@ -8,7 +8,7 @@
//! clients. //! clients.
use std::collections::HashMap; use std::collections::HashMap;
use cretonne::ir::{StackSlot, JumpTable, Ebb, Value}; use cretonne::ir::{StackSlot, JumpTable, Ebb, Value, SigRef, FuncRef};
use cretonne::ir::entities::AnyEntity; use cretonne::ir::entities::AnyEntity;
use error::{Result, Location}; use error::{Result, Location};
use lexer::split_entity_name; use lexer::split_entity_name;
@ -19,6 +19,8 @@ pub struct SourceMap {
values: HashMap<Value, Value>, // vNN, vxNN values: HashMap<Value, Value>, // vNN, vxNN
ebbs: HashMap<Ebb, Ebb>, // ebbNN ebbs: HashMap<Ebb, Ebb>, // ebbNN
stack_slots: HashMap<u32, StackSlot>, // ssNN stack_slots: HashMap<u32, StackSlot>, // ssNN
signatures: HashMap<u32, SigRef>, // sigNN
functions: HashMap<u32, FuncRef>, // fnNN
jump_tables: HashMap<u32, JumpTable>, // jtNN jump_tables: HashMap<u32, JumpTable>, // jtNN
// Store locations for entities, including instructions. // Store locations for entities, including instructions.
@ -42,6 +44,16 @@ impl SourceMap {
self.stack_slots.get(&src_num).cloned() self.stack_slots.get(&src_num).cloned()
} }
/// Look up a signature entity by its source number.
pub fn get_sig(&self, src_num: u32) -> Option<SigRef> {
self.signatures.get(&src_num).cloned()
}
/// Look up a function entity by its source number.
pub fn get_fn(&self, src_num: u32) -> Option<FuncRef> {
self.functions.get(&src_num).cloned()
}
/// Look up a jump table entity by its source number. /// Look up a jump table entity by its source number.
pub fn get_jt(&self, src_num: u32) -> Option<JumpTable> { pub fn get_jt(&self, src_num: u32) -> Option<JumpTable> {
self.jump_tables.get(&src_num).cloned() self.jump_tables.get(&src_num).cloned()
@ -64,6 +76,8 @@ impl SourceMap {
} }
"ebb" => Ebb::with_number(num).and_then(|e| self.get_ebb(e)).map(AnyEntity::Ebb), "ebb" => Ebb::with_number(num).and_then(|e| self.get_ebb(e)).map(AnyEntity::Ebb),
"ss" => self.get_ss(num).map(AnyEntity::StackSlot), "ss" => self.get_ss(num).map(AnyEntity::StackSlot),
"sig" => self.get_sig(num).map(AnyEntity::SigRef),
"fn" => self.get_fn(num).map(AnyEntity::FuncRef),
"jt" => self.get_jt(num).map(AnyEntity::JumpTable), "jt" => self.get_jt(num).map(AnyEntity::JumpTable),
_ => None, _ => None,
} }
@ -126,6 +140,8 @@ pub trait MutableSourceMap {
fn def_value(&mut self, src: Value, entity: Value, loc: &Location) -> Result<()>; fn def_value(&mut self, src: Value, entity: Value, loc: &Location) -> Result<()>;
fn def_ebb(&mut self, src: Ebb, entity: Ebb, loc: &Location) -> Result<()>; fn def_ebb(&mut self, src: Ebb, entity: Ebb, loc: &Location) -> Result<()>;
fn def_ss(&mut self, src_num: u32, entity: StackSlot, loc: &Location) -> Result<()>; fn def_ss(&mut self, src_num: u32, entity: StackSlot, loc: &Location) -> Result<()>;
fn def_sig(&mut self, src_num: u32, entity: SigRef, loc: &Location) -> Result<()>;
fn def_fn(&mut self, src_num: u32, entity: FuncRef, loc: &Location) -> Result<()>;
fn def_jt(&mut self, src_num: u32, entity: JumpTable, loc: &Location) -> Result<()>; fn def_jt(&mut self, src_num: u32, entity: JumpTable, loc: &Location) -> Result<()>;
/// Define an entity without an associated source number. This can be used for instructions /// Define an entity without an associated source number. This can be used for instructions
@ -139,6 +155,8 @@ impl MutableSourceMap for SourceMap {
values: HashMap::new(), values: HashMap::new(),
ebbs: HashMap::new(), ebbs: HashMap::new(),
stack_slots: HashMap::new(), stack_slots: HashMap::new(),
signatures: HashMap::new(),
functions: HashMap::new(),
jump_tables: HashMap::new(), jump_tables: HashMap::new(),
locations: HashMap::new(), locations: HashMap::new(),
} }
@ -168,6 +186,22 @@ impl MutableSourceMap for SourceMap {
} }
} }
fn def_sig(&mut self, src_num: u32, entity: SigRef, loc: &Location) -> Result<()> {
if self.signatures.insert(src_num, entity).is_some() {
err!(loc, "duplicate signature: sig{}", src_num)
} else {
self.def_entity(entity.into(), loc)
}
}
fn def_fn(&mut self, src_num: u32, entity: FuncRef, loc: &Location) -> Result<()> {
if self.functions.insert(src_num, entity).is_some() {
err!(loc, "duplicate function: fn{}", src_num)
} else {
self.def_entity(entity.into(), loc)
}
}
fn def_jt(&mut self, src_num: u32, entity: JumpTable, loc: &Location) -> Result<()> { fn def_jt(&mut self, src_num: u32, entity: JumpTable, loc: &Location) -> Result<()> {
if self.jump_tables.insert(src_num, entity).is_some() { if self.jump_tables.insert(src_num, entity).is_some() {
err!(loc, "duplicate jump table: jt{}", src_num) err!(loc, "duplicate jump table: jt{}", src_num)

Loading…
Cancel
Save