jitcraft/Modules.h
author David Anderson <dvander@alliedmods.net>
Mon Jul 02 01:52:57 2012 -0700 (2012-07-02)
changeset 26 a48382113da6
parent 14 0784ac5cc347
child 44 c920f9328716
permissions -rw-r--r--
Added a Function object to sit in between Module and Code.
dvander@0
     1
/*
dvander@0
     2
 * Copyright (C) 2012 David Anderson
dvander@0
     3
 *
dvander@0
     4
 * This file is part of JITCraft.
dvander@0
     5
 *
dvander@0
     6
 * JITCraft is free software: you can redistribute it and/or modify it under
dvander@0
     7
 * the terms of the GNU General Public License as published by the Free
dvander@0
     8
 * Software Foundation, either version 3 of the License, or (at your option)
dvander@0
     9
 * any later version.
dvander@0
    10
 * 
dvander@0
    11
 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
dvander@0
    12
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@0
    13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
dvander@0
    14
 *
dvander@0
    15
 * You should have received a copy of the GNU General Public License along with
dvander@0
    16
 * JITCraft. If not, see http://www.gnu.org/licenses/.
dvander@0
    17
 */
dvander@0
    18
#ifndef _include_jc_module_h_
dvander@0
    19
#define _include_jc_module_h_
dvander@0
    20
dvander@14
    21
#include "Heap.h"
dvander@0
    22
#include "Code.h"
dvander@26
    23
#include "Functions.h"
dvander@0
    24
dvander@0
    25
namespace jc {
dvander@0
    26
dvander@14
    27
class Module : public Object
dvander@0
    28
{
dvander@14
    29
    Barriered<FixedArray> functions_;
dvander@0
    30
dvander@0
    31
  public:
dvander@14
    32
    static Module *New(Zone *zone, unsigned nfunctions);
dvander@0
    33
dvander@26
    34
    Function *getFunction(size_t i) {
dvander@26
    35
        return Function::cast(functions_->at(i));
dvander@0
    36
    }
dvander@26
    37
    void setFunction(Zone *zone, size_t i, Function *fun) {
dvander@14
    38
        assert(!functions_->at(i));
dvander@26
    39
        assert(fun);
dvander@26
    40
        functions_->set(zone, i, fun);
dvander@14
    41
    }
dvander@14
    42
dvander@14
    43
    static inline Module *cast(Object *obj) {
dvander@14
    44
        assert(!obj || obj->is(MapKind_Module));
dvander@14
    45
        return reinterpret_cast<Module *>(obj);
dvander@0
    46
    }
dvander@0
    47
};
dvander@0
    48
dvander@0
    49
}
dvander@0
    50
dvander@0
    51
#endif // _include_jc_module_h_