Add shortcuts for native operations
This commit is contained in:
parent
c3a3a09107
commit
ce54d834a5
@ -159,26 +159,11 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local band = {}
|
|
||||||
local bor = {}
|
|
||||||
local bxor = {}
|
|
||||||
local bnot = {}
|
local bnot = {}
|
||||||
|
|
||||||
band.i32 = bit.band
|
|
||||||
band.i64 = bit.band
|
|
||||||
|
|
||||||
bnot.i32 = bit.bnot
|
bnot.i32 = bit.bnot
|
||||||
bnot.i64 = bit.bnot
|
bnot.i64 = bit.bnot
|
||||||
|
|
||||||
bor.i32 = bit.bor
|
|
||||||
bor.i64 = bit.bor
|
|
||||||
|
|
||||||
bxor.i32 = bit.bxor
|
|
||||||
bxor.i64 = bit.bxor
|
|
||||||
|
|
||||||
module.band = band
|
|
||||||
module.bor = bor
|
|
||||||
module.bxor = bxor
|
|
||||||
module.bnot = bnot
|
module.bnot = bnot
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -230,12 +230,21 @@ fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<Intermediate> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<()> {
|
||||||
|
match (head, tail) {
|
||||||
|
("abs" | "ceil" | "floor" | "sqrt" | "min" | "max", _) | ("band" | "bor" | "bxor", _) => {
|
||||||
|
write!(w, "local {head}_{tail} = math.{head} ")
|
||||||
|
}
|
||||||
|
_ => write!(w, "local {head}_{tail} = rt.{head}.{tail} "),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<()> {
|
fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<()> {
|
||||||
let loc_set: BTreeSet<_> = func_list.iter().flat_map(localize::visit).collect();
|
let loc_set: BTreeSet<_> = func_list.iter().flat_map(localize::visit).collect();
|
||||||
|
|
||||||
loc_set
|
loc_set
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_for_each(|(a, b)| write!(w, "local {a}_{b} = rt.{a}.{b} "))
|
.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: &[Intermediate], w: &mut dyn Write) -> Result<Vec<usize>> {
|
||||||
|
@ -180,16 +180,13 @@ do
|
|||||||
local bxor = {}
|
local bxor = {}
|
||||||
local bnot = {}
|
local bnot = {}
|
||||||
|
|
||||||
band.i32 = bit32.band
|
|
||||||
band.i64 = I64.bit_and
|
band.i64 = I64.bit_and
|
||||||
|
|
||||||
bnot.i32 = bit32.bnot
|
bnot.i32 = bit32.bnot
|
||||||
bnot.i64 = I64.bit_not
|
bnot.i64 = I64.bit_not
|
||||||
|
|
||||||
bor.i32 = bit32.bor
|
|
||||||
bor.i64 = I64.bit_or
|
bor.i64 = I64.bit_or
|
||||||
|
|
||||||
bxor.i32 = bit32.bxor
|
|
||||||
bxor.i64 = I64.bit_xor
|
bxor.i64 = I64.bit_xor
|
||||||
|
|
||||||
module.band = band
|
module.band = band
|
||||||
|
@ -229,12 +229,22 @@ fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<Intermediate> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<()> {
|
||||||
|
match (head, tail) {
|
||||||
|
("abs" | "ceil" | "floor" | "sqrt" | "min" | "max", _)
|
||||||
|
| ("band" | "bor" | "bxor", "i32") => {
|
||||||
|
write!(w, "local {head}_{tail} = math.{head} ")
|
||||||
|
}
|
||||||
|
_ => write!(w, "local {head}_{tail} = rt.{head}.{tail} "),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<()> {
|
fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<()> {
|
||||||
let loc_set: BTreeSet<_> = func_list.iter().flat_map(localize::visit).collect();
|
let loc_set: BTreeSet<_> = func_list.iter().flat_map(localize::visit).collect();
|
||||||
|
|
||||||
loc_set
|
loc_set
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_for_each(|(a, b)| write!(w, "local {a}_{b} = rt.{a}.{b} "))
|
.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: &[Intermediate], w: &mut dyn Write) -> Result<Vec<usize>> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user