codegen: s/gen_fn[0-9]/gen_fn[0-9]_const/ to indicate inline args

We need to differentiate between gen_fn, gen_call_fn, etc. This is a
step in the right direction, but isn't quite enough.
This commit is contained in:
Amaan Cheval 2018-04-20 19:29:18 +05:30 committed by Fabian
parent ebe7b3d426
commit cde8a2d005
7 changed files with 32 additions and 27 deletions

View file

@ -83,7 +83,7 @@ function gen_codegen_call(name, args)
args = args || [];
const args_count = args.length;
args = [].concat([`"${name}"`, name.length], args);
return gen_call(`gen_fn${args_count}`, args);
return gen_call(`gen_fn${args_count}_const`, args);
}
function gen_codegen_call_modrm(name, args)
@ -298,7 +298,7 @@ function gen_instruction_body(encodings, size)
default_case: {
body: [
"assert(false);",
`gen_fn0("trigger_ud", 10);`,
`gen_fn0_const("trigger_ud", 10);`,
],
}
},

View file

@ -35,19 +35,19 @@ Codegen.prototype.str_input = function(str)
Codegen.prototype.fn0 = function(fn)
{
this.str_input(fn);
this.wm.exports["_gen_fn0"](Codegen.STR_INPUT_OFFSET, fn.length);
this.wm.exports["_gen_fn0_const"](Codegen.STR_INPUT_OFFSET, fn.length);
};
Codegen.prototype.fn1 = function(fn, arg0)
{
this.str_input(fn);
this.wm.exports["_gen_fn1"](Codegen.STR_INPUT_OFFSET, fn.length, arg0);
this.wm.exports["_gen_fn1_const"](Codegen.STR_INPUT_OFFSET, fn.length, arg0);
};
Codegen.prototype.fn2 = function(fn, arg0, arg1)
{
this.str_input(fn);
this.wm.exports["_gen_fn2"](Codegen.STR_INPUT_OFFSET, fn.length, arg0, arg1);
this.wm.exports["_gen_fn2_const"](Codegen.STR_INPUT_OFFSET, fn.length, arg0, arg1);
};
Codegen.prototype.modrm_fn1 = function(fn, modrm_byte, arg)

View file

@ -185,7 +185,7 @@ void gen_fn0_ret(char const* fn, uint8_t fn_len)
call_fn(&instruction_body, fn_idx);
}
void gen_fn0(char const* fn, uint8_t fn_len)
void gen_fn0_const(char const* fn, uint8_t fn_len)
{
int32_t fn_idx = get_fn_index(fn, fn_len, FN0_TYPE_INDEX);
call_fn(&instruction_body, fn_idx);
@ -223,7 +223,7 @@ void gen_call_fn1_ret(char const* fn, uint8_t fn_len)
call_fn(&instruction_body, fn_idx);
}
void gen_fn1(char const* fn, uint8_t fn_len, int32_t arg0)
void gen_fn1_const(char const* fn, uint8_t fn_len, int32_t arg0)
{
int32_t fn_idx = get_fn_index(fn, fn_len, FN1_TYPE_INDEX);
push_i32(&instruction_body, arg0);
@ -274,7 +274,7 @@ void gen_call_fn2(char const* fn, uint8_t fn_len)
call_fn(&instruction_body, fn_idx);
}
void gen_fn2(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1)
void gen_fn2_const(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1)
{
int32_t fn_idx = get_fn_index(fn, fn_len, FN2_TYPE_INDEX);
push_i32(&instruction_body, arg0);
@ -282,7 +282,7 @@ void gen_fn2(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1)
call_fn(&instruction_body, fn_idx);
}
void gen_fn3(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1, int32_t arg2)
void gen_fn3_const(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1, int32_t arg2)
{
int32_t fn_idx = get_fn_index(fn, fn_len, FN3_TYPE_INDEX);
push_i32(&instruction_body, arg0);

View file

@ -26,16 +26,21 @@ uintptr_t gen_get_final_offset(void);
int32_t get_fn_index(char const* fn, uint8_t fn_len, uint8_t type_index);
// Generate function call with constant arguments
void gen_fn0_const(char const* fn, uint8_t fn_len);
void gen_fn1_const(char const* fn, uint8_t fn_len, int32_t arg0);
void gen_fn2_const(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1);
void gen_fn3_const(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1, int32_t arg2);
// Generate code to set register value to result of function call
void gen_set_reg16_fn0(char const* fn, uint8_t fn_len, int32_t reg);
void gen_set_reg32s_fn0(char const* fn, uint8_t fn_len, int32_t reg);
void gen_fn0(char const* fn, uint8_t fn_len);
void gen_fn1(char const* fn, uint8_t fn_len, int32_t arg0);
void gen_set_reg16_fn1(char const* fn, uint8_t fn_len, int32_t arg0, int32_t reg);
void gen_set_reg32s_fn1(char const* fn, uint8_t fn_len, int32_t arg0, int32_t reg);
// Generate function call with register value as argument (reg is index of register)
void gen_fn1_reg16(char const* fn, uint8_t fn_len, int32_t reg);
void gen_fn1_reg32s(char const* fn, uint8_t fn_len, int32_t reg);
void gen_fn2(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1);
void gen_fn3(char const* fn, uint8_t fn_len, int32_t arg0, int32_t arg1, int32_t arg2);
void gen_fn0_ret(char const* fn, uint8_t fn_len);
void gen_fn1_ret(char const* fn, uint8_t fn_len, int32_t arg0);

View file

@ -1294,7 +1294,7 @@ static void jit_generate(uint32_t phys_addr, uint32_t page_dirtiness)
}
else
{
gen_fn1("jmp_rel16", strlen("jmp_rel16"), block.jump_offset);
gen_fn1_const("jmp_rel16", strlen("jmp_rel16"), block.jump_offset);
}
if(block.next_block_branch_taken_addr)

View file

@ -655,26 +655,26 @@ void instr32_8F_0_reg(int32_t r)
void instr16_8F_0_jit_mem(int32_t modrm_byte)
{
gen_fn0("instr16_8F_0_mem_pre", 20);
gen_fn0_const("instr16_8F_0_mem_pre", 20);
gen_modrm_resolve(modrm_byte);
gen_modrm_fn0("instr16_8F_0_mem", 16);
}
void instr16_8F_0_jit_reg(int32_t r)
{
gen_fn1("instr16_8F_0_reg", 16, r);
gen_fn1_const("instr16_8F_0_reg", 16, r);
}
void instr32_8F_0_jit_mem(int32_t modrm_byte)
{
gen_fn0("instr32_8F_0_mem_pre", 20);
gen_fn0_const("instr32_8F_0_mem_pre", 20);
gen_modrm_resolve(modrm_byte);
gen_modrm_fn0("instr32_8F_0_mem", 16);
}
void instr32_8F_0_jit_reg(int32_t r)
{
gen_fn1("instr32_8F_0_reg", 16, r);
gen_fn1_const("instr32_8F_0_reg", 16, r);
}
void instr_90() { }
@ -1444,11 +1444,11 @@ void instr32_E8(int32_t imm32s) {
//dbg_assert(is_asize_32() || get_real_eip() < 0x10000);
}
void instr16_E8_jit(int32_t imm16) {
gen_fn1("instr16_E8", 10, imm16);
gen_fn1_const("instr16_E8", 10, imm16);
}
void instr32_E8_jit(int32_t imm32s) {
gen_fn1("instr32_E8", 10, imm32s);
gen_fn1_const("instr32_E8", 10, imm32s);
}
void instr16_E9(int32_t imm16) {
@ -1461,10 +1461,10 @@ void instr32_E9(int32_t imm32s) {
dbg_assert(is_asize_32() || get_real_eip() < 0x10000);
}
void instr16_E9_jit(int32_t imm16) {
gen_fn1("instr16_E9", 10, imm16);
gen_fn1_const("instr16_E9", 10, imm16);
}
void instr32_E9_jit(int32_t imm32s) {
gen_fn1("instr32_E9", 10, imm32s);
gen_fn1_const("instr32_E9", 10, imm32s);
}
void instr16_EA(int32_t new_ip, int32_t cs) {
@ -1485,7 +1485,7 @@ void instr_EB(int32_t imm8) {
}
void instr_EB_jit(int32_t imm8s) {
gen_fn1("instr_EB", 8, imm8s);
gen_fn1_const("instr_EB", 8, imm8s);
}
void instr_EC() {

View file

@ -256,11 +256,11 @@ void push16_imm_jit(int32_t imm)
{
if(*stack_size_32)
{
gen_fn1("push16_ss32", 11, imm);
gen_fn1_const("push16_ss32", 11, imm);
}
else
{
gen_fn1("push16_ss16", 11, imm);
gen_fn1_const("push16_ss16", 11, imm);
}
}
@ -326,11 +326,11 @@ void push32_imm_jit(int32_t imm)
{
if(*stack_size_32)
{
gen_fn1("push32_ss32", 11, imm);
gen_fn1_const("push32_ss32", 11, imm);
}
else
{
gen_fn1("push32_ss16", 11, imm);
gen_fn1_const("push32_ss16", 11, imm);
}
}