Remove unused code

This commit is contained in:
Jef
2019-03-26 17:50:03 +01:00
parent 96df539554
commit 1ff22de331
5 changed files with 7 additions and 470 deletions

View File

@@ -1,5 +1,3 @@
#![allow(dead_code)] // for now
use crate::error::Error;
use crate::microwasm::{BrTarget, SignlessType, Type, Value, F32, F64, I32, I64};
use crate::module::ModuleContext;
@@ -166,6 +164,7 @@ impl GPRs {
}
}
#[allow(dead_code)]
pub mod registers {
use super::{RegId, GPR};
@@ -238,7 +237,6 @@ extern "sysv64" fn println(len: u64, args: *const u8) {
});
}
#[allow(unused_macros)]
macro_rules! asm_println {
($asm:expr) => {asm_println!($asm,)};
($asm:expr, $($args:tt)*) => {{
@@ -313,10 +311,6 @@ impl GPRs {
self.bits |= 1 << gpr;
}
fn free_count(&self) -> u32 {
self.bits.count_ones()
}
fn is_free(&self, gpr: RegId) -> bool {
(self.bits & (1 << gpr)) != 0
}
@@ -400,14 +394,6 @@ impl Registers {
let (gpr, scratch_counts) = self.scratch_counts(gpr);
scratch_counts.0.is_free(gpr)
}
pub fn free_64(&self) -> u32 {
self.scratch_64.0.free_count()
}
pub fn free_128(&self) -> u32 {
self.scratch_128.0.free_count()
}
}
#[derive(Debug, Clone)]
@@ -583,9 +569,6 @@ struct RelocateAccess {
address: RelocateAddress,
}
#[derive(Debug)]
pub struct UninitializedCodeSection(TranslatedCodeSection);
#[derive(Debug)]
pub struct TranslatedCodeSection {
exec_buf: ExecutableBuffer,
@@ -631,65 +614,8 @@ pub struct BlockState {
type Stack = Vec<ValueLocation>;
pub enum MemoryAccessMode {
/// This is slower than using `Unchecked` mode, but works in
/// any scenario (the most important scenario being when we're
/// running on a system that can't index much more memory than
/// the Wasm).
Checked,
/// This means that checks are _not emitted by the compiler_!
/// If you're using WebAssembly to run untrusted code, you
/// _must_ delegate bounds checking somehow (probably by
/// allocating 2^33 bytes of memory with the second half set
/// to unreadable/unwriteable/unexecutable)
Unchecked,
}
struct Pending<T> {
label: T,
is_defined: bool,
}
impl<T> Pending<T> {
fn undefined(label: T) -> Self {
Pending {
label,
is_defined: false,
}
}
fn defined(label: T) -> Self {
Pending {
label,
is_defined: true,
}
}
fn as_undefined(&self) -> Option<T>
where
T: Copy,
{
if !self.is_defined {
Some(self.label)
} else {
None
}
}
}
impl<T> From<T> for Pending<T> {
fn from(label: T) -> Self {
Pending {
label,
is_defined: false,
}
}
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
enum LabelValue {
I8(i8),
I16(i16),
I32(i32),
I64(i64),
}
@@ -971,11 +897,6 @@ macro_rules! conversion {
macro_rules! shift {
($name:ident, $reg_ty:ident, $instr:ident, $const_fallback:expr, $ty:expr) => {
pub fn $name(&mut self) {
enum RestoreRcx {
MoveValBack(GPR),
PopRcx,
}
let mut count = self.pop();
let mut val = self.pop();
@@ -2055,21 +1976,6 @@ impl<'this, M: ModuleContext> Context<'this, M> {
(self.block_state.depth.0 as i32 + offset) * WORD_SIZE as i32
}
fn zero_reg(&mut self, reg: GPR) {
match reg {
GPR::Rq(r) => {
dynasm!(self.asm
; xor Rq(r), Rq(r)
);
}
GPR::Rx(r) => {
dynasm!(self.asm
; pxor Rx(r), Rx(r)
);
}
}
}
cmp_i32!(i32_eq, sete, sete, |a, b| a == b);
cmp_i32!(i32_neq, setne, setne, |a, b| a != b);
// `dynasm-rs` inexplicably doesn't support setb but `setnae` (and `setc`) are synonymous
@@ -3418,8 +3324,6 @@ impl<'this, M: ModuleContext> Context<'this, M> {
}
pub fn i64_truncate_f32_u(&mut self) {
struct Trunc;
let mut val = self.pop();
let out_val = match val {
@@ -4884,12 +4788,6 @@ where
fn const_value(val: LabelValue) -> impl FnMut(&mut Assembler) {
move |asm| match val {
LabelValue::I8(val) => dynasm!(asm
; .byte val
),
LabelValue::I16(val) => dynasm!(asm
; .word val
),
LabelValue::I32(val) => dynasm!(asm
; .dword val
),
@@ -4902,12 +4800,6 @@ fn const_value(val: LabelValue) -> impl FnMut(&mut Assembler) {
fn const_values(a: LabelValue, b: LabelValue) -> impl FnMut(&mut Assembler) {
move |asm| {
match a {
LabelValue::I8(val) => dynasm!(asm
; .byte val
),
LabelValue::I16(val) => dynasm!(asm
; .word val
),
LabelValue::I32(val) => dynasm!(asm
; .dword val
),
@@ -4917,12 +4809,6 @@ fn const_values(a: LabelValue, b: LabelValue) -> impl FnMut(&mut Assembler) {
}
match b {
LabelValue::I8(val) => dynasm!(asm
; .byte val
),
LabelValue::I16(val) => dynasm!(asm
; .word val
),
LabelValue::I32(val) => dynasm!(asm
; .dword val
),

View File

@@ -2,7 +2,6 @@ use crate::error::Error;
use capstone::prelude::*;
use std::fmt::Write;
#[allow(dead_code)]
pub fn disassemble(mem: &[u8]) -> Result<(), Error> {
let mut cs = Capstone::new()
.x86()

View File

@@ -1,4 +1,6 @@
use crate::backend::*;
use crate::backend::{
ret_locs, BlockCallingConvention, CodeGenSession, Context, Label, VirtualCallingConvention,
};
use crate::error::Error;
use crate::microwasm::*;
use crate::module::{ModuleContext, SigType, Signature};

View File

@@ -1055,350 +1055,3 @@ fn bench_fibonacci_baseline(b: &mut test::Bencher) {
b.iter(|| test::black_box(fib(test::black_box(20))));
}
// #[test]
#[allow(dead_code)]
fn sieve() {
const CODE: &str = r#"
(module
(type $t0 (func (param i32 i32)))
(type $t1 (func (param i32 i32 i32) (result i32)))
(type $t2 (func (param i32 i32 i32)))
(type $t3 (func (param i32)))
(type $t4 (func (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)))
(type $t5 (func (param i32 i32) (result i32)))
(func $optimized_sieve (export "optimized_sieve") (type $t0) (param $p0 i32) (param $p1 i32)
(local $l0 i32) (local $l1 i32) (local $l2 i32) (local $l3 i32) (local $l4 i32) (local $l5 i32) (local $l6 i32) (local $l7 i32) (local $l8 i32) (local $l9 i32) (local $l10 i32) (local $l11 i32) (local $l12 i32) (local $l13 i32) (local $l14 i32) (local $l15 i32) (local $l16 i32) (local $l17 i32) (local $l18 f64)
get_global $g0
i32.const 64
i32.sub
tee_local $l0
set_global $g0
i32.const 0
set_local $l1
get_local $l0
i32.const 0
i32.const 64
call $memset
set_local $l0
block $B0
block $B1
block $B2
block $B3
get_local $p1
i32.const 2
i32.gt_u
br_if $B3
i32.const -1
i32.const 0
get_local $p1
i32.const 2
i32.eq
select
set_local $p1
i32.const 0
set_local $l2
i32.const 0
set_local $l3
i32.const 0
set_local $l4
i32.const 0
set_local $l5
i32.const 0
set_local $l6
i32.const 0
set_local $l7
i32.const 0
set_local $l8
i32.const 0
set_local $l9
i32.const 0
set_local $l10
i32.const 0
set_local $l11
i32.const 0
set_local $l12
i32.const 0
set_local $l13
i32.const 0
set_local $l14
i32.const 0
set_local $l15
i32.const 0
set_local $l16
i32.const 0
set_local $l17
br $B2
end
get_local $p1
i32.const -3
i32.add
i32.const 1
i32.shr_u
set_local $l3
block $B4
block $B5
get_local $p1
f64.convert_u/i32
f64.sqrt
tee_local $l18
f64.const 0x1p+32 (;=4.29497e+09;)
f64.lt
get_local $l18
f64.const 0x0p+0 (;=0;)
f64.ge
i32.and
br_if $B5
i32.const 0
set_local $p1
br $B4
end
get_local $l18
i32.trunc_u/f64
set_local $p1
end
get_local $l3
i32.const 1
i32.add
set_local $l17
get_local $p1
i32.const -3
i32.add
i32.const 1
i32.shr_u
set_local $l5
i32.const 0
set_local $p1
loop $L6
get_local $p1
tee_local $l4
i32.const 5
i32.shr_u
set_local $p1
get_local $l4
i32.const 511
i32.gt_u
br_if $B0
block $B7
get_local $l0
get_local $p1
i32.const 2
i32.shl
i32.add
i32.load
i32.const 1
get_local $l4
i32.const 31
i32.and
i32.shl
i32.and
br_if $B7
get_local $l4
i32.const 1
i32.shl
i32.const 3
i32.add
tee_local $l2
get_local $l2
i32.mul
i32.const -3
i32.add
i32.const 1
i32.shr_u
tee_local $p1
get_local $l3
i32.gt_u
br_if $B7
loop $L8
get_local $p1
i32.const 5
i32.shr_u
set_local $l1
get_local $p1
i32.const 511
i32.gt_u
br_if $B1
get_local $l0
get_local $l1
i32.const 2
i32.shl
i32.add
tee_local $l1
get_local $l1
i32.load
i32.const 1
get_local $p1
i32.const 31
i32.and
i32.shl
i32.or
i32.store
get_local $p1
get_local $l2
i32.add
tee_local $p1
get_local $l3
i32.le_u
br_if $L8
end
end
get_local $l4
i32.const 1
i32.add
set_local $p1
get_local $l4
get_local $l5
i32.lt_u
br_if $L6
end
i32.const -1
set_local $p1
get_local $l0
i32.load offset=60
set_local $l1
get_local $l0
i32.load offset=56
set_local $l2
get_local $l0
i32.load offset=52
set_local $l3
get_local $l0
i32.load offset=48
set_local $l4
get_local $l0
i32.load offset=44
set_local $l5
get_local $l0
i32.load offset=40
set_local $l6
get_local $l0
i32.load offset=36
set_local $l7
get_local $l0
i32.load offset=32
set_local $l8
get_local $l0
i32.load offset=28
set_local $l9
get_local $l0
i32.load offset=24
set_local $l10
get_local $l0
i32.load offset=20
set_local $l11
get_local $l0
i32.load offset=16
set_local $l12
get_local $l0
i32.load offset=12
set_local $l13
get_local $l0
i32.load offset=8
set_local $l14
get_local $l0
i32.load offset=4
set_local $l15
get_local $l0
i32.load
set_local $l16
end
get_local $p0
get_local $l1
i32.store offset=68
get_local $p0
get_local $l2
i32.store offset=64
get_local $p0
get_local $l3
i32.store offset=60
get_local $p0
get_local $l4
i32.store offset=56
get_local $p0
get_local $l5
i32.store offset=52
get_local $p0
get_local $l6
i32.store offset=48
get_local $p0
get_local $l7
i32.store offset=44
get_local $p0
get_local $l8
i32.store offset=40
get_local $p0
get_local $l9
i32.store offset=36
get_local $p0
get_local $l10
i32.store offset=32
get_local $p0
get_local $l11
i32.store offset=28
get_local $p0
get_local $l12
i32.store offset=24
get_local $p0
get_local $l13
i32.store offset=20
get_local $p0
get_local $l14
i32.store offset=16
get_local $p0
get_local $l15
i32.store offset=12
get_local $p0
get_local $l16
i32.store offset=8
get_local $p0
get_local $l17
i32.store offset=4
get_local $p0
get_local $p1
i32.store
get_local $l0
i32.const 64
i32.add
set_global $g0
return
end
i32.const 1396
get_local $l1
i32.const 16
unreachable
end
i32.const 1380
get_local $p1
i32.const 16
unreachable)
(func $memset (type $t1) (param $p0 i32) (param $p1 i32) (param $p2 i32) (result i32)
(local $l0 i32)
block $B0
get_local $p2
i32.eqz
br_if $B0
get_local $p0
set_local $l0
loop $L1
get_local $l0
get_local $p1
i32.store8
get_local $l0
i32.const 1
i32.add
set_local $l0
get_local $p2
i32.const -1
i32.add
tee_local $p2
br_if $L1
end
end
get_local $p0)
(memory $memory (export "memory") 17 17)
(global $g0 (mut i32) (i32.const 1050032)))
"#;
translate(&wabt::wat2wasm(CODE).unwrap()).unwrap();
}

View File

@@ -3,13 +3,10 @@ use crate::error::Error;
use crate::function_body;
use crate::module::SimpleContext;
use cranelift_codegen::{binemit, ir};
#[allow(unused_imports)] // for now
use wasmparser::{
CodeSectionReader, Data, DataSectionReader, Element, ElementSectionReader, Export,
ExportSectionReader, ExternalKind, FuncType, FunctionSectionReader, Global,
GlobalSectionReader, GlobalType, Import, ImportSectionEntryType, ImportSectionReader,
MemorySectionReader, MemoryType, Operator, TableSectionReader, TableType, Type,
TypeSectionReader,
CodeSectionReader, DataSectionReader, ElementSectionReader, ExportSectionReader, FuncType,
FunctionSectionReader, GlobalSectionReader, ImportSectionReader, MemorySectionReader,
MemoryType, Operator, TableSectionReader, TableType, TypeSectionReader,
};
/// Parses the Type section of the wasm module.