| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_CODE_GENERATOR_X64_H_ | 5 #ifndef VM_CODE_GENERATOR_X64_H_ |
| 6 #define VM_CODE_GENERATOR_X64_H_ | 6 #define VM_CODE_GENERATOR_X64_H_ |
| 7 | 7 |
| 8 #ifndef VM_CODE_GENERATOR_H_ | 8 #ifndef VM_CODE_GENERATOR_H_ |
| 9 #error Do not include code_generator_x64.h directly; use code_generator.h. | 9 #error Do not include code_generator_x64.h directly; use code_generator.h. |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include "vm/assembler.h" | 12 #include "vm/assembler.h" |
| 13 #include "vm/ast.h" | 13 #include "vm/ast.h" |
| 14 #include "vm/growable_array.h" | 14 #include "vm/growable_array.h" |
| 15 #include "vm/parser.h" | 15 #include "vm/parser.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 // Forward declarations. | 19 // Forward declarations. |
| 20 class Assembler; | 20 class Assembler; |
| 21 class AstNode; | 21 class AstNode; |
| 22 class CodeGenerator; | 22 class CodeGenerator; |
| 23 class DescriptorList; |
| 23 class SourceLabel; | 24 class SourceLabel; |
| 25 class StackmapBuilder; |
| 24 | 26 |
| 25 | 27 |
| 26 class CodeGeneratorState : public StackResource { | 28 class CodeGeneratorState : public StackResource { |
| 27 public: | 29 public: |
| 28 explicit CodeGeneratorState(CodeGenerator* codegen); | 30 explicit CodeGeneratorState(CodeGenerator* codegen); |
| 29 virtual ~CodeGeneratorState(); | 31 virtual ~CodeGeneratorState(); |
| 30 | 32 |
| 31 CodeGeneratorState* parent() const { return parent_; } | 33 CodeGeneratorState* parent() const { return parent_; } |
| 32 | 34 |
| 33 AstNode* root_node() const { return root_node_; } | 35 AstNode* root_node() const { return root_node_; } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 // We store the 'try index' of the block of code that we are | 59 // We store the 'try index' of the block of code that we are |
| 58 // currently generating code for in the current_try_index_ variable. | 60 // currently generating code for in the current_try_index_ variable. |
| 59 int current_try_index_; | 61 int current_try_index_; |
| 60 | 62 |
| 61 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeGeneratorState); | 63 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeGeneratorState); |
| 62 }; | 64 }; |
| 63 | 65 |
| 64 | 66 |
| 65 class CodeGenerator : public AstNodeVisitor { | 67 class CodeGenerator : public AstNodeVisitor { |
| 66 public: | 68 public: |
| 67 // Forward declarations. | |
| 68 class DescriptorList; | |
| 69 | |
| 70 CodeGenerator(Assembler* assembler, const ParsedFunction& parsed_function); | 69 CodeGenerator(Assembler* assembler, const ParsedFunction& parsed_function); |
| 71 virtual ~CodeGenerator() { } | 70 virtual ~CodeGenerator() { } |
| 72 | 71 |
| 73 // Accessors. | 72 // Accessors. |
| 74 Assembler* assembler() const { return assembler_; } | 73 Assembler* assembler() const { return assembler_; } |
| 75 | 74 |
| 76 const ParsedFunction& parsed_function() const { return parsed_function_; } | 75 const ParsedFunction& parsed_function() const { return parsed_function_; } |
| 77 | 76 |
| 78 void GenerateCode(); | 77 void GenerateCode(); |
| 79 virtual void GenerateDeferredCode(); | 78 virtual void GenerateDeferredCode(); |
| 80 | 79 |
| 81 // Add local variable descriptors to code. | |
| 82 void FinalizeVarDescriptors(const Code& code); | |
| 83 | |
| 84 #define DEFINE_VISITOR_FUNCTION(type, name) \ | 80 #define DEFINE_VISITOR_FUNCTION(type, name) \ |
| 85 virtual void Visit##type(type* node); | 81 virtual void Visit##type(type* node); |
| 86 NODE_LIST(DEFINE_VISITOR_FUNCTION) | 82 NODE_LIST(DEFINE_VISITOR_FUNCTION) |
| 87 #undef DEFINE_VISITOR_FUNCTION | 83 #undef DEFINE_VISITOR_FUNCTION |
| 88 | 84 |
| 89 CodeGeneratorState* state() const { return state_; } | 85 CodeGeneratorState* state() const { return state_; } |
| 90 void set_state(CodeGeneratorState* state) { state_ = state; } | 86 void set_state(CodeGeneratorState* state) { state_ = state; } |
| 91 | 87 |
| 92 // Add exception handler table to code. | 88 // Add exception handler table to code. |
| 93 void FinalizeExceptionHandlers(const Code& code); | 89 void FinalizeExceptionHandlers(const Code& code); |
| 94 | 90 |
| 95 // Add pc descriptors to code. | 91 // Add pc descriptors to code. |
| 96 void FinalizePcDescriptors(const Code& code); | 92 void FinalizePcDescriptors(const Code& code); |
| 97 | 93 |
| 94 // Add stack maps to code. |
| 95 void FinalizeStackmaps(const Code& code); |
| 96 |
| 97 // Add local variable descriptors to code. |
| 98 void FinalizeVarDescriptors(const Code& code); |
| 99 |
| 98 // Allocate and return an arguments descriptor. | 100 // Allocate and return an arguments descriptor. |
| 99 // Let 'num_names' be the length of 'optional_arguments_names'. | 101 // Let 'num_names' be the length of 'optional_arguments_names'. |
| 100 // Treat the first 'num_arguments - num_names' arguments as positional and | 102 // Treat the first 'num_arguments - num_names' arguments as positional and |
| 101 // treat the following 'num_names' arguments as named optional arguments. | 103 // treat the following 'num_names' arguments as named optional arguments. |
| 102 static const Array& ArgumentsDescriptor( | 104 static const Array& ArgumentsDescriptor( |
| 103 int num_arguments, | 105 int num_arguments, |
| 104 const Array& optional_arguments_names); | 106 const Array& optional_arguments_names); |
| 105 | 107 |
| 106 virtual bool IsOptimizing() const { | 108 virtual bool IsOptimizing() const { |
| 107 return false; | 109 return false; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 void CopyParameters(); | 208 void CopyParameters(); |
| 207 | 209 |
| 208 void set_context_level(intptr_t value) { context_level_ = value; } | 210 void set_context_level(intptr_t value) { context_level_ = value; } |
| 209 intptr_t context_level() const { return context_level_; } | 211 intptr_t context_level() const { return context_level_; } |
| 210 | 212 |
| 211 Assembler* assembler_; | 213 Assembler* assembler_; |
| 212 const ParsedFunction& parsed_function_; | 214 const ParsedFunction& parsed_function_; |
| 213 intptr_t locals_space_size_; | 215 intptr_t locals_space_size_; |
| 214 CodeGeneratorState* state_; | 216 CodeGeneratorState* state_; |
| 215 DescriptorList* pc_descriptors_list_; | 217 DescriptorList* pc_descriptors_list_; |
| 218 StackmapBuilder* stackmap_builder_; |
| 216 HandlerList* exception_handlers_list_; | 219 HandlerList* exception_handlers_list_; |
| 217 int try_index_; | 220 int try_index_; |
| 218 // The runtime context level is only incremented when a new context is | 221 // The runtime context level is only incremented when a new context is |
| 219 // allocated and chained to the list of contexts. | 222 // allocated and chained to the list of contexts. |
| 220 intptr_t context_level_; | 223 intptr_t context_level_; |
| 221 | 224 |
| 222 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeGenerator); | 225 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeGenerator); |
| 223 }; | 226 }; |
| 224 | 227 |
| 225 | 228 |
| 226 } // namespace dart | 229 } // namespace dart |
| 227 | 230 |
| 228 #endif // VM_CODE_GENERATOR_X64_H_ | 231 #endif // VM_CODE_GENERATOR_X64_H_ |
| OLD | NEW |