Rename Intermediate to FuncData

This commit is contained in:
Rerumu 2022-06-10 23:33:46 -04:00
parent 78aa47cdd6
commit b8e40fe740
11 changed files with 47 additions and 47 deletions

View File

@ -1,7 +1,7 @@
use std::collections::BTreeSet;
use wasm_ast::{
node::{BinOp, CmpOp, Intermediate, LoadAt, StoreAt, UnOp},
node::{BinOp, CmpOp, FuncData, LoadAt, StoreAt, UnOp},
visit::{Driver, Visitor},
};
@ -51,12 +51,12 @@ impl Visitor for Visit {
}
}
pub fn visit(ir: &Intermediate) -> BTreeSet<(&'static str, &'static str)> {
pub fn visit(ast: &FuncData) -> BTreeSet<(&'static str, &'static str)> {
let mut visit = Visit {
result: BTreeSet::new(),
};
ir.accept(&mut visit);
ast.accept(&mut visit);
visit.result
}

View File

@ -1,7 +1,7 @@
use std::collections::BTreeSet;
use wasm_ast::{
node::{Intermediate, LoadAt, MemoryGrow, MemorySize, StoreAt},
node::{FuncData, LoadAt, MemoryGrow, MemorySize, StoreAt},
visit::{Driver, Visitor},
};
@ -27,12 +27,12 @@ impl Visitor for Visit {
}
}
pub fn visit(ir: &Intermediate) -> BTreeSet<usize> {
pub fn visit(ast: &FuncData) -> BTreeSet<usize> {
let mut visit = Visit {
result: BTreeSet::new(),
};
ir.accept(&mut visit);
ast.accept(&mut visit);
visit.result
}

View File

@ -5,7 +5,7 @@ use std::{
use parity_wasm::elements::ValueType;
use wasm_ast::node::{
Backward, Br, BrIf, BrTable, Call, CallIndirect, Forward, If, Intermediate, Return, SetGlobal,
Backward, Br, BrIf, BrTable, Call, CallIndirect, Forward, FuncData, If, Return, SetGlobal,
SetLocal, SetTemporary, Statement, StoreAt, Terminator,
};
@ -256,16 +256,16 @@ impl Driver for Statement {
}
}
fn write_parameter_list(ir: &Intermediate, w: &mut dyn Write) -> Result<()> {
fn write_parameter_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
write!(w, "function(")?;
write_ascending("param", 0..ir.num_param, w)?;
write_ascending("param", 0..ast.num_param, w)?;
write!(w, ")")
}
fn write_variable_list(ir: &Intermediate, w: &mut dyn Write) -> Result<()> {
fn write_variable_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
let mut total = 0;
for data in &ir.local_data {
for data in &ast.local_data {
let range = total..total + usize::try_from(data.count()).unwrap();
let typed = if data.value_type() == ValueType::I64 {
"0LL"
@ -283,16 +283,16 @@ fn write_variable_list(ir: &Intermediate, w: &mut dyn Write) -> Result<()> {
write!(w, " ")?;
}
if ir.num_stack != 0 {
if ast.num_stack != 0 {
write!(w, "local ")?;
write_ascending("reg", 0..ir.num_stack, w)?;
write_ascending("reg", 0..ast.num_stack, w)?;
write!(w, " ")?;
}
Ok(())
}
impl Driver for Intermediate {
impl Driver for FuncData {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
write_parameter_list(self, w)?;
write_variable_list(self, w)?;

View File

@ -9,7 +9,7 @@ use parity_wasm::elements::{
use wasm_ast::{
builder::{Builder, TypeInfo},
node::Intermediate,
node::FuncData,
};
use crate::{
@ -218,7 +218,7 @@ fn write_data_list(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Re
Ok(())
}
fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<Intermediate> {
fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<FuncData> {
let list = match wasm.code_section() {
Some(v) => v.bodies(),
None => return Vec::new(),
@ -243,7 +243,7 @@ fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<()
}
}
fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<()> {
fn write_localize_used(func_list: &[FuncData], w: &mut dyn Write) -> Result<()> {
let loc_set: BTreeSet<_> = func_list.iter().flat_map(localize::visit).collect();
loc_set
@ -251,7 +251,7 @@ fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<
.try_for_each(|(a, b)| write_local_operation(a, b, w))
}
fn write_memory_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<Vec<usize>> {
fn write_memory_used(func_list: &[FuncData], w: &mut dyn Write) -> Result<Vec<usize>> {
let mem_set: BTreeSet<_> = func_list.iter().flat_map(memory::visit).collect();
let list: Vec<_> = mem_set.into_iter().collect();
@ -280,7 +280,7 @@ fn write_func_start(wasm: &Module, index: u32, offset: u32, w: &mut dyn Write) -
fn write_func_list(
wasm: &Module,
type_info: &TypeInfo,
func_list: &[Intermediate],
func_list: &[FuncData],
w: &mut dyn Write,
) -> Result<()> {
let offset = type_info.len_ex().try_into().unwrap();

View File

@ -1,7 +1,7 @@
use std::collections::BTreeSet;
use wasm_ast::{
node::{BinOp, CmpOp, Intermediate, LoadAt, StoreAt, UnOp, Value},
node::{BinOp, CmpOp, FuncData, LoadAt, StoreAt, UnOp, Value},
visit::{Driver, Visitor},
};
@ -62,12 +62,12 @@ impl Visitor for Visit {
}
}
pub fn visit(ir: &Intermediate) -> BTreeSet<(&'static str, &'static str)> {
pub fn visit(ast: &FuncData) -> BTreeSet<(&'static str, &'static str)> {
let mut visit = Visit {
result: BTreeSet::new(),
};
ir.accept(&mut visit);
ast.accept(&mut visit);
visit.result
}

View File

@ -1,7 +1,7 @@
use std::collections::BTreeSet;
use wasm_ast::{
node::{Intermediate, LoadAt, MemoryGrow, MemorySize, StoreAt},
node::{FuncData, LoadAt, MemoryGrow, MemorySize, StoreAt},
visit::{Driver, Visitor},
};
@ -27,12 +27,12 @@ impl Visitor for Visit {
}
}
pub fn visit(ir: &Intermediate) -> BTreeSet<usize> {
pub fn visit(ast: &FuncData) -> BTreeSet<usize> {
let mut visit = Visit {
result: BTreeSet::new(),
};
ir.accept(&mut visit);
ast.accept(&mut visit);
visit.result
}

View File

@ -5,7 +5,7 @@ use std::{
use parity_wasm::elements::ValueType;
use wasm_ast::node::{
Backward, Br, BrIf, BrTable, Call, CallIndirect, Forward, If, Intermediate, Return, SetGlobal,
Backward, Br, BrIf, BrTable, Call, CallIndirect, Forward, FuncData, If, Return, SetGlobal,
SetLocal, SetTemporary, Statement, StoreAt, Terminator,
};
@ -263,16 +263,16 @@ impl Driver for Statement {
}
}
fn write_parameter_list(ir: &Intermediate, w: &mut dyn Write) -> Result<()> {
fn write_parameter_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
write!(w, "function(")?;
write_ascending("param", 0..ir.num_param, w)?;
write_ascending("param", 0..ast.num_param, w)?;
write!(w, ")")
}
fn write_variable_list(ir: &Intermediate, w: &mut dyn Write) -> Result<()> {
fn write_variable_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
let mut total = 0;
for data in &ir.local_data {
for data in &ast.local_data {
let range = total..total + usize::try_from(data.count()).unwrap();
let zero = if data.value_type() == ValueType::I64 {
"num_K_ZERO "
@ -289,16 +289,16 @@ fn write_variable_list(ir: &Intermediate, w: &mut dyn Write) -> Result<()> {
write!(w, " ")?;
}
if ir.num_stack != 0 {
if ast.num_stack != 0 {
write!(w, "local ")?;
write_ascending("reg", 0..ir.num_stack, w)?;
write_ascending("reg", 0..ast.num_stack, w)?;
write!(w, " ")?;
}
Ok(())
}
impl Driver for Intermediate {
impl Driver for FuncData {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
write_parameter_list(self, w)?;
write_variable_list(self, w)?;

View File

@ -9,7 +9,7 @@ use parity_wasm::elements::{
use wasm_ast::{
builder::{Builder, TypeInfo},
node::Intermediate,
node::FuncData,
};
use crate::{
@ -217,7 +217,7 @@ fn write_data_list(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Re
Ok(())
}
fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<Intermediate> {
fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<FuncData> {
let list = match wasm.code_section() {
Some(v) => v.bodies(),
None => return Vec::new(),
@ -241,7 +241,7 @@ fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<()
}
}
fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<()> {
fn write_localize_used(func_list: &[FuncData], w: &mut dyn Write) -> Result<()> {
let loc_set: BTreeSet<_> = func_list.iter().flat_map(localize::visit).collect();
loc_set
@ -249,7 +249,7 @@ fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<
.try_for_each(|(a, b)| write_local_operation(a, b, w))
}
fn write_memory_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<Vec<usize>> {
fn write_memory_used(func_list: &[FuncData], w: &mut dyn Write) -> Result<Vec<usize>> {
let mem_set: BTreeSet<_> = func_list.iter().flat_map(memory::visit).collect();
let list: Vec<_> = mem_set.into_iter().collect();
@ -278,7 +278,7 @@ fn write_func_start(wasm: &Module, index: u32, offset: u32, w: &mut dyn Write) -
fn write_func_list(
wasm: &Module,
type_info: &TypeInfo,
func_list: &[Intermediate],
func_list: &[FuncData],
w: &mut dyn Write,
) -> Result<()> {
let offset = type_info.len_ex().try_into().unwrap();

View File

@ -5,7 +5,7 @@ use parity_wasm::elements::{
use crate::node::{
Backward, BinOp, BinOpType, Br, BrIf, BrTable, Call, CallIndirect, CmpOp, CmpOpType,
Expression, Forward, GetGlobal, GetLocal, GetTemporary, If, Intermediate, LoadAt, LoadType,
Expression, Forward, FuncData, GetGlobal, GetLocal, GetTemporary, If, LoadAt, LoadType,
MemoryGrow, MemorySize, Return, Select, SetGlobal, SetLocal, SetTemporary, Statement, StoreAt,
StoreType, Terminator, UnOp, UnOpType, Value,
};
@ -328,10 +328,10 @@ impl<'a> Builder<'a> {
}
#[must_use]
pub fn build_anonymous(mut self, list: &[Instruction]) -> Intermediate {
pub fn build_anonymous(mut self, list: &[Instruction]) -> FuncData {
let data = self.build_stat_list(list, 1);
Intermediate {
FuncData {
local_data: Vec::new(),
num_param: 0,
num_stack: data.num_stack,
@ -340,11 +340,11 @@ impl<'a> Builder<'a> {
}
#[must_use]
pub fn build_indexed(mut self, index: usize, func: &FuncBody) -> Intermediate {
pub fn build_indexed(mut self, index: usize, func: &FuncBody) -> FuncData {
let arity = &self.type_info.rel_arity_of(self.type_info.len_ex() + index);
let data = self.build_stat_list(func.code().elements(), arity.num_result);
Intermediate {
FuncData {
local_data: func.locals().to_vec(),
num_param: arity.num_param,
num_stack: data.num_stack,

View File

@ -751,7 +751,7 @@ pub enum Statement {
StoreAt(StoreAt),
}
pub struct Intermediate {
pub struct FuncData {
pub local_data: Vec<Local>,
pub num_param: usize,
pub num_stack: usize,

View File

@ -1,6 +1,6 @@
use crate::node::{
Backward, BinOp, Br, BrIf, BrTable, Call, CallIndirect, CmpOp, Expression, Forward, GetGlobal,
GetLocal, GetTemporary, If, Intermediate, LoadAt, MemoryGrow, MemorySize, Return, Select,
Backward, BinOp, Br, BrIf, BrTable, Call, CallIndirect, CmpOp, Expression, Forward, FuncData,
GetGlobal, GetLocal, GetTemporary, If, LoadAt, MemoryGrow, MemorySize, Return, Select,
SetGlobal, SetLocal, SetTemporary, Statement, StoreAt, Terminator, UnOp, Value,
};
@ -328,7 +328,7 @@ impl<T: Visitor> Driver<T> for Statement {
}
}
impl<T: Visitor> Driver<T> for Intermediate {
impl<T: Visitor> Driver<T> for FuncData {
fn accept(&self, visitor: &mut T) {
self.code.accept(visitor);
}