説明を見る。00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_CODEGEN_H_
00029 #define V8_CODEGEN_H_
00030
00031 #include "ast.h"
00032 #include "code-stubs.h"
00033 #include "runtime.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #if defined(ARM)
00062 #include "codegen-arm.h"
00063 #else
00064 #include "codegen-ia32.h"
00065 #endif
00066
00067 namespace v8 { namespace internal {
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 class DeferredCode: public ZoneObject {
00081 public:
00082 explicit DeferredCode(CodeGenerator* generator);
00083 virtual ~DeferredCode() { }
00084
00085 virtual void Generate() = 0;
00086
00087 MacroAssembler* masm() const { return masm_; }
00088 CodeGenerator* generator() const { return generator_; }
00089
00090 Label* enter() { return &enter_; }
00091 Label* exit() { return &exit_; }
00092
00093 int statement_position() const { return statement_position_; }
00094 int position() const { return position_; }
00095
00096 #ifdef DEBUG
00097 void set_comment(const char* comment) { comment_ = comment; }
00098 const char* comment() const { return comment_; }
00099 #else
00100 inline void set_comment(const char* comment) { }
00101 const char* comment() const { return ""; }
00102 #endif
00103
00104 protected:
00105
00106
00107
00108 MacroAssembler* masm_;
00109
00110 private:
00111 CodeGenerator* const generator_;
00112 Label enter_;
00113 Label exit_;
00114 int statement_position_;
00115 int position_;
00116 #ifdef DEBUG
00117 const char* comment_;
00118 #endif
00119 DISALLOW_COPY_AND_ASSIGN(DeferredCode);
00120 };
00121
00122
00123
00124 class RuntimeStub : public CodeStub {
00125 public:
00126 explicit RuntimeStub(Runtime::FunctionId id, int num_arguments)
00127 : id_(id), num_arguments_(num_arguments) { }
00128
00129 void Generate(MacroAssembler* masm);
00130
00131
00132
00133 static const char* GetNameFromMinorKey(int minor_key) {
00134 return Runtime::FunctionForId(IdField::decode(minor_key))->stub_name;
00135 }
00136
00137 private:
00138 Runtime::FunctionId id_;
00139 int num_arguments_;
00140
00141 class ArgumentField: public BitField<int, 0, 16> {};
00142 class IdField: public BitField<Runtime::FunctionId, 16, kMinorBits - 16> {};
00143
00144 Major MajorKey() { return Runtime; }
00145 int MinorKey() {
00146 return IdField::encode(id_) | ArgumentField::encode(num_arguments_);
00147 }
00148
00149 const char* GetName();
00150
00151 #ifdef DEBUG
00152 void Print() {
00153 PrintF("RuntimeStub (id %s)\n", Runtime::FunctionForId(id_)->name);
00154 }
00155 #endif
00156 };
00157
00158
00159 class StackCheckStub : public CodeStub {
00160 public:
00161 StackCheckStub() { }
00162
00163 void Generate(MacroAssembler* masm);
00164
00165 private:
00166
00167 const char* GetName() { return "StackCheckStub"; }
00168
00169 Major MajorKey() { return StackCheck; }
00170 int MinorKey() { return 0; }
00171 };
00172
00173
00174 class UnarySubStub : public CodeStub {
00175 public:
00176 UnarySubStub() { }
00177
00178 private:
00179 Major MajorKey() { return UnarySub; }
00180 int MinorKey() { return 0; }
00181 void Generate(MacroAssembler* masm);
00182
00183 const char* GetName() { return "UnarySubStub"; }
00184 };
00185
00186
00187 class CEntryStub : public CodeStub {
00188 public:
00189 CEntryStub() { }
00190
00191 void Generate(MacroAssembler* masm) { GenerateBody(masm, false); }
00192
00193 protected:
00194 void GenerateBody(MacroAssembler* masm, bool is_debug_break);
00195 void GenerateCore(MacroAssembler* masm,
00196 Label* throw_normal_exception,
00197 Label* throw_out_of_memory_exception,
00198 StackFrame::Type frame_type,
00199 bool do_gc,
00200 bool always_allocate_scope);
00201 void GenerateThrowTOS(MacroAssembler* masm);
00202 void GenerateThrowOutOfMemory(MacroAssembler* masm);
00203
00204 private:
00205 Major MajorKey() { return CEntry; }
00206 int MinorKey() { return 0; }
00207
00208 const char* GetName() { return "CEntryStub"; }
00209 };
00210
00211
00212 class CEntryDebugBreakStub : public CEntryStub {
00213 public:
00214 CEntryDebugBreakStub() { }
00215
00216 void Generate(MacroAssembler* masm) { GenerateBody(masm, true); }
00217
00218 private:
00219 int MinorKey() { return 1; }
00220
00221 const char* GetName() { return "CEntryDebugBreakStub"; }
00222 };
00223
00224
00225 class JSEntryStub : public CodeStub {
00226 public:
00227 JSEntryStub() { }
00228
00229 void Generate(MacroAssembler* masm) { GenerateBody(masm, false); }
00230
00231 protected:
00232 void GenerateBody(MacroAssembler* masm, bool is_construct);
00233
00234 private:
00235 Major MajorKey() { return JSEntry; }
00236 int MinorKey() { return 0; }
00237
00238 const char* GetName() { return "JSEntryStub"; }
00239 };
00240
00241
00242 class JSConstructEntryStub : public JSEntryStub {
00243 public:
00244 JSConstructEntryStub() { }
00245
00246 void Generate(MacroAssembler* masm) { GenerateBody(masm, true); }
00247
00248 private:
00249 int MinorKey() { return 1; }
00250
00251 const char* GetName() { return "JSConstructEntryStub"; }
00252 };
00253
00254
00255 class ArgumentsAccessStub: public CodeStub {
00256 public:
00257 enum Type {
00258 READ_LENGTH,
00259 READ_ELEMENT,
00260 NEW_OBJECT
00261 };
00262
00263 explicit ArgumentsAccessStub(Type type) : type_(type) { }
00264
00265 private:
00266 Type type_;
00267
00268 Major MajorKey() { return ArgumentsAccess; }
00269 int MinorKey() { return type_; }
00270
00271 void Generate(MacroAssembler* masm);
00272 void GenerateReadLength(MacroAssembler* masm);
00273 void GenerateReadElement(MacroAssembler* masm);
00274 void GenerateNewObject(MacroAssembler* masm);
00275
00276 const char* GetName() { return "ArgumentsAccessStub"; }
00277
00278 #ifdef DEBUG
00279 void Print() {
00280 PrintF("ArgumentsAccessStub (type %d)\n", type_);
00281 }
00282 #endif
00283 };
00284
00285
00286 }
00287 }
00288
00289 #endif // V8_CODEGEN_H_