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

Side by Side Diff: runtime/vm/code_generator_x64.cc

Issue 9949020: Move HandlerList to shared ExceptionHandlerList. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 | « runtime/vm/code_generator_x64.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/code_generator.h" 8 #include "vm/code_generator.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 12 matching lines...) Expand all
23 namespace dart { 23 namespace dart {
24 24
25 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); 25 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree.");
26 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables."); 26 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables.");
27 DEFINE_FLAG(bool, trace_functions, false, "Trace entry of each function."); 27 DEFINE_FLAG(bool, trace_functions, false, "Trace entry of each function.");
28 DECLARE_FLAG(bool, enable_type_checks); 28 DECLARE_FLAG(bool, enable_type_checks);
29 DECLARE_FLAG(bool, trace_compiler); 29 DECLARE_FLAG(bool, trace_compiler);
30 30
31 #define __ assembler_-> 31 #define __ assembler_->
32 32
33
34 // TODO(regis): CodeGeneratorState, CodeGenerator::DescriptorList, and
35 // CodeGenerator::HandlerList can probably be moved to code_generator.cc, since
36 // they seem to be architecture independent.
37
38
39 CodeGeneratorState::CodeGeneratorState(CodeGenerator* codegen) 33 CodeGeneratorState::CodeGeneratorState(CodeGenerator* codegen)
40 : StackResource(Isolate::Current()), 34 : StackResource(Isolate::Current()),
41 codegen_(codegen), 35 codegen_(codegen),
42 parent_(codegen->state()) { 36 parent_(codegen->state()) {
43 if (parent_ != NULL) { 37 if (parent_ != NULL) {
44 root_node_ = parent_->root_node_; 38 root_node_ = parent_->root_node_;
45 current_try_index_ = parent_->current_try_index_; 39 current_try_index_ = parent_->current_try_index_;
46 } else { 40 } else {
47 root_node_ = NULL; 41 root_node_ = NULL;
48 current_try_index_ = CatchClauseNode::kInvalidTryIndex; 42 current_try_index_ = CatchClauseNode::kInvalidTryIndex;
49 } 43 }
50 codegen_->set_state(this); 44 codegen_->set_state(this);
51 } 45 }
52 46
53 47
54 CodeGeneratorState::~CodeGeneratorState() { 48 CodeGeneratorState::~CodeGeneratorState() {
55 codegen_->set_state(parent_); 49 codegen_->set_state(parent_);
56 } 50 }
57 51
58 52
59 class CodeGenerator::HandlerList : public ZoneAllocated {
60 public:
61 struct HandlerDesc {
62 intptr_t try_index; // Try block index handled by the handler.
63 intptr_t pc_offset; // Handler PC offset value.
64 };
65
66 HandlerList() : list_() {
67 }
68 ~HandlerList() { }
69
70 intptr_t Length() const {
71 return list_.length();
72 }
73
74 intptr_t TryIndex(int index) const {
75 return list_[index].try_index;
76 }
77 intptr_t PcOffset(int index) const {
78 return list_[index].pc_offset;
79 }
80 void SetPcOffset(int index, intptr_t handler_pc) {
81 list_[index].pc_offset = handler_pc;
82 }
83
84 void AddHandler(intptr_t try_index, intptr_t pc_offset) {
85 struct HandlerDesc data;
86 data.try_index = try_index;
87 data.pc_offset = pc_offset;
88 list_.Add(data);
89 }
90
91 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) {
92 intptr_t num_handlers = Length();
93 const ExceptionHandlers& handlers =
94 ExceptionHandlers::Handle(ExceptionHandlers::New(num_handlers));
95 for (intptr_t i = 0; i < num_handlers; i++) {
96 handlers.SetHandlerEntry(i, TryIndex(i), (entry_point + PcOffset(i)));
97 }
98 return handlers.raw();
99 }
100
101 private:
102 GrowableArray<struct HandlerDesc> list_;
103 DISALLOW_COPY_AND_ASSIGN(HandlerList);
104 };
105
106
107 CodeGenerator::CodeGenerator(Assembler* assembler, 53 CodeGenerator::CodeGenerator(Assembler* assembler,
108 const ParsedFunction& parsed_function) 54 const ParsedFunction& parsed_function)
109 : assembler_(assembler), 55 : assembler_(assembler),
110 parsed_function_(parsed_function), 56 parsed_function_(parsed_function),
111 locals_space_size_(-1), 57 locals_space_size_(-1),
112 state_(NULL), 58 state_(NULL),
113 pc_descriptors_list_(NULL), 59 pc_descriptors_list_(NULL),
114 stackmap_builder_(NULL), 60 stackmap_builder_(NULL),
115 exception_handlers_list_(NULL), 61 exception_handlers_list_(NULL),
116 try_index_(CatchClauseNode::kInvalidTryIndex), 62 try_index_(CatchClauseNode::kInvalidTryIndex),
117 context_level_(0) { 63 context_level_(0) {
118 ASSERT(assembler_ != NULL); 64 ASSERT(assembler_ != NULL);
119 ASSERT(parsed_function.node_sequence() != NULL); 65 ASSERT(parsed_function.node_sequence() != NULL);
120 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump()); 66 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump());
121 pc_descriptors_list_ = new DescriptorList(); 67 pc_descriptors_list_ = new DescriptorList();
122 // We do not build any stack maps in the unoptimizing compiler. 68 // We do not build any stack maps in the unoptimizing compiler.
123 exception_handlers_list_ = new CodeGenerator::HandlerList(); 69 exception_handlers_list_ = new ExceptionHandlerList();
124 } 70 }
125 71
126 72
127 bool CodeGenerator::IsResultNeeded(AstNode* node) const { 73 bool CodeGenerator::IsResultNeeded(AstNode* node) const {
128 return !state()->IsRootNode(node); 74 return !state()->IsRootNode(node);
129 } 75 }
130 76
131 77
132 // NOTE: First 13 bytes of the code may be patched with a jump instruction. Do 78 // NOTE: First 13 bytes of the code may be patched with a jump instruction. Do
133 // not emit any objects in the first 13 bytes. 79 // not emit any objects in the first 13 bytes.
(...skipping 2580 matching lines...) Expand 10 before | Expand all | Expand 10 after
2714 const Error& error = Error::Handle( 2660 const Error& error = Error::Handle(
2715 Parser::FormatError(script, token_index, "Error", format, args)); 2661 Parser::FormatError(script, token_index, "Error", format, args));
2716 va_end(args); 2662 va_end(args);
2717 Isolate::Current()->long_jump_base()->Jump(1, error); 2663 Isolate::Current()->long_jump_base()->Jump(1, error);
2718 UNREACHABLE(); 2664 UNREACHABLE();
2719 } 2665 }
2720 2666
2721 } // namespace dart 2667 } // namespace dart
2722 2668
2723 #endif // defined TARGET_ARCH_X64 2669 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/code_generator_x64.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698