Fix timeout handling in the test harness.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
20 #include "BytecodeEmitter.h"
21 #include "../Heap-inl.h"
22 #include "../Handles-inl.h"
26 class HIRTranslator : public HIRVisitor
29 HIRTranslator(Zone *zone, BytecodeEmitter &emitter)
35 void translate(HIR *hir) {
39 void visitFloat(HFloat *hir);
40 void visitInteger(HInteger *hir);
41 void visitCall(HCall *call);
42 void visitStore(HStore *store);
43 void visitBinary(HBinary *binary);
44 void visitLocal(HLocal *local);
45 void visitGlobal(HGlobal *global);
46 void visitConvert(HConvert *convert);
47 void visitIndex(HIndex *index);
51 BytecodeEmitter &emitter_;
57 HIRTranslator::visitFloat(HFloat *hir)
59 __ float_(hir->value());
63 HIRTranslator::visitInteger(HInteger *hir)
65 __ int_(hir->value());
69 HIRTranslator::visitCall(HCall *call)
71 Local<FunctionType> fun(zone_, FunctionType::cast(call->callee()->type()));
73 assert(call->args()->length() == fun->parameters()->length());
75 unsigned argc = call->args()->length();
77 for (size_t i = call->args()->length() - 1; i < call->args()->length(); i--) {
78 HIR *hir = call->args()->at(i);
82 call->callee()->accept(this);
87 HGlobal::bind(HIRVisitor *visitor, BytecodeEmitter &emitter_)
92 HGlobal::store(BytecodeEmitter &emitter_)
98 HGlobal::load(BytecodeEmitter &emitter_)
104 HLocal::bind(HIRVisitor *visitor, BytecodeEmitter &emitter_)
106 if (sym_->type()->isReference())
111 HLocal::store(BytecodeEmitter &emitter_)
113 if (sym_->type()->isReference())
114 __ setref(sym_->type()->contained_ref());
120 HLocal::load(BytecodeEmitter &emitter_)
122 if (sym_->type()->isReference())
123 __ getref(sym_->type());
129 HIndex::bind(HIRVisitor *visitor, BytecodeEmitter &emitter_)
131 left_->accept(visitor);
132 right_->accept(visitor);
136 HIndex::store(BytecodeEmitter &emitter_)
142 HIndex::load(BytecodeEmitter &emitter_)
148 HIRTranslator::visitLocal(HLocal *local)
150 local->bind(this, emitter_);
151 local->load(emitter_);
155 HIRTranslator::visitIndex(HIndex *index)
157 index->bind(this, emitter_);
158 index->load(emitter_);
162 HIRTranslator::visitGlobal(HGlobal *global)
164 __ getglobal(global->sym());
168 HIRTranslator::visitStore(HStore *store)
170 store->lval()->bind(this, emitter_);
171 store->rval()->accept(this);
172 store->lval()->store(emitter_);
176 TokenToOpcode(TokenKind kind)
212 assert(kind == TOK_BITXOR);
218 HIRTranslator::visitBinary(HBinary *binary)
220 binary->left()->accept(this);
221 binary->right()->accept(this);
223 // We define three sets of math operators:
225 // (1) ADD, SUB, MUL, DIV, MOD, which take two equal types and produce
227 // (2) LT, LE, GE, GT, EQ, NE, which take two equal types and produce
229 // (3) SHL, SR, USHR, BITAND, BITOR, BITXOR, BITNOT, which take two
230 // equal integer types and return that integer type.
232 Opcode op = TokenToOpcode(binary->token());
234 if (op >= OP_ADD && op <= OP_NE) {
235 if (binary->type()->isFloat())
236 op = Opcode(int(op) + int(OP_ADD_F - OP_ADD));
238 assert(binary->type()->isInt32());
245 HIRTranslator::visitConvert(HConvert *convert)
247 convert->in()->accept(this);
248 __ unary(convert->opcode());
252 ke::EmitHIR(Zone *zone, BytecodeEmitter &emitter, HIR *hir)
254 HIRTranslator translator(zone, emitter);
255 translator.translate(hir);