WIP.
This commit is contained in:
parent
003650281a
commit
e53d801107
|
@ -452,7 +452,7 @@ impl LocalTracker {
|
||||||
)),
|
)),
|
||||||
_ => todo!("unsupported type: {:?}", ty),
|
_ => todo!("unsupported type: {:?}", ty),
|
||||||
};
|
};
|
||||||
body.blocks[at_block].insts.push(val);
|
body.append_to_block(at_block, val);
|
||||||
log::trace!(
|
log::trace!(
|
||||||
"created default value {} of type {} at block {}",
|
"created default value {} of type {} at block {}",
|
||||||
val,
|
val,
|
||||||
|
@ -1342,7 +1342,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
log::trace!(" -> value: {:?}", value);
|
log::trace!(" -> value: {:?}", value);
|
||||||
|
|
||||||
if let Some(block) = self.cur_block {
|
if let Some(block) = self.cur_block {
|
||||||
self.body.blocks[block].insts.push(value);
|
self.body.append_to_block(block, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if n_outputs == 1 {
|
if n_outputs == 1 {
|
||||||
|
@ -1354,7 +1354,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
.body
|
.body
|
||||||
.add_value(ValueDef::PickOutput(value, i, output_ty));
|
.add_value(ValueDef::PickOutput(value, i, output_ty));
|
||||||
if let Some(block) = self.cur_block {
|
if let Some(block) = self.cur_block {
|
||||||
self.body.blocks[block].insts.push(pick);
|
self.body.append_to_block(block, pick);
|
||||||
}
|
}
|
||||||
self.op_stack.push((output_ty, pick));
|
self.op_stack.push((output_ty, pick));
|
||||||
log::trace!(" -> pick {}: {:?} ty {:?}", i, pick, output_ty);
|
log::trace!(" -> pick {}: {:?} ty {:?}", i, pick, output_ty);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{Block, FunctionBodyDisplay, Local, Module, Signature, Type, Value, ValueDef};
|
use super::{Block, FunctionBodyDisplay, Local, Module, Signature, Type, Value, ValueDef};
|
||||||
use crate::entity::EntityVec;
|
use crate::entity::{EntityVec, PerEntity};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum FuncDecl {
|
pub enum FuncDecl {
|
||||||
|
@ -45,6 +45,8 @@ pub struct FunctionBody {
|
||||||
pub blocks: EntityVec<Block, BlockDef>,
|
pub blocks: EntityVec<Block, BlockDef>,
|
||||||
/// Value definitions, indexed by `Value`.
|
/// Value definitions, indexed by `Value`.
|
||||||
pub values: EntityVec<Value, ValueDef>,
|
pub values: EntityVec<Value, ValueDef>,
|
||||||
|
/// Blocks in which values are computed. Each may be `Block::invalid()` if not placed.
|
||||||
|
pub value_blocks: PerEntity<Value, Block>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FunctionBody {
|
impl FunctionBody {
|
||||||
|
@ -55,9 +57,11 @@ impl FunctionBody {
|
||||||
let mut blocks = EntityVec::default();
|
let mut blocks = EntityVec::default();
|
||||||
let entry = blocks.push(BlockDef::default());
|
let entry = blocks.push(BlockDef::default());
|
||||||
let mut values = EntityVec::default();
|
let mut values = EntityVec::default();
|
||||||
|
let mut value_blocks = PerEntity::default();
|
||||||
for (i, &arg_ty) in locals.values().enumerate() {
|
for (i, &arg_ty) in locals.values().enumerate() {
|
||||||
let value = values.push(ValueDef::BlockParam(entry, i, arg_ty));
|
let value = values.push(ValueDef::BlockParam(entry, i, arg_ty));
|
||||||
blocks[entry].params.push((arg_ty, value));
|
blocks[entry].params.push((arg_ty, value));
|
||||||
|
value_blocks[value] = entry;
|
||||||
}
|
}
|
||||||
FunctionBody {
|
FunctionBody {
|
||||||
n_params,
|
n_params,
|
||||||
|
@ -66,6 +70,7 @@ impl FunctionBody {
|
||||||
entry,
|
entry,
|
||||||
blocks,
|
blocks,
|
||||||
values,
|
values,
|
||||||
|
value_blocks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +124,7 @@ impl FunctionBody {
|
||||||
let index = self.blocks[block].params.len();
|
let index = self.blocks[block].params.len();
|
||||||
let value = self.add_value(ValueDef::BlockParam(block, index, ty));
|
let value = self.add_value(ValueDef::BlockParam(block, index, ty));
|
||||||
self.blocks[block].params.push((ty, value));
|
self.blocks[block].params.push((ty, value));
|
||||||
|
self.value_blocks[value] = block;
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +155,7 @@ impl FunctionBody {
|
||||||
|
|
||||||
pub fn append_to_block(&mut self, block: Block, value: Value) {
|
pub fn append_to_block(&mut self, block: Block, value: Value) {
|
||||||
self.blocks[block].insts.push(value);
|
self.blocks[block].insts.push(value);
|
||||||
|
self.value_blocks[value] = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn end_block(&mut self, block: Block, terminator: Terminator) {
|
pub fn end_block(&mut self, block: Block, terminator: Terminator) {
|
||||||
|
|
Loading…
Reference in a new issue