1.1 --- a/jitcraft/Code.h Fri Jun 29 19:35:17 2012 -0700
1.2 +++ b/jitcraft/Code.h Sat Jun 30 19:38:53 2012 -0700
1.3 @@ -19,64 +19,80 @@
1.4 #define _include_jc_code_h_
1.5
1.6 #include "Opcodes.h"
1.7 +#include "Barriers.h"
1.8 +#include "Heap.h"
1.9 +#include "Types.h"
1.10 +#include "FixedArray.h"
1.11
1.12 namespace jc {
1.13
1.14 class Module;
1.15 class Type;
1.16
1.17 -class Code
1.18 +class Code : public Object
1.19 {
1.20 - bytecode *start_;
1.21 - unsigned length_;
1.22 - Type **locals_;
1.23 - unsigned nlocals_;
1.24 - unsigned maxStackDepth_;
1.25 - Module *module_;
1.26 - Type **args_;
1.27 - unsigned nargs_;
1.28 + OBJECT_FIELD(ByteArray *, bytecode);
1.29 + OBJECT_FIELD(FixedArray *, locals);
1.30 + OBJECT_FIELD(FixedArray *, args);
1.31 + OBJECT_FIELD(uint32, maxStackDepth);
1.32 + OBJECT_FIELD(VoidPtr, module);
1.33 + OBJECT_FIELD(FixedArray *, maps);
1.34 +
1.35 + private:
1.36 + void init(ByteArray *bytecode, FixedArray *locals, FixedArray *args,
1.37 + FixedArray *maps, unsigned maxStackDepth, Module *module);
1.38 +
1.39 + ByteArray *code() {
1.40 + return ByteArray::cast(READ_FIELD_OBJ(bytecode));
1.41 + }
1.42 + FixedArray *locals() {
1.43 + return FixedArray::cast(READ_FIELD_OBJ(locals));
1.44 + }
1.45 + FixedArray *args() {
1.46 + return FixedArray::cast(READ_FIELD_OBJ(args));
1.47 + }
1.48 + FixedArray *maps() {
1.49 + return FixedArray::cast(READ_FIELD_OBJ(maps));
1.50 + }
1.51
1.52 public:
1.53 - Code(Module *module, bytecode *start, unsigned length,
1.54 - Type **args, unsigned nargs,
1.55 - Type **locals, unsigned nlocals,
1.56 - unsigned maxStackDepth)
1.57 - : start_(start),
1.58 - length_(length),
1.59 - locals_(locals),
1.60 - nlocals_(nlocals),
1.61 - maxStackDepth_(maxStackDepth),
1.62 - module_(module),
1.63 - args_(args),
1.64 - nargs_(nargs)
1.65 - {
1.66 + // :TODO: use handles
1.67 + static Code *New(Zone *zone, ByteArray *bytecode, FixedArray *locals, FixedArray *args,
1.68 + FixedArray *maps, unsigned maxStackDepth, Module *module);
1.69 +
1.70 + Module *module() {
1.71 + return (Module *)READ_FIELD(module);
1.72 + }
1.73 + bytecode *start() {
1.74 + return code()->raw();
1.75 + }
1.76 + unsigned length() {
1.77 + return code()->length();
1.78 + }
1.79 + Type *localType(size_t index) {
1.80 + assert(index < nlocals());
1.81 + return Type::cast(locals()->at(index));
1.82 + }
1.83 + Type *argType(size_t index) {
1.84 + assert(index < nlocals());
1.85 + return Type::cast(args()->at(index));
1.86 + }
1.87 + unsigned nlocals() {
1.88 + return locals()->length();
1.89 + }
1.90 + unsigned nargs() {
1.91 + return args()->length();
1.92 + }
1.93 + unsigned maxStackDepth() {
1.94 + return READ_FIELD(maxStackDepth);
1.95 + }
1.96 + Map *map(size_t index) {
1.97 + return Map::cast(maps()->at(index));
1.98 }
1.99
1.100 - Module *module() const {
1.101 - return module_;
1.102 - }
1.103 - bytecode *start() const {
1.104 - return start_;
1.105 - }
1.106 - unsigned length() const {
1.107 - return length_;
1.108 - }
1.109 - Type *localType(size_t index) const {
1.110 - assert(index < nlocals());
1.111 - return locals_[index];
1.112 - }
1.113 - Type *argType(size_t index) const {
1.114 - assert(index < nlocals());
1.115 - return args_[index];
1.116 - }
1.117 - unsigned nlocals() const {
1.118 - return nlocals_;
1.119 - }
1.120 - unsigned nargs() const {
1.121 - return nargs_;
1.122 - }
1.123 - unsigned maxStackDepth() const {
1.124 - return maxStackDepth_;
1.125 + static Code *cast(Object *obj) {
1.126 + assert(obj->is(MapKind_Code));
1.127 + return reinterpret_cast<Code *>(obj);
1.128 }
1.129 };
1.130