WIP.
This commit is contained in:
parent
3dc1356669
commit
a73dacd5df
|
@ -131,9 +131,7 @@ fn parse_body<'a>(
|
||||||
for (arg_idx, &arg_ty) in module.signature(my_sig).params.iter().enumerate() {
|
for (arg_idx, &arg_ty) in module.signature(my_sig).params.iter().enumerate() {
|
||||||
let local_idx = Local::new(arg_idx);
|
let local_idx = Local::new(arg_idx);
|
||||||
builder.body.add_blockparam(entry, arg_ty);
|
builder.body.add_blockparam(entry, arg_ty);
|
||||||
let value = builder
|
let value = builder.body.blocks[entry].params.last().unwrap().1;
|
||||||
.body
|
|
||||||
.add_value(ValueDef::BlockParam(entry, arg_idx, arg_ty));
|
|
||||||
trace!("defining local {} to value {}", local_idx, value);
|
trace!("defining local {} to value {}", local_idx, value);
|
||||||
builder.locals.declare(local_idx, arg_ty);
|
builder.locals.declare(local_idx, arg_ty);
|
||||||
builder.locals.set(local_idx, value);
|
builder.locals.set(local_idx, value);
|
||||||
|
@ -321,6 +319,12 @@ impl LocalTracker {
|
||||||
_ => todo!("unsupported type: {:?}", ty),
|
_ => todo!("unsupported type: {:?}", ty),
|
||||||
};
|
};
|
||||||
body.blocks[at_block].insts.push(val);
|
body.blocks[at_block].insts.push(val);
|
||||||
|
log::trace!(
|
||||||
|
"created default value {} of type {} at block {}",
|
||||||
|
val,
|
||||||
|
ty,
|
||||||
|
at_block
|
||||||
|
);
|
||||||
val
|
val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,11 @@ use super::{FuncDecl, FunctionBody, Module, ValueDef};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||||
|
|
||||||
pub struct FunctionBodyDisplay<'a>(pub(crate) &'a FunctionBody, pub(crate) &'a str);
|
pub struct FunctionBodyDisplay<'a>(
|
||||||
|
pub(crate) &'a FunctionBody,
|
||||||
|
pub(crate) &'a str,
|
||||||
|
pub(crate) bool,
|
||||||
|
);
|
||||||
|
|
||||||
impl<'a> Display for FunctionBodyDisplay<'a> {
|
impl<'a> Display for FunctionBodyDisplay<'a> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||||
|
@ -29,10 +33,34 @@ impl<'a> Display for FunctionBodyDisplay<'a> {
|
||||||
ret_tys.join(", ")
|
ret_tys.join(", ")
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let verbose = self.2;
|
||||||
for (value, value_def) in self.0.values.entries() {
|
for (value, value_def) in self.0.values.entries() {
|
||||||
match value_def {
|
match value_def {
|
||||||
ValueDef::Operator(..) | ValueDef::BlockParam(..) => {}
|
ValueDef::Operator(op, args, tys) if verbose => writeln!(
|
||||||
ValueDef::Alias(_alias_target) => {}
|
f,
|
||||||
|
"{} {} = {} {} # {}",
|
||||||
|
self.1,
|
||||||
|
value,
|
||||||
|
op,
|
||||||
|
args.iter()
|
||||||
|
.map(|arg| format!("{}", arg))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", "),
|
||||||
|
tys.iter()
|
||||||
|
.map(|arg| format!("{}", arg))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)?,
|
||||||
|
ValueDef::BlockParam(block, idx, ty) if verbose => writeln!(
|
||||||
|
f,
|
||||||
|
"{} {} = blockparam {}, {} # {}",
|
||||||
|
self.1, value, block, idx, ty
|
||||||
|
)?,
|
||||||
|
ValueDef::Alias(alias_target) => {
|
||||||
|
if verbose {
|
||||||
|
writeln!(f, "{} {} = {}", self.1, value, alias_target)?
|
||||||
|
}
|
||||||
|
}
|
||||||
ValueDef::PickOutput(val, idx, ty) => {
|
ValueDef::PickOutput(val, idx, ty) => {
|
||||||
writeln!(f, "{} {} = {}.{} # {}", self.1, value, val, idx, ty)?
|
writeln!(f, "{} {} = {}.{} # {}", self.1, value, val, idx, ty)?
|
||||||
}
|
}
|
||||||
|
@ -40,6 +68,7 @@ impl<'a> Display for FunctionBodyDisplay<'a> {
|
||||||
writeln!(f, "{} {} = placeholder # {}", self.1, value, ty)?
|
writeln!(f, "{} {} = placeholder # {}", self.1, value, ty)?
|
||||||
}
|
}
|
||||||
ValueDef::None => panic!(),
|
ValueDef::None => panic!(),
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,9 @@ impl FunctionBody {
|
||||||
|
|
||||||
pub fn add_value(&mut self, value: ValueDef) -> Value {
|
pub fn add_value(&mut self, value: ValueDef) -> Value {
|
||||||
log::trace!("add_value: def {:?}", value);
|
log::trace!("add_value: def {:?}", value);
|
||||||
self.values.push(value)
|
let value = self.values.push(value);
|
||||||
|
log::trace!(" -> {}", value);
|
||||||
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_alias(&mut self, value: Value, to: Value) {
|
pub fn set_alias(&mut self, value: Value, to: Value) {
|
||||||
|
@ -140,7 +142,11 @@ impl FunctionBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display<'a>(&'a self, indent: &'a str) -> FunctionBodyDisplay<'a> {
|
pub fn display<'a>(&'a self, indent: &'a str) -> FunctionBodyDisplay<'a> {
|
||||||
FunctionBodyDisplay(self, indent)
|
FunctionBodyDisplay(self, indent, /* verbose = */ false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn display_verbose<'a>(&'a self, indent: &'a str) -> FunctionBodyDisplay<'a> {
|
||||||
|
FunctionBodyDisplay(self, indent, /* verbose = */ true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue