v86/gen/util.js
Fabian 3a8d644d75 Port jit to Rust
The following files and functions were ported:
- jit.c
- codegen.c
- _jit functions in instructions*.c and misc_instr.c
- generate_{analyzer,jit}.js (produces Rust code)
- jit_* from cpu.c

And the following data structures:
- hot_code_addresses
- wasm_table_index_free_list
- entry_points
- jit_cache_array
- page_first_jit_cache_entry

Other miscellaneous changes:
- Page is an abstract type
- Addresses, locals and bitflags are unsigned
- Make the number of entry points a growable type
- Avoid use of global state wherever possible
- Delete string packing
- Make CachedStateFlags abstract
- Make AnalysisType product type
- Make BasicBlockType product type
- Restore opcode assertion
- Set opt-level=2 in debug mode (for test performance)
- Delete JIT_ALWAYS instrumentation (now possible via api)
- Refactor generate_analyzer.js
- Refactor generate_jit.js
2020-08-30 19:29:13 -05:00

93 lines
2.1 KiB
JavaScript

"use strict";
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const process = require("process");
const child_process = require("child_process");
const CYAN_FMT = "\x1b[36m%s\x1b[0m";
function hex(n, pad)
{
pad = pad || 0;
let s = n.toString(16).toUpperCase();
while(s.length < pad) s = "0" + s;
return s;
}
function mkdirpSync(dir)
{
path.normalize(dir).split(path.sep).reduce((accum_path, dir) => {
const new_dir = accum_path + dir + path.sep;
if(!fs.existsSync(new_dir)) fs.mkdirSync(new_dir);
return new_dir;
}, "");
}
function get_switch_value(arg_switch)
{
const argv = process.argv;
const switch_i = argv.indexOf(arg_switch);
const val_i = switch_i + 1;
if(switch_i > -1 && val_i < argv.length)
{
return argv[switch_i + 1];
}
return null;
}
function get_switch_exist(arg_switch)
{
return process.argv.includes(arg_switch);
}
function create_backup_file(src, dest)
{
try
{
fs.copyFileSync(src, dest);
}
catch(e)
{
if(e.code !== "ENOENT") throw e;
fs.writeFileSync(dest, "");
}
}
function create_diff_file(in1, in2, out)
{
const diff = child_process.spawnSync("git", ["diff", "--no-index", in1, in2]).stdout;
fs.writeFileSync(out, diff);
}
function finalize_table(out_dir, name, contents)
{
const file_path = path.join(out_dir, `${name}.c`);
const backup_file_path = path.join(out_dir, `${name}.c.bak`);
const diff_file_path = path.join(out_dir, `${name}.c.diff`);
create_backup_file(file_path, backup_file_path);
fs.writeFileSync(file_path, contents);
create_diff_file(backup_file_path, file_path, diff_file_path);
console.log(CYAN_FMT, `[+] Wrote table ${name}. Remember to check ${diff_file_path}`);
}
function finalize_table_rust(out_dir, name, contents)
{
const file_path = path.join(out_dir, name);
fs.writeFileSync(file_path, contents);
console.log(CYAN_FMT, `[+] Wrote table ${name}.`);
}
module.exports = {
hex,
mkdirpSync,
get_switch_value,
get_switch_exist,
finalize_table,
finalize_table_rust,
};