Show srclocs
This commit is contained in:
parent
cfc758900d
commit
df19820693
|
@ -31,7 +31,7 @@ macro_rules! op {
|
||||||
impl<'a> WasmFuncBackend<'a> {
|
impl<'a> WasmFuncBackend<'a> {
|
||||||
pub fn new(body: &'a FunctionBody) -> Result<WasmFuncBackend<'a>> {
|
pub fn new(body: &'a FunctionBody) -> Result<WasmFuncBackend<'a>> {
|
||||||
body.validate()?;
|
body.validate()?;
|
||||||
log::debug!("Backend compiling:\n{}\n", body.display_verbose("| "));
|
log::debug!("Backend compiling:\n{}\n", body.display_verbose("| ", None));
|
||||||
let cfg = CFGInfo::new(body);
|
let cfg = CFGInfo::new(body);
|
||||||
log::debug!("CFG:\n{:?}\n", cfg);
|
log::debug!("CFG:\n{:?}\n", cfg);
|
||||||
let trees = Trees::compute(body);
|
let trees = Trees::compute(body);
|
||||||
|
|
|
@ -373,7 +373,7 @@ impl<'a> DebugLocReader<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_loc(&mut self, offset: usize) -> SourceLoc {
|
fn get_loc(&mut self, offset: usize) -> SourceLoc {
|
||||||
let offset = u32::try_from(offset).unwrap();
|
let offset = u32::try_from(offset).unwrap() + self.code_offset;
|
||||||
while self.locs.len() > 0 {
|
while self.locs.len() > 0 {
|
||||||
let (start, len, loc) = self.locs[0];
|
let (start, len, loc) = self.locs[0];
|
||||||
if offset < start {
|
if offset < start {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! Displaying IR.
|
//! Displaying IR.
|
||||||
|
|
||||||
use super::{FuncDecl, FunctionBody, Module, ValueDef};
|
use super::{FuncDecl, FunctionBody, Module, SourceLoc, ValueDef};
|
||||||
|
use crate::entity::EntityRef;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ pub struct FunctionBodyDisplay<'a>(
|
||||||
pub(crate) &'a FunctionBody,
|
pub(crate) &'a FunctionBody,
|
||||||
pub(crate) &'a str,
|
pub(crate) &'a str,
|
||||||
pub(crate) bool,
|
pub(crate) bool,
|
||||||
|
pub(crate) Option<&'a Module<'a>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<'a> Display for FunctionBodyDisplay<'a> {
|
impl<'a> Display for FunctionBodyDisplay<'a> {
|
||||||
|
@ -121,15 +123,26 @@ impl<'a> Display for FunctionBodyDisplay<'a> {
|
||||||
ValueDef::Operator(op, args, tys) => {
|
ValueDef::Operator(op, args, tys) => {
|
||||||
let args = args.iter().map(|&v| format!("{}", v)).collect::<Vec<_>>();
|
let args = args.iter().map(|&v| format!("{}", v)).collect::<Vec<_>>();
|
||||||
let tys = tys.iter().map(|&ty| format!("{}", ty)).collect::<Vec<_>>();
|
let tys = tys.iter().map(|&ty| format!("{}", ty)).collect::<Vec<_>>();
|
||||||
|
let loc = if self.0.source_locs[inst] != SourceLoc::invalid()
|
||||||
|
&& self.3.is_some()
|
||||||
|
{
|
||||||
|
let module = self.3.as_ref().unwrap();
|
||||||
|
let loc = self.0.source_locs[inst];
|
||||||
|
let data = &module.debug.source_locs[loc];
|
||||||
|
let filename = &module.debug.source_files[data.file];
|
||||||
|
format!("@{} {}:{}:{}", loc, filename, data.line, data.col)
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
};
|
||||||
writeln!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
"{} {} = {} {} # {} @{}",
|
"{} {} = {} {} # {} {}",
|
||||||
self.1,
|
self.1,
|
||||||
inst,
|
inst,
|
||||||
op,
|
op,
|
||||||
args.join(", "),
|
args.join(", "),
|
||||||
tys.join(", "),
|
tys.join(", "),
|
||||||
self.0.source_locs[inst],
|
loc,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
ValueDef::PickOutput(val, idx, ty) => {
|
ValueDef::PickOutput(val, idx, ty) => {
|
||||||
|
@ -226,7 +239,7 @@ impl<'a> Display for ModuleDisplay<'a> {
|
||||||
sig,
|
sig,
|
||||||
sig_strs.get(&sig).unwrap()
|
sig_strs.get(&sig).unwrap()
|
||||||
)?;
|
)?;
|
||||||
writeln!(f, "{}", body.display(" "))?;
|
writeln!(f, "{}", body.display(" ", Some(self.0)))?;
|
||||||
}
|
}
|
||||||
FuncDecl::Lazy(sig, name, reader) => {
|
FuncDecl::Lazy(sig, name, reader) => {
|
||||||
writeln!(
|
writeln!(
|
||||||
|
|
|
@ -265,12 +265,20 @@ impl FunctionBody {
|
||||||
self.locals.push(ty)
|
self.locals.push(ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display<'a>(&'a self, indent: &'a str) -> FunctionBodyDisplay<'a> {
|
pub fn display<'a>(
|
||||||
FunctionBodyDisplay(self, indent, /* verbose = */ false)
|
&'a self,
|
||||||
|
indent: &'a str,
|
||||||
|
module: Option<&'a Module>,
|
||||||
|
) -> FunctionBodyDisplay<'a> {
|
||||||
|
FunctionBodyDisplay(self, indent, /* verbose = */ false, module)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display_verbose<'a>(&'a self, indent: &'a str) -> FunctionBodyDisplay<'a> {
|
pub fn display_verbose<'a>(
|
||||||
FunctionBodyDisplay(self, indent, /* verbose = */ true)
|
&'a self,
|
||||||
|
indent: &'a str,
|
||||||
|
module: Option<&'a Module>,
|
||||||
|
) -> FunctionBodyDisplay<'a> {
|
||||||
|
FunctionBodyDisplay(self, indent, /* verbose = */ true, module)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validate(&self) -> anyhow::Result<()> {
|
pub fn validate(&self) -> anyhow::Result<()> {
|
||||||
|
@ -358,7 +366,7 @@ impl FunctionBody {
|
||||||
if bad.len() > 0 {
|
if bad.len() > 0 {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Body is:\n{}\nError(s) in SSA: {:?}",
|
"Body is:\n{}\nError(s) in SSA: {:?}",
|
||||||
self.display_verbose(" | "),
|
self.display_verbose(" | ", None),
|
||||||
bad
|
bad
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{FunctionBody, ValueDef};
|
||||||
pub fn run(body: &mut FunctionBody) {
|
pub fn run(body: &mut FunctionBody) {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Resolve aliases: running on:\n{}\n",
|
"Resolve aliases: running on:\n{}\n",
|
||||||
body.display_verbose("| ")
|
body.display_verbose("| ", None),
|
||||||
);
|
);
|
||||||
for value in body.values.iter() {
|
for value in body.values.iter() {
|
||||||
let mut value_def = std::mem::take(&mut body.values[value]);
|
let mut value_def = std::mem::take(&mut body.values[value]);
|
||||||
|
|
Loading…
Reference in a new issue