Re-add LIFO stack optimizations.
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_code_h_
20 #define _include_jc_code_h_
26 #include "FixedArray.h"
33 // A code object contains the bytecode compiled from a function (or global
34 // script), as well as all information needed to interpret or JIT-compile
36 class Code : public Object
38 Barriered<Module> module_;
39 Barriered<ByteArray> bytecode_;
40 Barriered<FixedArray> locals_;
41 Barriered<FixedArray> objects_;
42 Barriered<FixedArray> strings_;
43 Barriered<ByteArray> safepoints_;
44 Barriered<ByteArray> sourcemap_;
45 unsigned maxStackDepth_;
47 unsigned maxLoopDepth_;
50 static inline size_t BytesPerSafepoint(size_t stackDepth) {
51 return (Align(stackDepth, 8) / 8) + sizeof(unsigned);
55 static Code *New(Zone *zone, Handle<ByteArray> bytecode, Handle<FixedArray> locals,
56 Handle<FixedArray> objects, Handle<FixedArray> strings, unsigned maxStackDepth,
57 unsigned maxLoopDepth, Handle<ByteArray> safepoints, Handle<ByteArray> sourcemap);
63 return bytecode_->raw();
66 return bytecode_->length();
68 Type *localType(size_t index) {
69 return Type::cast(locals_->at(index));
72 return locals_ ? locals_->length() : 0;
74 unsigned maxStackDepth() {
75 return maxStackDepth_;
77 unsigned maxLoopDepth() {
80 Map *map(size_t index) {
81 return Map::cast(objects_->at(index));
83 Object *object(size_t index) {
84 return objects_->at(index);
86 ByteArray *safepoints() {
89 FixedArray *strings() {
92 uint8 *safepointAt(unsigned pcOffset);
94 void setModule(Handle<Module> module) {
98 unsigned pcToOffset(bytecode *pc) {
99 assert(pc >= start() && pc < start() + length());
100 return unsigned(pc - start());
103 SourcePosition pcToSource(unsigned pc);
104 unsigned lineNumber() {
109 static inline size_t offsetOfModule() {
110 return OFFSETOF(Code, module_);
112 static inline size_t offsetOfBytecode() {
113 return OFFSETOF(Code, bytecode_);
115 static inline size_t offsetOfLocals() {
116 return OFFSETOF(Code, locals_);
118 static inline size_t offsetOfObjects() {
119 return OFFSETOF(Code, objects_);
121 static inline size_t offsetOfStrings() {
122 return OFFSETOF(Code, strings_);
124 static inline size_t offsetOfSafepoints() {
125 return OFFSETOF(Code, safepoints_);
127 static inline size_t offsetOfSourceMap() {
128 return OFFSETOF(Code, sourcemap_);
130 // End GC Descriptor.
132 static Code *cast(Object *obj) {
133 assert(!obj || obj->is(MapKind_Code));
134 return reinterpret_cast<Code *>(obj);
140 #endif // _include_jc_code_h_