jitcraft/Code.h
author David Anderson <dvander@alliedmods.net>
Tue Jul 03 00:21:37 2012 -0700 (2012-07-03)
changeset 29 c0e27b4f0672
parent 26 a48382113da6
child 34 9aafaf3797e6
permissions -rw-r--r--
Added RootScopes for AST roots.
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     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)
     9  * any later version.
    10  * 
    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.
    14  *
    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/.
    17  */
    18 #ifndef _include_jc_code_h_
    19 #define _include_jc_code_h_
    20 
    21 #include "Opcodes.h"
    22 #include "Barriers.h"
    23 #include "Heap.h"
    24 #include "Types.h"
    25 #include "FixedArray.h"
    26 
    27 namespace jc {
    28 
    29 class Module;
    30 class Type;
    31 
    32 // A code object contains the bytecode compiled from a function (or global
    33 // script), as well as all information needed to interpret or JIT-compile
    34 // the bytecode.
    35 class Code : public Object
    36 {
    37     Module *module_;
    38     Unbarriered<ByteArray> bytecode_;
    39     Unbarriered<FixedArray> locals_;
    40     Unbarriered<FixedArray> objects_;
    41     unsigned maxStackDepth_;
    42 
    43   public:
    44     // :TODO: use handles
    45     static Code *New(Zone *zone, ByteArray *bytecode, FixedArray *locals,
    46                      FixedArray *objects, unsigned maxStackDepth, Module *module);
    47 
    48     Module *module() {
    49         return module_;
    50     }
    51     bytecode *start() {
    52         return bytecode_->raw();
    53     }
    54     unsigned length() {
    55         return bytecode_->length();
    56     }
    57     Type *localType(size_t index) {
    58         return Type::cast(locals_->at(index));
    59     }
    60     unsigned nlocals() {
    61         return locals_->length();
    62     }
    63     unsigned maxStackDepth() {
    64         return maxStackDepth_;
    65     }
    66     Map *map(size_t index) {
    67         return Map::cast(objects_->at(index));
    68     }
    69     Object *object(size_t index) {
    70         return objects_->at(index);
    71     }
    72 
    73     static Code *cast(Object *obj) {
    74         assert(!obj || obj->is(MapKind_Code));
    75         return reinterpret_cast<Code *>(obj);
    76     }
    77 };
    78 
    79 }
    80 
    81 #endif // _include_jc_code_h_