| 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 #include "vm/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 #include "vm/longjump.h" | 9 #include "vm/longjump.h" |
| 10 #include "vm/os.h" | 10 #include "vm/os.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 void EffectGraphVisitor::VisitStringConcatNode(StringConcatNode* node) { | 239 void EffectGraphVisitor::VisitStringConcatNode(StringConcatNode* node) { |
| 240 Bailout("EffectGraphVisitor::VisitStringConcatNode"); | 240 Bailout("EffectGraphVisitor::VisitStringConcatNode"); |
| 241 } | 241 } |
| 242 | 242 |
| 243 | 243 |
| 244 // <Expression> :: Comparison { kind: Token::Kind | 244 // <Expression> :: Comparison { kind: Token::Kind |
| 245 // left: <Expression> | 245 // left: <Expression> |
| 246 // right: <Expression> } | 246 // right: <Expression> } |
| 247 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { | 247 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { |
| 248 if (Token::IsInstanceofOperator(node->kind())) { | 248 if (Token::IsInstanceofOperator(node->kind())) { |
| 249 Bailout("instanceof not yet implemented"); | 249 ArgumentGraphVisitor for_left_value(owner(), temp_index()); |
| 250 } else if ((node->kind() == Token::kEQ) || (node->kind() == Token::kNE)) { | 250 node->left()->Visit(&for_left_value); |
| 251 Bailout("'==' or '!=' comparison not yet implemented"); | 251 Append(for_left_value); |
| 252 InstanceOfComp* instance_of = new InstanceOfComp( |
| 253 node->id(), |
| 254 node->token_index(), |
| 255 for_left_value.value(), |
| 256 node->right()->AsTypeNode()->type(), |
| 257 (node->kind() == Token::kISNOT)); |
| 258 ReturnComputation(instance_of); |
| 259 return; |
| 252 } | 260 } |
| 253 if ((node->kind() == Token::kEQ_STRICT) || | 261 if ((node->kind() == Token::kEQ_STRICT) || |
| 254 (node->kind() == Token::kNE_STRICT)) { | 262 (node->kind() == Token::kNE_STRICT)) { |
| 255 ValueGraphVisitor for_left_value(owner(), temp_index()); | 263 ValueGraphVisitor for_left_value(owner(), temp_index()); |
| 256 node->left()->Visit(&for_left_value); | 264 node->left()->Visit(&for_left_value); |
| 257 Append(for_left_value); | 265 Append(for_left_value); |
| 258 ValueGraphVisitor for_right_value(owner(), for_left_value.temp_index()); | 266 ValueGraphVisitor for_right_value(owner(), for_left_value.temp_index()); |
| 259 node->right()->Visit(&for_right_value); | 267 node->right()->Visit(&for_right_value); |
| 260 Append(for_right_value); | 268 Append(for_right_value); |
| 261 StrictCompareComp* comp = new StrictCompareComp( | 269 StrictCompareComp* comp = new StrictCompareComp( |
| 262 node->kind(), for_left_value.value(), for_right_value.value()); | 270 node->kind(), for_left_value.value(), for_right_value.value()); |
| 263 ReturnComputation(comp); | 271 ReturnComputation(comp); |
| 264 return; | 272 return; |
| 265 } | 273 } |
| 266 | 274 |
| 267 ArgumentGraphVisitor for_left_value(owner(), temp_index()); | 275 ArgumentGraphVisitor for_left_value(owner(), temp_index()); |
| 268 node->left()->Visit(&for_left_value); | 276 node->left()->Visit(&for_left_value); |
| 269 Append(for_left_value); | 277 Append(for_left_value); |
| 270 ArgumentGraphVisitor for_right_value(owner(), for_left_value.temp_index()); | 278 ArgumentGraphVisitor for_right_value(owner(), for_left_value.temp_index()); |
| 271 node->right()->Visit(&for_right_value); | 279 node->right()->Visit(&for_right_value); |
| 272 Append(for_right_value); | 280 Append(for_right_value); |
| 273 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(2); | 281 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(2); |
| 274 arguments->Add(for_left_value.value()); | 282 arguments->Add(for_left_value.value()); |
| 275 arguments->Add(for_right_value.value()); | 283 arguments->Add(for_right_value.value()); |
| 276 const String& name = String::ZoneHandle(String::NewSymbol(node->Name())); | 284 // 'kNE' is not overloadable, must implement as kEQ and negation. |
| 277 InstanceCallComp* call = | 285 // Boolean negation '!' cannot be overloaded neither. |
| 278 new InstanceCallComp(node->id(), node->token_index(), name, | 286 if (node->kind() == Token::kNE) { |
| 279 arguments, Array::ZoneHandle(), 2); | 287 const String& name = String::ZoneHandle(String::NewSymbol("==")); |
| 280 ReturnComputation(call); | 288 InstanceCallComp* call_equal = |
| 289 new InstanceCallComp(node->id(), node->token_index(), name, |
| 290 arguments, Array::ZoneHandle(), 2); |
| 291 AddInstruction(new BindInstr(temp_index(), call_equal)); |
| 292 Value* eq_result = new TempVal(temp_index()); |
| 293 if (FLAG_enable_type_checks) { |
| 294 Bailout("GenerateConditionTypeCheck in kNE"); |
| 295 } |
| 296 BooleanNegateComp* negate = new BooleanNegateComp(eq_result); |
| 297 ReturnComputation(negate); |
| 298 } else { |
| 299 const String& name = String::ZoneHandle(String::NewSymbol(node->Name())); |
| 300 InstanceCallComp* call = |
| 301 new InstanceCallComp(node->id(), node->token_index(), name, |
| 302 arguments, Array::ZoneHandle(), 2); |
| 303 ReturnComputation(call); |
| 304 } |
| 281 } | 305 } |
| 282 | 306 |
| 283 | 307 |
| 284 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) { | 308 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) { |
| 285 // "!" cannot be overloaded, therefore do not call operator. | 309 // "!" cannot be overloaded, therefore do not call operator. |
| 286 if (node->kind() == Token::kNOT) { | 310 if (node->kind() == Token::kNOT) { |
| 287 Bailout("EffectGraphVisitor::VisitUnaryOpNode NOT"); | 311 Bailout("EffectGraphVisitor::VisitUnaryOpNode NOT"); |
| 288 } | 312 } |
| 289 ArgumentGraphVisitor for_value(owner(), temp_index()); | 313 ArgumentGraphVisitor for_value(owner(), temp_index()); |
| 290 node->operand()->Visit(&for_value); | 314 node->operand()->Visit(&for_value); |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 | 940 |
| 917 void FlowGraphPrinter::VisitInstanceSetter(InstanceSetterComp* comp) { | 941 void FlowGraphPrinter::VisitInstanceSetter(InstanceSetterComp* comp) { |
| 918 OS::Print("InstanceSetter("); | 942 OS::Print("InstanceSetter("); |
| 919 comp->receiver()->Accept(this); | 943 comp->receiver()->Accept(this); |
| 920 OS::Print(", "); | 944 OS::Print(", "); |
| 921 comp->value()->Accept(this); | 945 comp->value()->Accept(this); |
| 922 OS::Print(")"); | 946 OS::Print(")"); |
| 923 } | 947 } |
| 924 | 948 |
| 925 | 949 |
| 950 void FlowGraphPrinter::VisitBooleanNegate(BooleanNegateComp* comp) { |
| 951 OS::Print("! "); |
| 952 comp->value()->Accept(this); |
| 953 } |
| 954 |
| 955 |
| 956 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) { |
| 957 comp->value()->Accept(this); |
| 958 OS::Print(" %s %s", |
| 959 comp->negate_result() ? "ISNOT" : "IS", |
| 960 String::Handle(comp->type().Name()).ToCString()); |
| 961 } |
| 962 |
| 926 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { | 963 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { |
| 927 OS::Print("%2d: [join]", instr->block_number()); | 964 OS::Print("%2d: [join]", instr->block_number()); |
| 928 } | 965 } |
| 929 | 966 |
| 930 | 967 |
| 931 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { | 968 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { |
| 932 OS::Print("%2d: [target]", instr->block_number()); | 969 OS::Print("%2d: [target]", instr->block_number()); |
| 933 } | 970 } |
| 934 | 971 |
| 935 | 972 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 char* chars = reinterpret_cast<char*>( | 1025 char* chars = reinterpret_cast<char*>( |
| 989 Isolate::Current()->current_zone()->Allocate(len)); | 1026 Isolate::Current()->current_zone()->Allocate(len)); |
| 990 OS::SNPrint(chars, len, kFormat, function_name, reason); | 1027 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 991 const Error& error = Error::Handle( | 1028 const Error& error = Error::Handle( |
| 992 LanguageError::New(String::Handle(String::New(chars)))); | 1029 LanguageError::New(String::Handle(String::New(chars)))); |
| 993 Isolate::Current()->long_jump_base()->Jump(1, error); | 1030 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 994 } | 1031 } |
| 995 | 1032 |
| 996 | 1033 |
| 997 } // namespace dart | 1034 } // namespace dart |
| OLD | NEW |