Miscellanious opcode cleanup.
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/.
27 OpInfo jc::OpcodeInfo[] =
29 #define OPDEF(name, number, text, length, uses, defs) \
30 {text, length, uses, defs},
31 #include "Opcodes.tbl"
36 Code::New(Zone *zone, ByteArray *bytecode, FixedArray *locals, FixedArray *args,
37 FixedArray *maps, unsigned maxStackDepth, Module *module)
39 Object *obj = zone->allocate(MapKind_Code, sizeof(Code), Heap::Tenure_Old);
43 Code *code = Code::cast(obj);
44 code->bytecode_ = bytecode;
45 code->locals_ = locals;
48 code->maxStackDepth_ = maxStackDepth;
49 code->module_ = module;
53 // All jumps must be the same length.
54 STATIC_ASSERT(OP_JL_LENGTH == OP_JUMP_LENGTH);
55 STATIC_ASSERT(OP_JLE_LENGTH == OP_JUMP_LENGTH);
56 STATIC_ASSERT(OP_JG_LENGTH == OP_JUMP_LENGTH);
57 STATIC_ASSERT(OP_JGE_LENGTH == OP_JUMP_LENGTH);
58 STATIC_ASSERT(OP_JEQ_LENGTH == OP_JUMP_LENGTH);
59 STATIC_ASSERT(OP_JNE_LENGTH == OP_JUMP_LENGTH);
60 STATIC_ASSERT(OP_JT_LENGTH == OP_JUMP_LENGTH);
61 STATIC_ASSERT(OP_JF_LENGTH == OP_JUMP_LENGTH);
64 jc::Disassemble(Code *code, FILE *fp)
66 bytecode *pc = code->start();
68 Opcode op = Opcode(*pc);
70 fprintf(fp, "%-4d %s ", int(pc - code->start()), OpcodeInfo[op].name);
101 case OP_SLOTREF_LIFO:
102 case OP_ARRAYREF_LIFO:
110 fprintf(fp, "%d", READ_INT32(pc));
114 fprintf(fp, "%f", READ_FLOAT(pc));
126 fprintf(fp, "%u (%+d)", unsigned((pc + READ_INT32(pc)) - code->start()), READ_INT32(pc));
129 case OP_NEWARRAY_LIFO:
132 ArrayMap *map = ArrayMap::cast(code->map(READ_UINT32(pc)));
133 fprintf(fp, "%s:", map->type()->innermost()->tag()
134 ? map->type()->innermost()->tag()
136 for (; map; map = map->contained()) {
137 Type *type = map->type();
138 fprintf(fp, "[%d]", type->elements());
152 fprintf(fp, "%u", READ_UINT32(pc));
162 pc += OpcodeInfo[op].length;
163 assert(pc < code->start() + code->length());