Move around and add some assertions

This commit is contained in:
Fabian 2018-04-12 12:32:48 -05:00
parent 65bf2e350d
commit a9b5f153a8
5 changed files with 20 additions and 11 deletions

View file

@ -149,11 +149,6 @@ function gen_instruction_body(encodings, size)
if((e.opcode >>> 16) === 0xF3) has_F3 = true;
}
console.assert(
!encodings.some(e => e.nonfaulting && e.block_boundary),
"Unsupported: instruction cannot be both a jump and nonfaulting. Opcode: 0x" + hex(encoding.opcode)
);
if(has_66 || has_F2 || has_F3)
{
console.assert((encoding.opcode & 0xFF00) === 0x0F00);
@ -416,6 +411,7 @@ function gen_instruction_body(encodings, size)
if(encoding.conditional_jump)
{
console.assert((encoding.opcode & ~0xF) === 0x70 || (encoding.opcode & ~0xF) === 0x0F80);
instruction_postfix.push("analysis.condition_index = " + (encoding.opcode & 0xF) + ";");
}

View file

@ -168,11 +168,6 @@ function gen_instruction_body(encodings, size)
if((e.opcode >>> 16) === 0xF3) has_F3 = true;
}
console.assert(
!encodings.some(e => e.nonfaulting && e.block_boundary),
"Unsupported: instruction cannot be both a block boundary and nonfaulting. Opcode: 0x" + hex(encoding.opcode)
);
if(has_66 || has_F2 || has_F3)
{
console.assert((encoding.opcode & 0xFF00) === 0x0F00);

View file

@ -1,5 +1,7 @@
"use strict";
const { hex } = require("./util");
// http://ref.x86asm.net/coder32.html
const zf = 1 << 6;
@ -678,4 +680,18 @@ encodings.sort((e1, e2) => {
return o1 - o2 || e1.fixed_g - e2.fixed_g;
});
function test_encodings()
{
const invalid = encodings.find(e => e.nonfaulting && e.block_boundary);
if(invalid)
{
console.assert(
false,
"Unsupported: instruction cannot be both a block boundary and nonfaulting. Opcode: " + hex(invalid.opcode)
);
}
}
test_encodings();
module.exports = Object.freeze(encodings.map(entry => Object.freeze(entry)));

View file

@ -296,6 +296,8 @@ void gen_return(void)
// where [i] is passed on the wasm stack
void gen_switch(int32_t cases_count)
{
assert(cases_count >= 0);
write_raw_u8(&instruction_body, OP_BRTABLE);
write_leb_u32(&instruction_body, cases_count);

View file

@ -1024,7 +1024,7 @@ static void jit_find_basic_blocks()
{
int32_t to_visit = to_visit_stack[--to_visit_stack_count];
assert((*instruction_pointer & ~0xFFF) == (to_visit & ~0xFFF));
assert(same_page(*instruction_pointer, to_visit));
*instruction_pointer = *instruction_pointer & ~0xFFF | to_visit & 0xFFF;
if(find_basic_block_index(&basic_blocks, *instruction_pointer) != -1)