From b36a03ca40f82a3835227ad02f0ee08368bcf787 Mon Sep 17 00:00:00 2001 From: Amaan Cheval Date: Fri, 23 Feb 2018 13:56:33 +0530 Subject: [PATCH] generate_jit: Refactor to deduplicate custom call generation --- gen/generate_jit.js | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/gen/generate_jit.js b/gen/generate_jit.js index 4332ebf99a..73be452b2c 100755 --- a/gen/generate_jit.js +++ b/gen/generate_jit.js @@ -150,6 +150,21 @@ function get_nonfaulting_mem_reg_postfix(encoding) }; } +function gen_custom_call(encoding, size, args) +{ + console.assert(!encoding.nonfaulting, "Prefix/custom instructions cannot be marked as nonfaulting."); + + const instruction_name = make_instruction_name(encoding, size) + "_jit"; + const imm_read = gen_read_imm_call(encoding, size); + + if(imm_read) + { + args.push(imm_read); + } + + return gen_call(instruction_name, args); +} + function gen_instruction_body(encodings, size) { const encoding = encodings[0]; @@ -207,19 +222,11 @@ function gen_instruction_body(encodings, size) const instruction_postfix = case_.jump ? ["instr_flags |= JIT_INSTR_JUMP_FLAG;"] : []; if(case_.custom) { - console.assert(!case_.nonfaulting, "Unsupported: custom fixed_g instruction as nonfaulting"); - const instruction_name = make_instruction_name(case_, size) + "_jit"; - const imm_read = gen_read_imm_call(case_, size); - const args = ["modrm_byte"]; - - if(imm_read) - { - args.push(imm_read); - } + const custom_call = gen_custom_call(case_, size, ["modrm_byte"]); return { conditions: [fixed_g], - body: [gen_call(instruction_name, args)].concat(instruction_postfix), + body: [custom_call].concat(instruction_postfix), }; } @@ -417,20 +424,10 @@ function gen_instruction_body(encodings, size) } else if(encoding.prefix || encoding.custom) { - console.assert(!encoding.nonfaulting, "Prefix/custom instructions cannot be marked as nonfaulting."); - - const instruction_name = make_instruction_name(encoding, size) + "_jit"; - const imm_read = gen_read_imm_call(encoding, size); - const args = []; - - if(imm_read) - { - args.push(imm_read); - } - + const custom_call = gen_custom_call(encoding, size, []); const call_prefix = encoding.prefix ? "instr_flags |= " : ""; // Prefix calls can add to the return flags - return [call_prefix + gen_call(instruction_name, args)].concat(instruction_postfix); + return [call_prefix + custom_call].concat(instruction_postfix); } else {