Generate instruction tables into build directory, and only when changed
This commit is contained in:
parent
ae5ec9b91a
commit
948fa047d0
|
@ -2,9 +2,12 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encodings = require("./x86_table");
|
||||
const c_ast = require("./c_ast");
|
||||
const { hex } = require("./util");
|
||||
const { hex, write_sync_if_changed } = require("./util");
|
||||
|
||||
const OUT_DIR = path.join(__dirname, "..", "build");
|
||||
|
||||
gen_table();
|
||||
|
||||
|
@ -390,7 +393,10 @@ function gen_table()
|
|||
body: ["assert(false);"]
|
||||
},
|
||||
};
|
||||
fs.writeFileSync("/tmp/table", c_ast.print_syntax_tree([table]).join("\n") + "\n");
|
||||
write_sync_if_changed(
|
||||
path.join(OUT_DIR, "interpreter"),
|
||||
c_ast.print_syntax_tree([table]).join("\n") + "\n"
|
||||
);
|
||||
|
||||
const cases0f_16 = [];
|
||||
const cases0f_32 = [];
|
||||
|
@ -449,6 +455,12 @@ function gen_table()
|
|||
body: ["assert(false);"]
|
||||
},
|
||||
};
|
||||
fs.writeFileSync("/tmp/table0f_16", c_ast.print_syntax_tree([table0f_16]).join("\n") + "\n");
|
||||
fs.writeFileSync("/tmp/table0f_32", c_ast.print_syntax_tree([table0f_32]).join("\n") + "\n");
|
||||
write_sync_if_changed(
|
||||
path.join(OUT_DIR, "interpreter0f_16"),
|
||||
c_ast.print_syntax_tree([table0f_16]).join("\n") + "\n"
|
||||
);
|
||||
write_sync_if_changed(
|
||||
path.join(OUT_DIR, "interpreter0f_32"),
|
||||
c_ast.print_syntax_tree([table0f_32]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encodings = require("./x86_table");
|
||||
const c_ast = require("./c_ast");
|
||||
const { hex } = require("./util");
|
||||
const { hex, write_sync_if_changed } = require("./util");
|
||||
|
||||
const OUT_DIR = path.join(__dirname, "..", "build");
|
||||
|
||||
const APPEND_NONFAULTING_FLAG = "instr_flags |= JIT_INSTR_NONFAULTING_FLAG;";
|
||||
|
||||
|
@ -490,7 +493,10 @@ function gen_table()
|
|||
body: ["assert(false);"]
|
||||
},
|
||||
};
|
||||
fs.writeFileSync("/tmp/jit", c_ast.print_syntax_tree([table]).join("\n") + "\n");
|
||||
write_sync_if_changed(
|
||||
path.join(OUT_DIR, "jit"),
|
||||
c_ast.print_syntax_tree([table]).join("\n") + "\n"
|
||||
);
|
||||
|
||||
const cases0f_16 = [];
|
||||
const cases0f_32 = [];
|
||||
|
@ -549,6 +555,12 @@ function gen_table()
|
|||
body: ["assert(false);"]
|
||||
},
|
||||
};
|
||||
fs.writeFileSync("/tmp/jit0f_16", c_ast.print_syntax_tree([table0f_16]).join("\n") + "\n");
|
||||
fs.writeFileSync("/tmp/jit0f_32", c_ast.print_syntax_tree([table0f_32]).join("\n") + "\n");
|
||||
write_sync_if_changed(
|
||||
path.join(OUT_DIR, "jit0f_16"),
|
||||
c_ast.print_syntax_tree([table0f_16]).join("\n") + "\n"
|
||||
);
|
||||
write_sync_if_changed(
|
||||
path.join(OUT_DIR, "jit0f_32"),
|
||||
c_ast.print_syntax_tree([table0f_32]).join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
|
26
gen/util.js
26
gen/util.js
|
@ -1,5 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const fs = require("fs");
|
||||
|
||||
function hex(n, pad)
|
||||
{
|
||||
|
@ -9,6 +11,30 @@ function hex(n, pad)
|
|||
return s;
|
||||
}
|
||||
|
||||
function write_sync_if_changed(filename, contents)
|
||||
{
|
||||
assert.ok(typeof contents === "string", "Contents must be a string for comparison");
|
||||
|
||||
let existing_contents = null;
|
||||
try
|
||||
{
|
||||
existing_contents = fs.readFileSync(filename).toString();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
if(e.code !== "ENOENT") throw e;
|
||||
}
|
||||
|
||||
const contents_changed = existing_contents !== contents;
|
||||
if(contents_changed)
|
||||
{
|
||||
fs.writeFileSync(filename, contents);
|
||||
console.log("[+] Writing", filename);
|
||||
}
|
||||
return contents_changed;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hex,
|
||||
write_sync_if_changed
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue