Initial import of prototype.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
24 OpInfo jc::OpcodeInfo[] =
26 #define OPDEF(name, number, text, length, uses, defs) \
27 {text, length, uses, defs},
28 #include "Opcodes.tbl"
32 // All jumps must be the same length.
33 STATIC_ASSERT(OP_JL_LENGTH == OP_JUMP_LENGTH);
34 STATIC_ASSERT(OP_JLE_LENGTH == OP_JUMP_LENGTH);
35 STATIC_ASSERT(OP_JG_LENGTH == OP_JUMP_LENGTH);
36 STATIC_ASSERT(OP_JGE_LENGTH == OP_JUMP_LENGTH);
37 STATIC_ASSERT(OP_JEQ_LENGTH == OP_JUMP_LENGTH);
38 STATIC_ASSERT(OP_JNE_LENGTH == OP_JUMP_LENGTH);
39 STATIC_ASSERT(OP_JT_LENGTH == OP_JUMP_LENGTH);
40 STATIC_ASSERT(OP_JF_LENGTH == OP_JUMP_LENGTH);
43 jc::Disassemble(Code *code, FILE *fp)
45 bytecode *pc = code->start();
47 Opcode op = Opcode(*pc);
49 fprintf(fp, "%-4d %s ", int(pc - code->start()), OpcodeInfo[op].name);
70 fprintf(fp, "%d", READ_INT32(pc));
82 fprintf(fp, "%d (%u)", READ_INT32(pc), unsigned((pc + READ_INT32(pc)) - code->start()));
87 unsigned width = pc[1];
88 unsigned dims = pc[2];
90 for (unsigned i = 0; i < dims; i++)
91 fprintf(fp, "[%u]", READ_UINT32(pc + 2 + (i * sizeof(unsigned))));
92 fprintf(fp, " ; (width = %s)\n", (width == 1 ? "char" : "cell"));
93 pc += 3 + dims * sizeof(unsigned);
101 fprintf(fp, "%u", READ_UINT32(pc));
105 fprintf(fp, "%u", READ_UINT32(pc));
115 pc += OpcodeInfo[op].length;