Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/compiler.h

Issue 3566003: Introduce subclasses of class CompilationInfo. (Closed)
Patch Set: Rebased to HEAD. Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/compiler.cc » ('j') | src/compiler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 23 matching lines...) Expand all
34 #include "register-allocator.h" 34 #include "register-allocator.h"
35 #include "zone.h" 35 #include "zone.h"
36 36
37 namespace v8 { 37 namespace v8 {
38 namespace internal { 38 namespace internal {
39 39
40 // CompilationInfo encapsulates some information known at compile time. It 40 // CompilationInfo encapsulates some information known at compile time. It
41 // is constructed based on the resources available at compile-time. 41 // is constructed based on the resources available at compile-time.
42 class CompilationInfo BASE_EMBEDDED { 42 class CompilationInfo BASE_EMBEDDED {
43 public: 43 public:
44 // Lazy compilation of a JSFunction. 44 virtual ~CompilationInfo() {}
45 CompilationInfo(Handle<JSFunction> closure, int loop_nesting) 45
46 : closure_(closure), 46 // Dispatched behavior.
47 function_(NULL), 47 virtual Handle<SharedFunctionInfo> shared_info() const = 0;
48 is_eval_(false), 48
49 loop_nesting_(loop_nesting) { 49 virtual Handle<Script> script() const {
50 ASSERT(!closure_.is_null() && 50 return Handle<Script>(Script::cast(shared_info()->script()));
51 shared_info_.is_null() &&
52 script_.is_null());
53 } 51 }
54 52
55 // Lazy compilation based on SharedFunctionInfo. 53 virtual Handle<JSFunction> closure() const {
56 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info) 54 return Handle<JSFunction>::null();
57 : shared_info_(shared_info),
58 function_(NULL),
59 is_eval_(false),
60 loop_nesting_(0) {
61 ASSERT(closure_.is_null() &&
62 !shared_info_.is_null() &&
63 script_.is_null());
64 } 55 }
65 56
66 // Eager compilation. 57 virtual bool is_eval() const { return false; }
67 CompilationInfo(FunctionLiteral* literal, Handle<Script> script, bool is_eval)
68 : script_(script),
69 function_(literal),
70 is_eval_(is_eval),
71 loop_nesting_(0) {
72 ASSERT(closure_.is_null() &&
73 shared_info_.is_null() &&
74 !script_.is_null());
75 }
76 58
77 // We can only get a JSFunction if we actually have one. 59 virtual int loop_nesting() const { return 0; }
78 Handle<JSFunction> closure() { return closure_; }
79 60
80 // We can get a SharedFunctionInfo from a JSFunction or if we actually 61 virtual bool has_global_object() const { return false; }
81 // have one. 62 virtual GlobalObject* global_object() const { return NULL; }
82 Handle<SharedFunctionInfo> shared_info() {
83 if (!closure().is_null()) {
84 return Handle<SharedFunctionInfo>(closure()->shared());
85 } else {
86 return shared_info_;
87 }
88 }
89
90 // We can always get a script. Either we have one or we can get a shared
91 // function info.
92 Handle<Script> script() {
93 if (!script_.is_null()) {
94 return script_;
95 } else {
96 ASSERT(shared_info()->script()->IsScript());
97 return Handle<Script>(Script::cast(shared_info()->script()));
98 }
99 }
100 63
101 // There should always be a function literal, but it may be set after 64 // There should always be a function literal, but it may be set after
102 // construction (for lazy compilation). 65 // construction (for lazy compilation).
103 FunctionLiteral* function() { return function_; } 66 FunctionLiteral* function() { return function_; }
104 void set_function(FunctionLiteral* literal) { function_ = literal; } 67 void set_function(FunctionLiteral* literal) { function_ = literal; }
105 68
106 // Simple accessors.
107 bool is_eval() { return is_eval_; }
108 int loop_nesting() { return loop_nesting_; }
109
110 bool has_global_object() {
111 return !closure().is_null() && (closure()->context()->global() != NULL);
112 }
113
114 GlobalObject* global_object() {
115 return has_global_object() ? closure()->context()->global() : NULL;
116 }
117
118 // Derived accessors. 69 // Derived accessors.
119 Scope* scope() { return function()->scope(); } 70 Scope* scope() { return function()->scope(); }
120 71
72 protected:
73 CompilationInfo() : function_(NULL) {}
74
121 private: 75 private:
122 Handle<JSFunction> closure_;
123 Handle<SharedFunctionInfo> shared_info_;
124 Handle<Script> script_;
125
126 FunctionLiteral* function_; 76 FunctionLiteral* function_;
127 77
128 bool is_eval_;
129 int loop_nesting_;
130
131 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); 78 DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
132 }; 79 };
133 80
134 81
82 class EagerCompilationInfo: public CompilationInfo {
83 public:
84 EagerCompilationInfo(Handle<Script> script, bool is_eval)
85 : script_(script), is_eval_(is_eval) {
86 ASSERT(!script.is_null());
87 }
88
89 // Overridden functions from the base class.
90 virtual Handle<SharedFunctionInfo> shared_info() const {
91 return Handle<SharedFunctionInfo>::null();
92 }
93
94 virtual Handle<Script> script() const { return script_; }
95
96 virtual bool is_eval() const { return is_eval_; }
97
98 private:
99 Handle<Script> script_;
100 bool is_eval_;
101 };
102
103
104 class LazySharedCompilationInfo: public CompilationInfo {
105 public:
106 explicit LazySharedCompilationInfo(Handle<SharedFunctionInfo> shared_info)
107 : shared_info_(shared_info) {
108 ASSERT(!shared_info.is_null());
109 }
110
111 // Overridden functions from the base class.
112 virtual Handle<SharedFunctionInfo> shared_info() const {
113 return shared_info_;
114 }
115
116 private:
117 Handle<SharedFunctionInfo> shared_info_;
118 };
119
120
121 class LazyFunctionCompilationInfo: public CompilationInfo {
122 public:
123 LazyFunctionCompilationInfo(Handle<JSFunction> closure,
124 int loop_nesting)
125 : closure_(closure), loop_nesting_(loop_nesting) {
126 ASSERT(!closure.is_null());
127 }
128
129 // Overridden functions from the base class.
130 virtual Handle<SharedFunctionInfo> shared_info() const {
131 return Handle<SharedFunctionInfo>(closure_->shared());
132 }
133
134 virtual int loop_nesting() const { return loop_nesting_; }
135
136 virtual bool has_global_object() const {
137 return closure_->context()->global() != NULL;
138 }
139
140 virtual GlobalObject* global_object() const {
141 return closure_->context()->global();
142 }
143
144 private:
145 Handle<JSFunction> closure_;
146 int loop_nesting_;
147 };
148
149
135 // The V8 compiler 150 // The V8 compiler
136 // 151 //
137 // General strategy: Source code is translated into an anonymous function w/o 152 // General strategy: Source code is translated into an anonymous function w/o
138 // parameters which then can be executed. If the source code contains other 153 // parameters which then can be executed. If the source code contains other
139 // functions, they will be compiled and allocated as part of the compilation 154 // functions, they will be compiled and allocated as part of the compilation
140 // of the source code. 155 // of the source code.
141 156
142 // Please note this interface returns shared function infos. 157 // Please note this interface returns shared function infos.
143 // This means you need to call Factory::NewFunctionFromSharedFunctionInfo 158 // This means you need to call Factory::NewFunctionFromSharedFunctionInfo
144 // before you have a real function with a context. 159 // before you have a real function with a context.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 FrameElement::ClearConstantList(); 228 FrameElement::ClearConstantList();
214 Result::ClearConstantList(); 229 Result::ClearConstantList();
215 } 230 }
216 } 231 }
217 }; 232 };
218 233
219 234
220 } } // namespace v8::internal 235 } } // namespace v8::internal
221 236
222 #endif // V8_COMPILER_H_ 237 #endif // V8_COMPILER_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler.cc » ('j') | src/compiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698