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

Unified Diff: runtime/vm/flow_graph_builder.cc

Issue 9646008: Implementing ConstructorCall. (part I) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/flow_graph_builder.cc
===================================================================
--- runtime/vm/flow_graph_builder.cc (revision 5205)
+++ runtime/vm/flow_graph_builder.cc (working copy)
@@ -672,7 +672,11 @@
int length = node->arguments()->length();
ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(length);
TranslateArgumentList(*node->arguments(), temp_index(), values);
- StaticCallComp* call = new StaticCallComp(node, values);
+ StaticCallComp* call =
+ new StaticCallComp(node->token_index(),
+ node->function(),
+ node->arguments()->names(),
+ values);
ReturnComputation(call);
}
@@ -692,6 +696,69 @@
}
+void EffectGraphVisitor::BuildTypeArguments(ConstructorCallNode* node) {
+ const Class& cls = Class::ZoneHandle(node->constructor().owner());
+ ASSERT(cls.HasTypeArguments());
+ if (node->type_arguments().IsNull() ||
+ node->type_arguments().IsInstantiated()) {
+ AddInstruction(
+ new BindInstr(temp_index(), new ConstantVal(node->type_arguments())));
+ if (node->constructor().IsFactory()) {
+ UNIMPLEMENTED();
+ } else {
+ // Null instantiator.
+ AddInstruction(new BindInstr(
+ temp_index() + 1, new ConstantVal(Object::ZoneHandle())));
+ }
+ return;
+ }
+ Bailout("EffectGraphVisitor::BuildTypeArguments");
+}
+
+
+void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) {
+ if (node->constructor().IsFactory()) {
+ Bailout("EffectGraphVisitor::VisitConstructorCallNode Factory");
+ }
+
+ const Class& cls = Class::ZoneHandle(node->constructor().owner());
+ const bool requires_type_arguments = cls.HasTypeArguments();
+ if (requires_type_arguments) {
+ BuildTypeArguments(node);
+ }
+ // t_n contains the allocated and initialized object.
+ // t_n <- AllocateObject(class)
+ // t_n+1 <- Pick(t_n)
+ // t_n+2 <- ctor-arg
+ // t_n+3... <- constructor arguments start here
+ // StaticCall(constructor, t_n+1, t_n+2, ...)
+
+ AllocateObjectComp* alloc_comp = new AllocateObjectComp(node);
+ AddInstruction(new BindInstr(temp_index(), alloc_comp));
+ intptr_t result_index = AllocateTempIndex();
+ TempVal* alloc_value = new TempVal(result_index);
+ TempVal* dup_alloc_value = new TempVal(result_index + 1);
+ TempVal* ctor_arg_value = new TempVal(result_index + 2);
+ AddInstruction(
+ new PickTempInstr(dup_alloc_value->index(), alloc_value->index()));
+
+ ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>();
+ values->Add(dup_alloc_value);
+ const Smi& ctor_arg = Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll));
+ AddInstruction(
+ new BindInstr(ctor_arg_value->index(), new ConstantVal(ctor_arg)));
+ values->Add(ctor_arg_value);
+ TranslateArgumentList(*node->arguments(), result_index + 3, values);
+ StaticCallComp* call =
+ new StaticCallComp(node->token_index(),
+ node->constructor(),
+ node->arguments()->names(),
+ values);
+ AddInstruction(new DoInstr(call));
+ ReturnValue(alloc_value);
+}
+
+
void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) {
ArgumentGraphVisitor for_receiver(owner(), temp_index());
node->receiver()->Visit(&for_receiver);
@@ -973,7 +1040,7 @@
void FlowGraphPrinter::VisitConstant(ConstantVal* val) {
- OS::Print("#%s", val->instance().ToCString());
+ OS::Print("#%s", val->value().ToCString());
}
@@ -1097,6 +1164,12 @@
String::Handle(comp->type().Name()).ToCString());
}
+void FlowGraphPrinter::VisitAllocateObject(AllocateObjectComp* comp) {
+ OS::Print("AllocateObject(%s)",
+ Class::Handle(comp->constructor().owner()).ToCString());
+}
+
+
void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) {
OS::Print("%2d: [join]", instr->block_number());
}

Powered by Google App Engine
This is Rietveld 408576698