WIP.
This commit is contained in:
parent
04ecdb16bd
commit
539af66b88
|
@ -1,11 +1,13 @@
|
|||
//! Backend: IR to Wasm.
|
||||
|
||||
use crate::cfg::CFGInfo;
|
||||
use crate::entity::{EntityRef, PerEntity};
|
||||
use crate::ir::{Block, FunctionBody, Value, ValueDef};
|
||||
use crate::passes::rpo::{RPOIndex, RPO};
|
||||
use anyhow::Result;
|
||||
|
||||
pub mod stackify;
|
||||
use stackify::{Context as StackifyContext, WasmBlock};
|
||||
pub mod treeify;
|
||||
use treeify::Trees;
|
||||
|
||||
|
@ -13,13 +15,24 @@ pub struct WasmBackend<'a> {
|
|||
body: &'a FunctionBody,
|
||||
rpo: RPO,
|
||||
trees: Trees,
|
||||
ctrl: Vec<WasmBlock<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> WasmBackend<'a> {
|
||||
pub fn new(body: &'a FunctionBody) -> Result<WasmBackend<'a>> {
|
||||
let cfg = CFGInfo::new(body);
|
||||
let rpo = RPO::compute(body);
|
||||
log::trace!("RPO:\n{:?}\n", rpo);
|
||||
let trees = Trees::compute(body);
|
||||
Ok(WasmBackend { body, rpo, trees })
|
||||
log::trace!("Trees:\n{:?}\n", trees);
|
||||
let ctrl = StackifyContext::new(body, &cfg, &rpo).compute();
|
||||
log::trace!("Ctrl:\n{:?}\n", ctrl);
|
||||
Ok(WasmBackend {
|
||||
body,
|
||||
rpo,
|
||||
trees,
|
||||
ctrl,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compile(&self) -> Result<Vec<u8>> {
|
||||
|
|
|
@ -69,10 +69,10 @@ impl WasmLabel {
|
|||
}
|
||||
}
|
||||
|
||||
struct Context<'a> {
|
||||
pub struct Context<'a, 'b> {
|
||||
body: &'a FunctionBody,
|
||||
cfg: &'a CFGInfo,
|
||||
rpo: &'a RPO,
|
||||
cfg: &'b CFGInfo,
|
||||
rpo: &'b RPO,
|
||||
merge_nodes: HashSet<Block>,
|
||||
loop_headers: HashSet<Block>,
|
||||
ctrl_stack: Vec<CtrlEntry>,
|
||||
|
@ -95,8 +95,8 @@ impl CtrlEntry {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> {
|
||||
fn new(body: &'a FunctionBody, cfg: &'a CFGInfo, rpo: &'a RPO) -> Self {
|
||||
impl<'a, 'b> Context<'a, 'b> {
|
||||
pub fn new(body: &'a FunctionBody, cfg: &'b CFGInfo, rpo: &'b RPO) -> Self {
|
||||
let (merge_nodes, loop_headers) =
|
||||
Self::compute_merge_nodes_and_loop_headers(body, cfg, rpo);
|
||||
Self {
|
||||
|
@ -109,6 +109,12 @@ impl<'a> Context<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn compute(mut self) -> Vec<WasmBlock<'a>> {
|
||||
let mut body = vec![];
|
||||
self.handle_dom_subtree(self.cfg.entry, &mut body);
|
||||
body
|
||||
}
|
||||
|
||||
fn compute_merge_nodes_and_loop_headers(
|
||||
body: &FunctionBody,
|
||||
cfg: &CFGInfo,
|
||||
|
|
|
@ -10,6 +10,7 @@ use std::convert::TryFrom;
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct ValueArg(Value, u16);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Trees {
|
||||
/// Is a value placed "under" the given arg slot of the given
|
||||
/// other value?
|
||||
|
|
Loading…
Reference in a new issue