Added support for arbitrary expression references.
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/.
41 buffer_ = (char *)malloc(STACK_SIZE);
46 end_ = buffer_ + STACK_SIZE;
51 SizeForCodeFrame(Code *code)
53 return sizeof(Frame) + sizeof(LocalSlot) * (code->nlocals() + code->maxStackDepth());
57 Stack::pushFrame(Frame *prev, Code *code)
59 size_t nbytes = SizeForCodeFrame(code);
60 if (reinterpret_cast<char *>(top_->sp) + nbytes >= end_)
63 Frame *frame = reinterpret_cast<Frame *>(top_->sp);
64 new (frame) Frame(prev, top_->pc, code, ZONE()->heap().lifoPosition());
65 memset(frame->locals(), 0, sizeof(LocalSlot) * code->nlocals());
67 top_->pc = frame->code()->start();
68 top_->sp = frame->stackBase();
75 Stack::popFrame(Frame *frame)
77 Frame *prev = frame->prev();
78 Code *code = frame->code();
79 size_t nbytes = sizeof(LocalSlot) * code->nlocals() +
81 sizeof(LocalSlot) * code->nargs();
82 top_->pc = frame->prevpc();
83 top_->sp = reinterpret_cast<LocalSlot *>(reinterpret_cast<char *>(top_->sp) - nbytes);
84 ZONE()->heap().unwindLifo(frame->lifoPosition());