jitcraft/Code.h
author David Anderson <dvander@alliedmods.net>
Mon Jun 25 02:57:28 2012 -0700 (2012-06-25)
changeset 0 c455ebb9a5dc
child 12 75e385f68b7e
permissions -rw-r--r--
Initial import of prototype.
     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 
    23 namespace jc {
    24 
    25 class Module;
    26 class Type;
    27 
    28 class Code
    29 {
    30     bytecode *start_;
    31     unsigned length_;
    32     Type **locals_;
    33     unsigned nlocals_;
    34     unsigned maxStackDepth_;
    35     Module *module_;
    36     Type **args_;
    37     unsigned nargs_;
    38 
    39   public:
    40     Code(Module *module, bytecode *start, unsigned length,
    41          Type **args, unsigned nargs,
    42          Type **locals, unsigned nlocals,
    43          unsigned maxStackDepth)
    44       : start_(start),
    45         length_(length),
    46         locals_(locals),
    47         nlocals_(nlocals),
    48         maxStackDepth_(maxStackDepth),
    49         module_(module),
    50         args_(args),
    51         nargs_(nargs)
    52     {
    53     }
    54 
    55     Module *module() const {
    56         return module_;
    57     }
    58     bytecode *start() const {
    59         return start_;
    60     }
    61     unsigned length() const {
    62         return length_;
    63     }
    64     Type *localType(size_t index) const {
    65         assert(index < nlocals());
    66         return locals_[index];
    67     }
    68     Type *argType(size_t index) const {
    69         assert(index < nlocals());
    70         return args_[index];
    71     }
    72     unsigned nlocals() const {
    73         return nlocals_;
    74     }
    75     unsigned nargs() const {
    76         return nargs_;
    77     }
    78     unsigned maxStackDepth() const {
    79         return maxStackDepth_;
    80     }
    81 };
    82 
    83 }
    84 
    85 #endif // _include_jc_code_h_