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

Side by Side Diff: src/compiler.h

Issue 655002: Merge revisions 3777-3813 from bleding_edge to partial snapshots ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « src/codegen-inl.h ('k') | src/compiler.cc » ('j') | no next file with comments »
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 17 matching lines...) Expand all
28 #ifndef V8_COMPILER_H_ 28 #ifndef V8_COMPILER_H_
29 #define V8_COMPILER_H_ 29 #define V8_COMPILER_H_
30 30
31 #include "frame-element.h" 31 #include "frame-element.h"
32 #include "parser.h" 32 #include "parser.h"
33 #include "zone.h" 33 #include "zone.h"
34 34
35 namespace v8 { 35 namespace v8 {
36 namespace internal { 36 namespace internal {
37 37
38 // CompilationInfo encapsulates some information known at compile time. 38 // CompilationInfo encapsulates some information known at compile time. It
39 // is constructed based on the resources available at compile-time.
39 class CompilationInfo BASE_EMBEDDED { 40 class CompilationInfo BASE_EMBEDDED {
40 public: 41 public:
41 CompilationInfo(Handle<SharedFunctionInfo> shared_info, 42 // Lazy compilation of a JSFunction.
42 Handle<Object> receiver, 43 CompilationInfo(Handle<JSFunction> closure,
43 int loop_nesting) 44 int loop_nesting,
44 : shared_info_(shared_info), 45 Handle<Object> receiver)
45 receiver_(receiver), 46 : closure_(closure),
47 function_(NULL),
48 is_eval_(false),
46 loop_nesting_(loop_nesting), 49 loop_nesting_(loop_nesting),
47 has_this_properties_(false), 50 receiver_(receiver) {
48 has_globals_(false) { 51 Initialize();
52 ASSERT(!closure_.is_null() &&
53 shared_info_.is_null() &&
54 script_.is_null());
49 } 55 }
50 56
51 Handle<SharedFunctionInfo> shared_info() { return shared_info_; } 57 // Lazy compilation based on SharedFunctionInfo.
58 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info)
59 : shared_info_(shared_info),
60 function_(NULL),
61 is_eval_(false),
62 loop_nesting_(0) {
63 Initialize();
64 ASSERT(closure_.is_null() &&
65 !shared_info_.is_null() &&
66 script_.is_null());
67 }
52 68
69 // Eager compilation.
70 CompilationInfo(FunctionLiteral* literal, Handle<Script> script, bool is_eval)
71 : script_(script),
72 function_(literal),
73 is_eval_(is_eval),
74 loop_nesting_(0) {
75 Initialize();
76 ASSERT(closure_.is_null() &&
77 shared_info_.is_null() &&
78 !script_.is_null());
79 }
80
81 // We can only get a JSFunction if we actually have one.
82 Handle<JSFunction> closure() { return closure_; }
83
84 // We can get a SharedFunctionInfo from a JSFunction or if we actually
85 // have one.
86 Handle<SharedFunctionInfo> shared_info() {
87 if (!closure().is_null()) {
88 return Handle<SharedFunctionInfo>(closure()->shared());
89 } else {
90 return shared_info_;
91 }
92 }
93
94 // We can always get a script. Either we have one or we can get a shared
95 // function info.
96 Handle<Script> script() {
97 if (!script_.is_null()) {
98 return script_;
99 } else {
100 ASSERT(shared_info()->script()->IsScript());
101 return Handle<Script>(Script::cast(shared_info()->script()));
102 }
103 }
104
105 // There should always be a function literal, but it may be set after
106 // construction (for lazy compilation).
107 FunctionLiteral* function() { return function_; }
108 void set_function(FunctionLiteral* literal) {
109 ASSERT(function_ == NULL);
110 function_ = literal;
111 }
112
113 // Simple accessors.
114 bool is_eval() { return is_eval_; }
115 int loop_nesting() { return loop_nesting_; }
53 bool has_receiver() { return !receiver_.is_null(); } 116 bool has_receiver() { return !receiver_.is_null(); }
54 Handle<Object> receiver() { return receiver_; } 117 Handle<Object> receiver() { return receiver_; }
55 118
56 int loop_nesting() { return loop_nesting_; } 119 // Accessors for mutable fields, possibly set by analysis passes with
57 120 // default values given by Initialize.
58 bool has_this_properties() { return has_this_properties_; } 121 bool has_this_properties() { return has_this_properties_; }
59 void set_has_this_properties(bool flag) { has_this_properties_ = flag; } 122 void set_has_this_properties(bool flag) { has_this_properties_ = flag; }
60 123
124 bool has_global_object() {
125 return !closure().is_null() && (closure()->context()->global() != NULL);
126 }
127
128 GlobalObject* global_object() {
129 return has_global_object() ? closure()->context()->global() : NULL;
130 }
131
61 bool has_globals() { return has_globals_; } 132 bool has_globals() { return has_globals_; }
62 void set_has_globals(bool flag) { has_globals_ = flag; } 133 void set_has_globals(bool flag) { has_globals_ = flag; }
63 134
135 // Derived accessors.
136 Scope* scope() { return function()->scope(); }
137
64 private: 138 private:
139 void Initialize() {
140 has_this_properties_ = false;
141 has_globals_ = false;
142 }
143
144 Handle<JSFunction> closure_;
65 Handle<SharedFunctionInfo> shared_info_; 145 Handle<SharedFunctionInfo> shared_info_;
146 Handle<Script> script_;
147
148 FunctionLiteral* function_;
149
150 bool is_eval_;
151 int loop_nesting_;
152
66 Handle<Object> receiver_; 153 Handle<Object> receiver_;
67 int loop_nesting_; 154
68 bool has_this_properties_; 155 bool has_this_properties_;
69 bool has_globals_; 156 bool has_globals_;
157
158 DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
70 }; 159 };
71 160
72 161
73 // The V8 compiler 162 // The V8 compiler
74 // 163 //
75 // General strategy: Source code is translated into an anonymous function w/o 164 // General strategy: Source code is translated into an anonymous function w/o
76 // parameters which then can be executed. If the source code contains other 165 // parameters which then can be executed. If the source code contains other
77 // functions, they will be compiled and allocated as part of the compilation 166 // functions, they will be compiled and allocated as part of the compilation
78 // of the source code. 167 // of the source code.
79 168
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 FrameElement::ClearConstantList(); 234 FrameElement::ClearConstantList();
146 Result::ClearConstantList(); 235 Result::ClearConstantList();
147 } 236 }
148 } 237 }
149 }; 238 };
150 239
151 240
152 } } // namespace v8::internal 241 } } // namespace v8::internal
153 242
154 #endif // V8_COMPILER_H_ 243 #endif // V8_COMPILER_H_
OLDNEW
« no previous file with comments | « src/codegen-inl.h ('k') | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698