Browse Source

Generalize def_inst() to def_entity().

Use this source map method for assigning a location to any entity whose
source number is not exposed. This could be

- Instructions.
- Signatures defined implicitly by function decls.

These entities only appear in the location map, not the entity number
maps.
pull/3/head
Jakob Stoklund Olesen 8 years ago
parent
commit
45cf655ce4
  1. 2
      lib/reader/src/parser.rs
  2. 28
      lib/reader/src/sourcemap.rs

2
lib/reader/src/parser.rs

@ -837,7 +837,7 @@ impl<'a> Parser<'a> {
let inst = ctx.function.dfg.make_inst(inst_data);
let num_results = ctx.function.dfg.make_inst_results(inst, ctrl_typevar);
ctx.function.layout.append_inst(inst, ebb);
ctx.map.def_inst(inst, &opcode_loc).expect("duplicate inst references created");
ctx.map.def_entity(inst.into(), &opcode_loc).expect("duplicate inst references created");
if results.len() != num_results {
return err!(self.loc,

28
lib/reader/src/sourcemap.rs

@ -8,7 +8,7 @@
//! clients.
use std::collections::HashMap;
use cretonne::ir::{StackSlot, JumpTable, Ebb, Value, Inst};
use cretonne::ir::{StackSlot, JumpTable, Ebb, Value};
use cretonne::ir::entities::AnyEntity;
use error::{Result, Location};
use lexer::split_entity_name;
@ -128,9 +128,9 @@ pub trait MutableSourceMap {
fn def_ss(&mut self, src_num: u32, entity: StackSlot, loc: &Location) -> Result<()>;
fn def_jt(&mut self, src_num: u32, entity: JumpTable, loc: &Location) -> Result<()>;
/// Define an instruction. Since instruction numbers never appear in source, only the location
/// is recorded.
fn def_inst(&mut self, entity: Inst, loc: &Location) -> Result<()>;
/// Define an entity without an associated source number. This can be used for instructions
/// whose numbers never appear in source, or implicitly defined signatures.
fn def_entity(&mut self, entity: AnyEntity, loc: &Location) -> Result<()>;
}
impl MutableSourceMap for SourceMap {
@ -147,45 +147,37 @@ impl MutableSourceMap for SourceMap {
fn def_value(&mut self, src: Value, entity: Value, loc: &Location) -> Result<()> {
if self.values.insert(src, entity).is_some() {
err!(loc, "duplicate value: {}", src)
} else if self.locations.insert(entity.into(), loc.clone()).is_some() {
err!(loc, "duplicate entity: {}", entity)
} else {
Ok(())
self.def_entity(entity.into(), loc)
}
}
fn def_ebb(&mut self, src: Ebb, entity: Ebb, loc: &Location) -> Result<()> {
if self.ebbs.insert(src, entity).is_some() {
err!(loc, "duplicate EBB: {}", src)
} else if self.locations.insert(entity.into(), loc.clone()).is_some() {
err!(loc, "duplicate entity: {}", entity)
} else {
Ok(())
self.def_entity(entity.into(), loc)
}
}
fn def_ss(&mut self, src_num: u32, entity: StackSlot, loc: &Location) -> Result<()> {
if self.stack_slots.insert(src_num, entity).is_some() {
err!(loc, "duplicate stack slot: ss{}", src_num)
} else if self.locations.insert(entity.into(), loc.clone()).is_some() {
err!(loc, "duplicate entity: {}", entity)
} else {
Ok(())
self.def_entity(entity.into(), loc)
}
}
fn def_jt(&mut self, src_num: u32, entity: JumpTable, loc: &Location) -> Result<()> {
if self.jump_tables.insert(src_num, entity).is_some() {
err!(loc, "duplicate jump table: jt{}", src_num)
} else if self.locations.insert(entity.into(), loc.clone()).is_some() {
err!(loc, "duplicate entity: {}", entity)
} else {
Ok(())
self.def_entity(entity.into(), loc)
}
}
fn def_inst(&mut self, entity: Inst, loc: &Location) -> Result<()> {
if self.locations.insert(entity.into(), loc.clone()).is_some() {
fn def_entity(&mut self, entity: AnyEntity, loc: &Location) -> Result<()> {
if self.locations.insert(entity, loc.clone()).is_some() {
err!(loc, "duplicate entity: {}", entity)
} else {
Ok(())

Loading…
Cancel
Save