OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "ast.h" | 33 #include "ast.h" |
34 | 34 |
35 namespace v8 { | 35 namespace v8 { |
36 namespace internal { | 36 namespace internal { |
37 | 37 |
38 | 38 |
39 class FastCodeGenerator: public AstVisitor { | 39 class FastCodeGenerator: public AstVisitor { |
40 public: | 40 public: |
41 FastCodeGenerator(MacroAssembler* masm, Handle<Script> script, bool is_eval) | 41 FastCodeGenerator(MacroAssembler* masm, Handle<Script> script, bool is_eval) |
42 : masm_(masm), function_(NULL), script_(script), is_eval_(is_eval) { | 42 : masm_(masm), |
| 43 function_(NULL), |
| 44 script_(script), |
| 45 is_eval_(is_eval), |
| 46 true_label_(NULL), |
| 47 false_label_(NULL) { |
43 } | 48 } |
44 | 49 |
45 static Handle<Code> MakeCode(FunctionLiteral* fun, | 50 static Handle<Code> MakeCode(FunctionLiteral* fun, |
46 Handle<Script> script, | 51 Handle<Script> script, |
47 bool is_eval); | 52 bool is_eval); |
48 | 53 |
49 void Generate(FunctionLiteral* fun); | 54 void Generate(FunctionLiteral* fun); |
50 | 55 |
51 private: | 56 private: |
52 int SlotOffset(Slot* slot); | 57 int SlotOffset(Slot* slot); |
53 | 58 |
54 void Move(Expression::Context destination, Register source); | 59 void Move(Expression::Context destination, Register source); |
55 void Move(Expression::Context destination, Slot* source); | 60 void Move(Expression::Context destination, Slot* source); |
56 void Move(Expression::Context destination, Literal* source); | 61 void Move(Expression::Context destination, Literal* source); |
57 | 62 |
58 // Drop the TOS, and store source to destination. | 63 // Drop the TOS, and store source to destination. |
59 // If destination is TOS, just overwrite TOS with source. | 64 // If destination is TOS, just overwrite TOS with source. |
60 void DropAndMove(Expression::Context destination, Register source); | 65 void DropAndMove(Expression::Context destination, Register source); |
61 | 66 |
| 67 // Test the JavaScript value in source as if in a test context, compile |
| 68 // control flow to a pair of labels. |
| 69 void TestAndBranch(Register source, Label* true_label, Label* false_label); |
| 70 |
62 void VisitDeclarations(ZoneList<Declaration*>* declarations); | 71 void VisitDeclarations(ZoneList<Declaration*>* declarations); |
63 Handle<JSFunction> BuildBoilerplate(FunctionLiteral* fun); | 72 Handle<JSFunction> BuildBoilerplate(FunctionLiteral* fun); |
64 void DeclareGlobals(Handle<FixedArray> pairs); | 73 void DeclareGlobals(Handle<FixedArray> pairs); |
65 | 74 |
66 void SetFunctionPosition(FunctionLiteral* fun); | 75 void SetFunctionPosition(FunctionLiteral* fun); |
67 void SetReturnPosition(FunctionLiteral* fun); | 76 void SetReturnPosition(FunctionLiteral* fun); |
68 void SetStatementPosition(Statement* stmt); | 77 void SetStatementPosition(Statement* stmt); |
69 void SetSourcePosition(int pos); | 78 void SetSourcePosition(int pos); |
70 | 79 |
71 // AST node visit functions. | 80 // AST node visit functions. |
72 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); | 81 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
73 AST_NODE_LIST(DECLARE_VISIT) | 82 AST_NODE_LIST(DECLARE_VISIT) |
74 #undef DECLARE_VISIT | 83 #undef DECLARE_VISIT |
75 | 84 |
76 // Handles the shortcutted logical binary operations in VisitBinaryOperation. | 85 // Handles the shortcutted logical binary operations in VisitBinaryOperation. |
77 void EmitLogicalOperation(BinaryOperation* expr); | 86 void EmitLogicalOperation(BinaryOperation* expr); |
78 | 87 |
79 MacroAssembler* masm_; | 88 MacroAssembler* masm_; |
80 FunctionLiteral* function_; | 89 FunctionLiteral* function_; |
81 Handle<Script> script_; | 90 Handle<Script> script_; |
82 bool is_eval_; | 91 bool is_eval_; |
83 | 92 |
| 93 Label* true_label_; |
| 94 Label* false_label_; |
| 95 |
84 DISALLOW_COPY_AND_ASSIGN(FastCodeGenerator); | 96 DISALLOW_COPY_AND_ASSIGN(FastCodeGenerator); |
85 }; | 97 }; |
86 | 98 |
87 | 99 |
88 } } // namespace v8::internal | 100 } } // namespace v8::internal |
89 | 101 |
90 #endif // V8_FAST_CODEGEN_H_ | 102 #endif // V8_FAST_CODEGEN_H_ |
OLD | NEW |