The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / codegen.h @ 40c0f755

History | View | Annotate | Download (8.45 KB)

1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
#ifndef V8_CODEGEN_H_
29
#define V8_CODEGEN_H_
30

    
31
#include "ast.h"
32
#include "code-stubs.h"
33
#include "runtime.h"
34

    
35
// Include the declaration of the architecture defined class CodeGenerator.
36
// The contract  to the shared code is that the the CodeGenerator is a subclass
37
// of Visitor and that the following methods are available publicly:
38
//   MakeCode
39
//   SetFunctionInfo
40
//   masm
41
//   frame
42
//   has_valid_frame
43
//   SetFrame
44
//   DeleteFrame
45
//   allocator
46
//   AddDeferred
47
//   in_spilled_code
48
//   set_in_spilled_code
49
//
50
// These methods are either used privately by the shared code or implemented as
51
// shared code:
52
//   CodeGenerator
53
//   ~CodeGenerator
54
//   ProcessDeferred
55
//   ClearDeferred
56
//   GenCode
57
//   BuildBoilerplate
58
//   ComputeCallInitialize
59
//   ComputeCallInitializeInLoop
60
//   ProcessDeclarations
61
//   DeclareGlobals
62
//   CheckForInlineRuntimeCall
63
//   GenerateFastCaseSwitchStatement
64
//   GenerateFastCaseSwitchCases
65
//   TryGenerateFastCaseSwitchStatement
66
//   GenerateFastCaseSwitchJumpTable
67
//   FastCaseSwitchMinCaseCount
68
//   FastCaseSwitchMaxOverheadFactor
69
//   CodeForFunctionPosition
70
//   CodeForReturnPosition
71
//   CodeForStatementPosition
72
//   CodeForSourcePosition
73

    
74
#ifdef ARM
75
#include "codegen-arm.h"
76
#else
77
#include "codegen-ia32.h"
78
#endif
79

    
80
namespace v8 { namespace internal {
81

    
82

    
83
// Use lazy compilation; defaults to true.
84
// NOTE: Do not remove non-lazy compilation until we can properly
85
//       install extensions with lazy compilation enabled. At the
86
//       moment, this doesn't work for the extensions in Google3,
87
//       and we can only run the tests with --nolazy.
88

    
89

    
90
// Deferred code objects are small pieces of code that are compiled
91
// out of line. They are used to defer the compilation of uncommon
92
// paths thereby avoiding expensive jumps around uncommon code parts.
93
class DeferredCode: public ZoneObject {
94
 public:
95
  explicit DeferredCode(CodeGenerator* generator);
96
  virtual ~DeferredCode() { }
97

    
98
  virtual void Generate() = 0;
99

    
100
  // Unuse the entry and exit targets, deallocating all virtual frames
101
  // held by them.  It will be impossible to emit a (correct) jump
102
  // into or out of the deferred code after clearing.
103
  void Clear() {
104
    enter_.Unuse();
105
    exit_.Unuse();
106
  }
107

    
108
  MacroAssembler* masm() const { return masm_; }
109
  CodeGenerator* generator() const { return generator_; }
110

    
111
  JumpTarget* enter() { return &enter_; }
112
  void BindExit() { exit_.Bind(0); }
113
  void BindExit(Result* result) { exit_.Bind(result, 1); }
114
  void BindExit(Result* result0, Result* result1, Result* result2) {
115
    exit_.Bind(result0, result1, result2, 3);
116
  }
117

    
118
  int statement_position() const { return statement_position_; }
119
  int position() const { return position_; }
120

    
121
#ifdef DEBUG
122
  void set_comment(const char* comment) { comment_ = comment; }
123
  const char* comment() const { return comment_; }
124
#else
125
  inline void set_comment(const char* comment) { }
126
  const char* comment() const { return ""; }
127
#endif
128

    
129
 protected:
130
  CodeGenerator* const generator_;
131
  MacroAssembler* const masm_;
132
  JumpTarget enter_;
133
  JumpTarget exit_;
134

    
135
 private:
136
  int statement_position_;
137
  int position_;
138
#ifdef DEBUG
139
  const char* comment_;
140
#endif
141
  DISALLOW_COPY_AND_ASSIGN(DeferredCode);
142
};
143

    
144

    
145
// RuntimeStub models code stubs calling entry points in the Runtime class.
146
class RuntimeStub : public CodeStub {
147
 public:
148
  explicit RuntimeStub(Runtime::FunctionId id, int num_arguments)
149
      : id_(id), num_arguments_(num_arguments) { }
150

    
151
  void Generate(MacroAssembler* masm);
152

    
153
  // Disassembler support.  It is useful to be able to print the name
154
  // of the runtime function called through this stub.
155
  static const char* GetNameFromMinorKey(int minor_key) {
156
    return Runtime::FunctionForId(IdField::decode(minor_key))->stub_name;
157
  }
158

    
159
 private:
160
  Runtime::FunctionId id_;
161
  int num_arguments_;
162

    
163
  class ArgumentField: public BitField<int,  0, 16> {};
164
  class IdField: public BitField<Runtime::FunctionId, 16, kMinorBits - 16> {};
165

    
166
  Major MajorKey() { return Runtime; }
167
  int MinorKey() {
168
    return IdField::encode(id_) | ArgumentField::encode(num_arguments_);
169
  }
170

    
171
  const char* GetName();
172

    
173
#ifdef DEBUG
174
  void Print() {
175
    PrintF("RuntimeStub (id %s)\n", Runtime::FunctionForId(id_)->name);
176
  }
177
#endif
178
};
179

    
180

    
181
class StackCheckStub : public CodeStub {
182
 public:
183
  StackCheckStub() { }
184

    
185
  void Generate(MacroAssembler* masm);
186

    
187
 private:
188

    
189
  const char* GetName() { return "StackCheckStub"; }
190

    
191
  Major MajorKey() { return StackCheck; }
192
  int MinorKey() { return 0; }
193
};
194

    
195

    
196
class UnarySubStub : public CodeStub {
197
 public:
198
  UnarySubStub() { }
199

    
200
 private:
201
  Major MajorKey() { return UnarySub; }
202
  int MinorKey() { return 0; }
203
  void Generate(MacroAssembler* masm);
204

    
205
  const char* GetName() { return "UnarySubStub"; }
206
};
207

    
208

    
209
class CEntryStub : public CodeStub {
210
 public:
211
  CEntryStub() { }
212

    
213
  void Generate(MacroAssembler* masm) { GenerateBody(masm, false); }
214

    
215
 protected:
216
  void GenerateBody(MacroAssembler* masm, bool is_debug_break);
217
  void GenerateCore(MacroAssembler* masm,
218
                    Label* throw_normal_exception,
219
                    Label* throw_out_of_memory_exception,
220
                    StackFrame::Type frame_type,
221
                    bool do_gc,
222
                    bool always_allocate_scope);
223
  void GenerateThrowTOS(MacroAssembler* masm);
224
  void GenerateThrowOutOfMemory(MacroAssembler* masm);
225

    
226
 private:
227
  Major MajorKey() { return CEntry; }
228
  int MinorKey() { return 0; }
229

    
230
  const char* GetName() { return "CEntryStub"; }
231
};
232

    
233

    
234
class CEntryDebugBreakStub : public CEntryStub {
235
 public:
236
  CEntryDebugBreakStub() { }
237

    
238
  void Generate(MacroAssembler* masm) { GenerateBody(masm, true); }
239

    
240
 private:
241
  int MinorKey() { return 1; }
242

    
243
  const char* GetName() { return "CEntryDebugBreakStub"; }
244
};
245

    
246

    
247
class JSEntryStub : public CodeStub {
248
 public:
249
  JSEntryStub() { }
250

    
251
  void Generate(MacroAssembler* masm) { GenerateBody(masm, false); }
252

    
253
 protected:
254
  void GenerateBody(MacroAssembler* masm, bool is_construct);
255

    
256
 private:
257
  Major MajorKey() { return JSEntry; }
258
  int MinorKey() { return 0; }
259

    
260
  const char* GetName() { return "JSEntryStub"; }
261
};
262

    
263

    
264
class JSConstructEntryStub : public JSEntryStub {
265
 public:
266
  JSConstructEntryStub() { }
267

    
268
  void Generate(MacroAssembler* masm) { GenerateBody(masm, true); }
269

    
270
 private:
271
  int MinorKey() { return 1; }
272

    
273
  const char* GetName() { return "JSConstructEntryStub"; }
274
};
275

    
276

    
277
class ArgumentsAccessStub: public CodeStub {
278
 public:
279
  enum Type {
280
    READ_LENGTH,
281
    READ_ELEMENT,
282
    NEW_OBJECT
283
  };
284

    
285
  explicit ArgumentsAccessStub(Type type) : type_(type) { }
286

    
287
 private:
288
  Type type_;
289

    
290
  Major MajorKey() { return ArgumentsAccess; }
291
  int MinorKey() { return type_; }
292

    
293
  void Generate(MacroAssembler* masm);
294
  void GenerateReadLength(MacroAssembler* masm);
295
  void GenerateReadElement(MacroAssembler* masm);
296
  void GenerateNewObject(MacroAssembler* masm);
297

    
298
  const char* GetName() { return "ArgumentsAccessStub"; }
299

    
300
#ifdef DEBUG
301
  void Print() {
302
    PrintF("ArgumentsAccessStub (type %d)\n", type_);
303
  }
304
#endif
305
};
306

    
307

    
308
}  // namespace internal
309
}  // namespace v8
310

    
311
#endif  // V8_CODEGEN_H_