jitcraft/Code.h
changeset 0 c455ebb9a5dc
child 12 75e385f68b7e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/jitcraft/Code.h	Mon Jun 25 02:57:28 2012 -0700
     1.3 @@ -0,0 +1,85 @@
     1.4 +/*
     1.5 + * Copyright (C) 2012 David Anderson
     1.6 + *
     1.7 + * This file is part of JITCraft.
     1.8 + *
     1.9 + * JITCraft is free software: you can redistribute it and/or modify it under
    1.10 + * the terms of the GNU General Public License as published by the Free
    1.11 + * Software Foundation, either version 3 of the License, or (at your option)
    1.12 + * any later version.
    1.13 + * 
    1.14 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    1.15 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License along with
    1.19 + * JITCraft. If not, see http://www.gnu.org/licenses/.
    1.20 + */
    1.21 +#ifndef _include_jc_code_h_
    1.22 +#define _include_jc_code_h_
    1.23 +
    1.24 +#include "Opcodes.h"
    1.25 +
    1.26 +namespace jc {
    1.27 +
    1.28 +class Module;
    1.29 +class Type;
    1.30 +
    1.31 +class Code
    1.32 +{
    1.33 +    bytecode *start_;
    1.34 +    unsigned length_;
    1.35 +    Type **locals_;
    1.36 +    unsigned nlocals_;
    1.37 +    unsigned maxStackDepth_;
    1.38 +    Module *module_;
    1.39 +    Type **args_;
    1.40 +    unsigned nargs_;
    1.41 +
    1.42 +  public:
    1.43 +    Code(Module *module, bytecode *start, unsigned length,
    1.44 +         Type **args, unsigned nargs,
    1.45 +         Type **locals, unsigned nlocals,
    1.46 +         unsigned maxStackDepth)
    1.47 +      : start_(start),
    1.48 +        length_(length),
    1.49 +        locals_(locals),
    1.50 +        nlocals_(nlocals),
    1.51 +        maxStackDepth_(maxStackDepth),
    1.52 +        module_(module),
    1.53 +        args_(args),
    1.54 +        nargs_(nargs)
    1.55 +    {
    1.56 +    }
    1.57 +
    1.58 +    Module *module() const {
    1.59 +        return module_;
    1.60 +    }
    1.61 +    bytecode *start() const {
    1.62 +        return start_;
    1.63 +    }
    1.64 +    unsigned length() const {
    1.65 +        return length_;
    1.66 +    }
    1.67 +    Type *localType(size_t index) const {
    1.68 +        assert(index < nlocals());
    1.69 +        return locals_[index];
    1.70 +    }
    1.71 +    Type *argType(size_t index) const {
    1.72 +        assert(index < nlocals());
    1.73 +        return args_[index];
    1.74 +    }
    1.75 +    unsigned nlocals() const {
    1.76 +        return nlocals_;
    1.77 +    }
    1.78 +    unsigned nargs() const {
    1.79 +        return nargs_;
    1.80 +    }
    1.81 +    unsigned maxStackDepth() const {
    1.82 +        return maxStackDepth_;
    1.83 +    }
    1.84 +};
    1.85 +
    1.86 +}
    1.87 +
    1.88 +#endif // _include_jc_code_h_