Fix gcc and clang builds.
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/.
19 #ifndef _include_jc_stack_h_
20 #define _include_jc_stack_h_
25 #include "Functions.h"
26 #include "VirtualObjectVisitor.h"
70 // Position of the LIFO stack at function entry.
71 Address lifoPosition_;
73 // Loop nesting level, for LIFO stack balancing. LIFO stack balancing
74 // is not strictly required, but it helps to avoid unnecessary waste,
75 // since once the LIFO stack is depleted, we must use the heap instead.
79 Frame(Frame *prev, bytecode *prevpc, Function *fun, Code *code, Address lifoPosition)
84 lifoPosition_(lifoPosition),
89 Frame(Frame *prev, bytecode *prevpc, Native *native, Address lifoPosition)
94 lifoPosition_(lifoPosition)
98 Address *loopStack() {
99 return reinterpret_cast<Address *>(this + 1);
101 LocalSlot *locals() {
102 return reinterpret_cast<LocalSlot *>(loopStack() + code_->maxLoopDepth());
104 LocalSlot *stackBase() {
105 return locals() + code_->nlocals();
107 Function *fun() const {
108 assert(fun_ && callee_->is(MapKind_Function));
111 Function *maybeFun() const {
112 return (fun_ && callee_->is(MapKind_Function)) ? fun_ : NULL;
114 bool isNative() const {
115 return callee_ && callee_->is(MapKind_Native);
117 Native *native() const {
125 Frame *prev() const {
128 bytecode *prevpc() const {
131 Address lifoPosition() const {
132 return lifoPosition_;
134 LocalSlot &arg(unsigned slot) {
135 assert(slot < fun()->nargs());
136 return *(reinterpret_cast<LocalSlot *>(this) - slot - 1);
138 void enterLoop(Zone *zone);
139 void leaveLoop(Zone *zone);
140 void accept(VirtualObjectVisitor *visitor);
143 // RAII object for calling a function from C++.
162 LocalSlot &arg(unsigned index) {
163 assert(index < nargs_);
164 return args_[nargs_ - index - 1];
168 // RAII object for calling a native from C++.
174 LocalSlot *argsBase_;
186 return reinterpret_cast<intptr_t *>(argsBase_);
192 friend class InvokeArgs;
193 friend class NativeArgs;
196 static const size_t STACK_SIZE = 1024 * 1024;
205 Frame *pushInlineFrame(Handle<Function> fun);
206 Frame *popInlineFrame();
208 bool pushInvokeFrame(Handle<Function> fun, InvokeArgs &args);
209 bool pushModuleFrame(Handle<Module> module, InvokeArgs &args);
210 bool pushNativeFrame(Handle<Native> native, NativeArgs &args, unsigned argc);
215 bool isInCallStack(Handle<Module> module);
216 void accept(VirtualObjectVisitor *visitor);
219 void popInvokeFrame(InvokeArgs &args);
220 void popNativeFrame(NativeArgs &args);
235 StackIter(Zone *zone);
238 const char *function() const;
239 unsigned lineNumber() const;
240 const char *source() const;
246 #endif // _include_jc_stack_h_