Refactored Array, Code to be Objects. Removed Object tagging.
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::init(ByteArray *bytecode, FixedArray *locals, FixedArray *args,
37 FixedArray *maps, unsigned maxStackDepth, Module *module)
39 WRITE_FIELD_OBJ_NO_BARRIER(bytecode, bytecode);
40 WRITE_FIELD_OBJ_NO_BARRIER(locals, locals);
41 WRITE_FIELD_OBJ_NO_BARRIER(args, args);
42 WRITE_FIELD_OBJ_NO_BARRIER(maps, maps);
43 WRITE_FIELD(maxStackDepth, maxStackDepth);
44 WRITE_FIELD(module, VoidPtr(module));
48 Code::New(Zone *zone, ByteArray *bytecode, FixedArray *locals, FixedArray *args,
49 FixedArray *maps, unsigned maxStackDepth, Module *module)
51 Object *obj = zone->allocate(MapKind_Code, sizeof(Code), Heap::Tenure_Old);
55 Code *code = Code::cast(obj);
56 code->init(bytecode, locals, args, maps, maxStackDepth, module);
60 // All jumps must be the same length.
61 STATIC_ASSERT(OP_JL_LENGTH == OP_JUMP_LENGTH);
62 STATIC_ASSERT(OP_JLE_LENGTH == OP_JUMP_LENGTH);
63 STATIC_ASSERT(OP_JG_LENGTH == OP_JUMP_LENGTH);
64 STATIC_ASSERT(OP_JGE_LENGTH == OP_JUMP_LENGTH);
65 STATIC_ASSERT(OP_JEQ_LENGTH == OP_JUMP_LENGTH);
66 STATIC_ASSERT(OP_JNE_LENGTH == OP_JUMP_LENGTH);
67 STATIC_ASSERT(OP_JT_LENGTH == OP_JUMP_LENGTH);
68 STATIC_ASSERT(OP_JF_LENGTH == OP_JUMP_LENGTH);
71 jc::Disassemble(Code *code, FILE *fp)
73 bytecode *pc = code->start();
75 Opcode op = Opcode(*pc);
77 fprintf(fp, "%-4d %s ", int(pc - code->start()), OpcodeInfo[op].name);
111 fprintf(fp, "%d", READ_INT32(pc));
115 fprintf(fp, "%f", READ_FLOAT(pc));
127 fprintf(fp, "%u (%+d)", unsigned((pc + READ_INT32(pc)) - code->start()), READ_INT32(pc));
133 ArrayMap *map = ArrayMap::cast(code->map(READ_UINT32(pc)));
134 fprintf(fp, "%s:", map->type()->innermost()->tag()
135 ? map->type()->innermost()->tag()
137 for (; map; map = map->contained()) {
138 Type *type = map->type();
139 fprintf(fp, "[%d]", type->elements());
151 fprintf(fp, "%u", READ_UINT32(pc));
161 pc += OpcodeInfo[op].length;
162 assert(pc < code->start() + code->length());