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

Side by Side Diff: src/rewriter.cc

Issue 3561012: More refactoring of class Compiler's interface. (Closed)
Patch Set: Reindent some code, change some copyright dates. 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2010 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "rewriter.h"
31
30 #include "ast.h" 32 #include "ast.h"
33 #include "compiler.h"
31 #include "scopes.h" 34 #include "scopes.h"
32 #include "rewriter.h"
33 35
34 namespace v8 { 36 namespace v8 {
35 namespace internal { 37 namespace internal {
36 38
37 class AstOptimizer: public AstVisitor { 39 class AstOptimizer: public AstVisitor {
38 public: 40 public:
39 explicit AstOptimizer() : has_function_literal_(false) {} 41 explicit AstOptimizer() : has_function_literal_(false) {}
40 42
41 void Optimize(ZoneList<Statement*>* statements); 43 void Optimize(ZoneList<Statement*>* statements);
42 44
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 UNREACHABLE(); 981 UNREACHABLE();
980 } 982 }
981 983
982 984
983 void Processor::VisitThisFunction(ThisFunction* node) { 985 void Processor::VisitThisFunction(ThisFunction* node) {
984 USE(node); 986 USE(node);
985 UNREACHABLE(); 987 UNREACHABLE();
986 } 988 }
987 989
988 990
989 bool Rewriter::Process(FunctionLiteral* function) { 991 // Assumes code has been parsed and scopes hve been analyzed. Mutates the
990 HistogramTimerScope timer(&Counters::rewriting); 992 // AST, so the AST should not continue to be used in the case of failure.
993 bool Rewriter::Rewrite(CompilationInfo* info) {
994 FunctionLiteral* function = info->function();
995 ASSERT(function != NULL);
991 Scope* scope = function->scope(); 996 Scope* scope = function->scope();
997 ASSERT(scope != NULL);
992 if (scope->is_function_scope()) return true; 998 if (scope->is_function_scope()) return true;
993 999
994 ZoneList<Statement*>* body = function->body(); 1000 ZoneList<Statement*>* body = function->body();
995 if (body->is_empty()) return true; 1001 if (!body->is_empty()) {
1002 VariableProxy* result = scope->NewTemporary(Factory::result_symbol());
1003 Processor processor(result);
1004 processor.Process(body);
1005 if (processor.HasStackOverflow()) return false;
996 1006
997 VariableProxy* result = scope->NewTemporary(Factory::result_symbol()); 1007 if (processor.result_assigned()) body->Add(new ReturnStatement(result));
998 Processor processor(result); 1008 }
999 processor.Process(body);
1000 if (processor.HasStackOverflow()) return false;
1001 1009
1002 if (processor.result_assigned()) body->Add(new ReturnStatement(result));
1003 return true; 1010 return true;
1004 } 1011 }
1005 1012
1006 1013
1007 bool Rewriter::Optimize(FunctionLiteral* function) { 1014 // Assumes code has been parsed and scopes have been analyzed. Mutates the
1015 // AST, so the AST should not continue to be used in the case of failure.
1016 bool Rewriter::Analyze(CompilationInfo* info) {
1017 FunctionLiteral* function = info->function();
1018 ASSERT(function != NULL && function->scope() != NULL);
1019
1008 ZoneList<Statement*>* body = function->body(); 1020 ZoneList<Statement*>* body = function->body();
1009
1010 if (FLAG_optimize_ast && !body->is_empty()) { 1021 if (FLAG_optimize_ast && !body->is_empty()) {
1011 HistogramTimerScope timer(&Counters::ast_optimization);
1012 AstOptimizer optimizer; 1022 AstOptimizer optimizer;
1013 optimizer.Optimize(body); 1023 optimizer.Optimize(body);
1014 if (optimizer.HasStackOverflow()) { 1024 if (optimizer.HasStackOverflow()) return false;
1015 return false;
1016 }
1017 } 1025 }
1018 return true; 1026 return true;
1019 } 1027 }
1020 1028
1021 1029
1022 } } // namespace v8::internal 1030 } } // namespace v8::internal
OLDNEW
« src/compiler.h ('K') | « src/rewriter.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698