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

Side by Side Diff: dart/frog/leg/ssa/builder.dart

Issue 9599026: Generate code for some switch statements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add a few comments 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/frog/leg/ssa/closure.dart » ('j') | dart/frog/leg/ssa/optimize.dart » ('J')
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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 * <Create box> <== move the first box creation outside the loop. 445 * <Create box> <== move the first box creation outside the loop.
446 * <initializer>; 446 * <initializer>;
447 * loop-entry: 447 * loop-entry:
448 * if (!<condition>) goto loop-exit; 448 * if (!<condition>) goto loop-exit;
449 * <body> 449 * <body>
450 * <update box> // create a new box and copy the captured loop-variables. 450 * <update box> // create a new box and copy the captured loop-variables.
451 * <updates> 451 * <updates>
452 * goto loop-entry; 452 * goto loop-entry;
453 * loop-exit: 453 * loop-exit:
454 */ 454 */
455 void startLoop(Loop node) { 455 void startLoop(Node node) {
456 ClosureScope scopeData = closureData.capturingScopes[node]; 456 ClosureScope scopeData = closureData.capturingScopes[node];
457 if (scopeData == null) return; 457 if (scopeData == null) return;
458 if (scopeData.hasBoxedLoopVariables()) { 458 if (scopeData.hasBoxedLoopVariables()) {
459 // If there are boxed loop variables then we set up the box and 459 // If there are boxed loop variables then we set up the box and
460 // redirections already now. This way the initializer can write its 460 // redirections already now. This way the initializer can write its
461 // values into the box. 461 // values into the box.
462 // For other loops the box will be created when entering the body. 462 // For other loops the box will be created when entering the body.
463 enterScope(node); 463 enterScope(node);
464 } 464 }
465 } 465 }
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 void visitLiteralStringJuxtaposition(LiteralStringJuxtaposition node) { 1950 void visitLiteralStringJuxtaposition(LiteralStringJuxtaposition node) {
1951 visitLiteralString(node); 1951 visitLiteralString(node);
1952 } 1952 }
1953 1953
1954 void visitLiteralNull(LiteralNull node) { 1954 void visitLiteralNull(LiteralNull node) {
1955 stack.add(graph.addNewLiteralNull()); 1955 stack.add(graph.addNewLiteralNull());
1956 } 1956 }
1957 1957
1958 visitNodeList(NodeList node) { 1958 visitNodeList(NodeList node) {
1959 for (Link<Node> link = node.nodes; !link.isEmpty(); link = link.tail) { 1959 for (Link<Node> link = node.nodes; !link.isEmpty(); link = link.tail) {
1960 visit(link.head); 1960 if (isAborted()) {
1961 compiler.reportWarning(link.head, 'dead code');
1962 } else {
1963 visit(link.head);
1964 }
1961 } 1965 }
1962 } 1966 }
1963 1967
1964 void visitParenthesizedExpression(ParenthesizedExpression node) { 1968 void visitParenthesizedExpression(ParenthesizedExpression node) {
1965 visit(node.expression); 1969 visit(node.expression);
1966 } 1970 }
1967 1971
1968 visitOperator(Operator node) { 1972 visitOperator(Operator node) {
1969 // Operators are intercepted in their surrounding Send nodes. 1973 // Operators are intercepted in their surrounding Send nodes.
1970 unreachable(); 1974 unreachable();
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 2278
2275 visitLiteralMapEntry(LiteralMapEntry node) { 2279 visitLiteralMapEntry(LiteralMapEntry node) {
2276 compiler.unimplemented('SsaBuilder.visitLiteralMapEntry', node: node); 2280 compiler.unimplemented('SsaBuilder.visitLiteralMapEntry', node: node);
2277 } 2281 }
2278 2282
2279 visitNamedArgument(NamedArgument node) { 2283 visitNamedArgument(NamedArgument node) {
2280 visit(node.expression); 2284 visit(node.expression);
2281 } 2285 }
2282 2286
2283 visitSwitchStatement(SwitchStatement node) { 2287 visitSwitchStatement(SwitchStatement node) {
2284 generateUnimplemented('switch statement not implemented'); 2288 work.allowSpeculativeOptimization = false;
2289 visit(node.expression);
2290 HInstruction expression = pop();
2291 Link cases = node.cases.nodes;
ngeoffray 2012/03/06 11:49:48 Link -> Link<Node> ?
ahe 2012/03/06 12:24:35 Done.
2292 int count = 0;
2293 handleThen() {
2294 if (cases.head.statements.nodes.isEmpty()) {
2295 compiler.unimplemented('fall-through', node: cases.head);
2296 }
2297 visit(cases.head.statements);
2298 cases = cases.tail;
2299 }
2300 handleElse() {
2301 if (cases.isEmpty()) return;
2302 if (cases.head is DefaultCase) {
ngeoffray 2012/03/06 11:49:48 is DefaultCase -> asDefaultCase() != null
ahe 2012/03/06 12:24:35 Done.
2303 stack.add(graph.addNewLiteralBool(true));
2304 if (!cases.tail.isEmpty()) {
2305 compiler.unimplemented('default case not last', node: cases.head);
2306 }
2307 } else {
2308 SwitchCase switchCase = cases.head;
2309 visit(switchCase.expression);
2310 HInstruction caseExpression = pop();
2311 Element equalsHelper = compiler.findHelper(const SourceString('eq'));
ngeoffray 2012/03/06 11:49:48 maybe make that a method in the Interceptors class
ahe 2012/03/06 12:24:35 Done.
2312 HInstruction target = new HStatic(equalsHelper);
2313 add(target);
2314 push(new HEquals(target, caseExpression, expression));
2315 }
2316 handleIf(handleThen, handleElse);
2317 }
2318
2319 localsHandler.startLoop(node);
2320 BreakHandler breakHandler = beginLoopHeader(node);
2321 HBasicBlock loopEntryBlock = current;
2322 localsHandler.enterLoopBody(node);
2323
2324 handleElse();
2325
2326 if (isAborted()) {
2327 compiler.unimplemented("SsaBuilder for loop with aborting body",
ngeoffray 2012/03/06 11:49:48 Err, not really :)
ahe 2012/03/06 12:24:35 Yes. Really. That is the problem.
ngeoffray 2012/03/06 12:32:55 In 'for loop' I read 'for' as in 'for (;;) {}' :)
Lasse Reichstein Nielsen 2012/03/06 12:53:50 I don't read it as that, but it's still a confusin
ahe 2012/03/06 13:10:51 I understand that the loop is purely synthetic and
Lasse Reichstein Nielsen 2012/03/06 13:23:36 I think that, in the long run, we should have diff
2328 node: node);
2329 }
2330
2331 HBasicBlock bodyExitBlock = close(new HGoto());
2332 HBasicBlock conditionBlock = addNewBlock();
2333 bodyExitBlock.addSuccessor(conditionBlock);
2334 open(conditionBlock);
2335 stack.add(graph.addNewLiteralBool(false));
2336
2337 conditionBlock = close(new HLoopBranch(popBoolified(),
2338 HLoopBranch.DO_WHILE_LOOP));
2339
2340 conditionBlock.addSuccessor(loopEntryBlock); // The back-edge.
2341 loopEntryBlock.postProcessLoopHeader();
2342
2343 endLoop(loopEntryBlock, conditionBlock, breakHandler);
2285 } 2344 }
2286 2345
2287 visitTryStatement(TryStatement node) { 2346 visitTryStatement(TryStatement node) {
2288 work.allowSpeculativeOptimization = false; 2347 work.allowSpeculativeOptimization = false;
2289 assert(!work.isBailoutVersion()); 2348 assert(!work.isBailoutVersion());
2290 HBasicBlock enterBlock = graph.addNewBlock(); 2349 HBasicBlock enterBlock = graph.addNewBlock();
2291 close(new HGoto()).addSuccessor(enterBlock); 2350 close(new HGoto()).addSuccessor(enterBlock);
2292 open(enterBlock); 2351 open(enterBlock);
2293 HTry tryInstruction = new HTry(); 2352 HTry tryInstruction = new HTry();
2294 List<HBasicBlock> blocks = <HBasicBlock>[]; 2353 List<HBasicBlock> blocks = <HBasicBlock>[];
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 // Normally, we would call [close] here. However, then we hit 2458 // Normally, we would call [close] here. However, then we hit
2400 // another unimplemented feature: aborting loop body. Simply 2459 // another unimplemented feature: aborting loop body. Simply
2401 // calling [add] does not work as it asserts that the instruction 2460 // calling [add] does not work as it asserts that the instruction
2402 // isn't a control flow instruction. So we inline parts of [add]. 2461 // isn't a control flow instruction. So we inline parts of [add].
2403 current.addAfter(current.last, new HThrow(message)); 2462 current.addAfter(current.last, new HThrow(message));
2404 if (isExpression) { 2463 if (isExpression) {
2405 stack.add(graph.addNewLiteralNull()); 2464 stack.add(graph.addNewLiteralNull());
2406 } 2465 }
2407 } 2466 }
2408 } 2467 }
OLDNEW
« no previous file with comments | « no previous file | dart/frog/leg/ssa/closure.dart » ('j') | dart/frog/leg/ssa/optimize.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698