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/.
39 buffer_ = (char *)malloc(STACK_SIZE);
44 end_ = buffer_ + STACK_SIZE;
49 SizeForCodeFrame(Code *code)
51 return sizeof(Frame) + sizeof(LocalSlot) * (code->nlocals() + code->maxStackDepth());
55 Stack::pushFrame(Frame *prev, Code *code)
57 size_t nbytes = SizeForCodeFrame(code);
58 if (reinterpret_cast<char *>(top_->sp) + nbytes >= end_)
61 Frame *frame = reinterpret_cast<Frame *>(top_->sp);
62 new (frame) Frame(prev, top_->pc, code);
63 memset(frame->locals(), 0, sizeof(LocalSlot) * code->nlocals());
65 top_->pc = frame->code()->start();
66 top_->sp = frame->stackBase();
73 Stack::popFrame(Frame *frame)
75 Frame *prev = frame->prev();
76 Code *code = frame->code();
77 size_t nbytes = sizeof(LocalSlot) * code->nlocals() +
79 sizeof(LocalSlot) * code->nargs();
80 top_->pc = frame->prevpc();
81 top_->sp = reinterpret_cast<LocalSlot *>(reinterpret_cast<char *>(top_->sp) - nbytes);
85 UnsafeStack::UnsafeStack()
92 UnsafeStack::~UnsafeStack()
98 UnsafeStack::initialize()
100 buffer_ = (char *)malloc(STACK_SIZE);
105 end_ = buffer_ + STACK_SIZE;