mirror of
https://github.com/copy/v86.git
synced 2025-12-31 04:23:15 +00:00
Backup and generate diff in generate_{jit,interpreter}, not Makefile
This commit is contained in:
parent
7cf28d3d76
commit
ce1ca76aea
4 changed files with 57 additions and 31 deletions
17
Makefile
17
Makefile
|
|
@ -163,36 +163,19 @@ build/libv86-debug.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
|
|||
.PHONY: instruction_tables
|
||||
instruction_tables: $(INSTRUCTION_TABLES)
|
||||
|
||||
# Back target file up if it exists; if not, create empty back up file
|
||||
BACKUP_EXISTING_TABLE_CMD=([ -e $@ ] && cp $@ $@.bak) || touch $@.bak
|
||||
GEN_DIFF_FROM_BACKUP_CMD=git diff --no-index $@.bak $@ > $@.diff || true
|
||||
|
||||
# All of the following generate a specific instruction table and a diff compared to the existing table
|
||||
build/jit.c: $(JIT_DEPENDENCIES)
|
||||
$(BACKUP_EXISTING_TABLE_CMD)
|
||||
./gen/generate_jit.js --output-dir build/ --table jit
|
||||
$(GEN_DIFF_FROM_BACKUP_CMD)
|
||||
build/jit0f_16.c: $(JIT_DEPENDENCIES)
|
||||
$(BACKUP_EXISTING_TABLE_CMD)
|
||||
./gen/generate_jit.js --output-dir build/ --table jit0f_16
|
||||
$(GEN_DIFF_FROM_BACKUP_CMD)
|
||||
build/jit0f_32.c: $(JIT_DEPENDENCIES)
|
||||
$(BACKUP_EXISTING_TABLE_CMD)
|
||||
./gen/generate_jit.js --output-dir build/ --table jit0f_32
|
||||
$(GEN_DIFF_FROM_BACKUP_CMD)
|
||||
|
||||
build/interpreter.c: $(INTERPRETER_DEPENDENCIES)
|
||||
$(BACKUP_EXISTING_TABLE_CMD)
|
||||
./gen/generate_interpreter.js --output-dir build/ --table interpreter
|
||||
$(GEN_DIFF_FROM_BACKUP_CMD)
|
||||
build/interpreter0f_16.c: $(INTERPRETER_DEPENDENCIES)
|
||||
$(BACKUP_EXISTING_TABLE_CMD)
|
||||
./gen/generate_interpreter.js --output-dir build/ --table interpreter0f_16
|
||||
$(GEN_DIFF_FROM_BACKUP_CMD)
|
||||
build/interpreter0f_32.c: $(INTERPRETER_DEPENDENCIES)
|
||||
$(BACKUP_EXISTING_TABLE_CMD)
|
||||
./gen/generate_interpreter.js --output-dir build/ --table interpreter0f_32
|
||||
$(GEN_DIFF_FROM_BACKUP_CMD)
|
||||
|
||||
|
||||
build/v86.wasm: src/native/*.c src/native/*.h src/native/codegen/*.c src/native/codegen/*.h src/native/profiler/* src/native/call-indirect.ll $(INSTRUCTION_TABLES)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const fs = require("fs");
|
|||
const path = require("path");
|
||||
const encodings = require("./x86_table");
|
||||
const c_ast = require("./c_ast");
|
||||
const { hex, get_switch_value, get_switch_exist } = require("./util");
|
||||
const { hex, get_switch_value, get_switch_exist, finalize_table } = require("./util");
|
||||
|
||||
const OUT_DIR = get_switch_value("--output-dir") ||
|
||||
path.join(__dirname, "..", "build");
|
||||
|
|
@ -408,8 +408,9 @@ function gen_table()
|
|||
};
|
||||
if(to_generate.interpreter)
|
||||
{
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, "interpreter.c"),
|
||||
finalize_table(
|
||||
OUT_DIR,
|
||||
"interpreter",
|
||||
c_ast.print_syntax_tree([table]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
|
@ -474,16 +475,18 @@ function gen_table()
|
|||
|
||||
if(to_generate.interpreter0f_16)
|
||||
{
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, "interpreter0f_16.c"),
|
||||
finalize_table(
|
||||
OUT_DIR,
|
||||
"interpreter0f_16",
|
||||
c_ast.print_syntax_tree([table0f_16]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
||||
if(to_generate.interpreter0f_32)
|
||||
{
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, "interpreter0f_32.c"),
|
||||
finalize_table(
|
||||
OUT_DIR,
|
||||
"interpreter0f_32",
|
||||
c_ast.print_syntax_tree([table0f_32]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const fs = require("fs");
|
|||
const path = require("path");
|
||||
const encodings = require("./x86_table");
|
||||
const c_ast = require("./c_ast");
|
||||
const { hex, get_switch_value, get_switch_exist } = require("./util");
|
||||
const { hex, get_switch_value, get_switch_exist, finalize_table } = require("./util");
|
||||
|
||||
const OUT_DIR = get_switch_value("--output-dir") ||
|
||||
path.join(__dirname, "..", "build");
|
||||
|
|
@ -509,8 +509,9 @@ function gen_table()
|
|||
|
||||
if(to_generate.jit)
|
||||
{
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, "jit.c"),
|
||||
finalize_table(
|
||||
OUT_DIR,
|
||||
"jit",
|
||||
c_ast.print_syntax_tree([table]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
|
@ -575,16 +576,18 @@ function gen_table()
|
|||
|
||||
if(to_generate.jit0f_16)
|
||||
{
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, "jit0f_16.c"),
|
||||
finalize_table(
|
||||
OUT_DIR,
|
||||
"jit0f_16",
|
||||
c_ast.print_syntax_tree([table0f_16]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
||||
if(to_generate.jit0f_32)
|
||||
{
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, "jit0f_32.c"),
|
||||
finalize_table(
|
||||
OUT_DIR,
|
||||
"jit0f_32",
|
||||
c_ast.print_syntax_tree([table0f_32]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
37
gen/util.js
37
gen/util.js
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
@ -29,8 +33,41 @@ 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}`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hex,
|
||||
get_switch_value,
|
||||
get_switch_exist,
|
||||
finalize_table,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue