8 #include "src/interpreter/bytecodes.h" 12 namespace interpreter {
14 void WriteBytecode(std::ofstream& out, Bytecode bytecode,
15 OperandScale operand_scale,
int* count,
int offset_table[],
17 DCHECK_NOT_NULL(count);
18 if (Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) {
19 out <<
" \\\n V(" << Bytecodes::ToString(bytecode, operand_scale,
"")
20 <<
"Handler, interpreter::OperandScale::k" << operand_scale
21 <<
", interpreter::Bytecode::k" << Bytecodes::ToString(bytecode) <<
")";
22 offset_table[table_index] = *count;
25 offset_table[table_index] = -1;
29 void WriteHeader(
const char* header_filename) {
30 std::ofstream out(header_filename);
32 out <<
"// Automatically generated from interpreter/bytecodes.h\n" 33 <<
"// The following list macro is used to populate the builtins list\n" 34 <<
"// with the bytecode handlers\n\n" 35 <<
"#ifndef V8_BUILTINS_GENERATED_BYTECODES_BUILTINS_LIST\n" 36 <<
"#define V8_BUILTINS_GENERATED_BYTECODES_BUILTINS_LIST\n\n" 38 <<
"namespace internal {\n\n" 39 <<
"#define BUILTIN_LIST_BYTECODE_HANDLERS(V)";
41 constexpr
int kTableSize =
42 BytecodeOperands::kOperandScaleCount * Bytecodes::kBytecodeCount;
43 int offset_table[kTableSize];
47 #define ADD_BYTECODES(Name, ...) \ 48 WriteBytecode(out, Bytecode::k##Name, operand_scale, &count, offset_table, \ 50 OperandScale operand_scale = OperandScale::kSingle;
51 BYTECODE_LIST(ADD_BYTECODES)
52 int single_count = count;
53 operand_scale = OperandScale::kDouble;
54 BYTECODE_LIST(ADD_BYTECODES)
55 int wide_count = count - single_count;
56 operand_scale = OperandScale::kQuadruple;
57 BYTECODE_LIST(ADD_BYTECODES)
59 int extra_wide_count = count - wide_count - single_count;
60 CHECK_GT(single_count, wide_count);
61 CHECK_EQ(single_count, Bytecodes::kBytecodeCount);
62 CHECK_EQ(wide_count, extra_wide_count);
63 out <<
"\n\nconst int kNumberOfBytecodeHandlers = " << single_count <<
";\n" 64 <<
"const int kNumberOfWideBytecodeHandlers = " << wide_count <<
";\n\n" 65 <<
"// Mapping from (Bytecode + OperandScaleAsIndex * |Bytecodes|) to\n" 66 <<
"// a dense form with all the illegal Bytecode/OperandScale\n" 67 <<
"// combinations removed. Used to index into the builtins table.\n" 68 <<
"constexpr int kBytecodeToBuiltinsMapping[" << kTableSize <<
"] = {\n" 71 for (
int i = 0;
i < kTableSize; ++
i) {
72 if (
i == single_count ||
i == 2 * single_count) {
75 out << offset_table[
i] <<
", ";
79 <<
"} // namespace internal\n" 80 <<
"} // namespace v8\n" 81 <<
"#endif // V8_BUILTINS_GENERATED_BYTECODES_BUILTINS_LIST\n";
88 int main(
int argc,
const char* argv[]) {
90 std::cerr <<
"Usage: " << argv[0] <<
" <output filename>\n";
94 v8::internal::interpreter::WriteHeader(argv[1]);