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

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10353014: Start implementing checked mode and tools support for using it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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
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 SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler);
7 String get name() => 'SSA code generator'; 7 String get name() => 'SSA code generator';
8 8
9 9
10 String buildJavaScriptFunction(FunctionElement element, 10 String buildJavaScriptFunction(FunctionElement element,
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 buffer.add(';\n'); 952 buffer.add(';\n');
953 } 953 }
954 }); 954 });
955 } 955 }
956 } 956 }
957 957
958 if (instruction is HGoto || instruction is HExit || instruction is HTry) { 958 if (instruction is HGoto || instruction is HExit || instruction is HTry) {
959 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); 959 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE);
960 return; 960 return;
961 } else if (!isGenerateAtUseSite(instruction)) { 961 } else if (!isGenerateAtUseSite(instruction)) {
962 if (instruction is !HIf && instruction is !HTypeGuard && 962 if (instruction is !HIf
963 instruction is !HLoopBranch && !isGeneratingExpression()) { 963 && instruction is !HTypeGuard
964 && instruction is !HLoopBranch
965 && !isGeneratingExpression()) {
964 addIndentation(); 966 addIndentation();
965 } 967 }
966 if (isGeneratingExpression()) { 968 if (isGeneratingExpression()) {
967 addExpressionSeparator(); 969 addExpressionSeparator();
968 } 970 }
969 if (instruction.usedBy.isEmpty() 971 if (instruction.usedBy.isEmpty()
970 || instruction is HTypeGuard 972 || instruction is HTypeGuard
971 || instruction is HCheck) { 973 || instruction is HCheck) {
972 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); 974 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE);
973 } else { 975 } else {
974 define(instruction); 976 define(instruction);
975 } 977 }
976 // Control flow instructions, and some other instructions, 978 // Control flow instructions, and some other instructions,
977 // know how to handle ';'. 979 // know how to handle ';'.
978 if (instruction is !HControlFlow && instruction is !HTypeGuard && 980 if (instruction is !HControlFlow
979 !isGeneratingExpression()) { 981 && instruction is !HTypeGuard
982 && !isGeneratingExpression()) {
980 buffer.add(';\n'); 983 buffer.add(';\n');
981 } 984 }
982 } else if (instruction is HIf) { 985 } else if (instruction is HIf) {
983 HIf hif = instruction; 986 HIf hif = instruction;
984 // The "if" is implementing part of a logical expression. 987 // The "if" is implementing part of a logical expression.
985 // Skip directly forward to to its latest successor, since everything 988 // Skip directly forward to to its latest successor, since everything
986 // in-between must also be generateAtUseSite. 989 // in-between must also be generateAtUseSite.
987 assert(hif.trueBranch.id < hif.falseBranch.id); 990 assert(hif.trueBranch.id < hif.falseBranch.id);
988 visitBasicBlock(hif.falseBranch); 991 visitBasicBlock(hif.falseBranch);
989 return; 992 return;
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 1746
1744 void checkImmutableArray(HInstruction input) { 1747 void checkImmutableArray(HInstruction input) {
1745 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); 1748 beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
1746 buffer.add('!!'); 1749 buffer.add('!!');
1747 use(input, JSPrecedence.MEMBER_PRECEDENCE); 1750 use(input, JSPrecedence.MEMBER_PRECEDENCE);
1748 buffer.add('.immutable\$list'); 1751 buffer.add('.immutable\$list');
1749 endExpression(JSPrecedence.PREFIX_PRECEDENCE); 1752 endExpression(JSPrecedence.PREFIX_PRECEDENCE);
1750 } 1753 }
1751 1754
1752 void checkExtendableArray(HInstruction input) { 1755 void checkExtendableArray(HInstruction input) {
1753 compiler.unimplemented("check extendable array"); 1756 beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
1757 buffer.add('!!');
1758 use(input, JSPrecedence.MEMBER_PRECEDENCE);
1759 buffer.add('.fixed\$length');
1760 endExpression(JSPrecedence.PREFIX_PRECEDENCE);
1754 } 1761 }
1755 1762
1756 void checkNull(HInstruction input) { 1763 void checkNull(HInstruction input) {
1757 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1764 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1758 use(input, JSPrecedence.EQUALITY_PRECEDENCE); 1765 use(input, JSPrecedence.EQUALITY_PRECEDENCE);
1759 buffer.add(" === (void 0)"); 1766 buffer.add(" === (void 0)");
1760 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1767 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1761 } 1768 }
1762 1769
1763 void checkFunction(HInstruction input, Element element) { 1770 void checkFunction(HInstruction input, Element element) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 buffer.add(".${name.slowToString()} === '${arguments.head}'"); 1892 buffer.add(".${name.slowToString()} === '${arguments.head}'");
1886 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 1893 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
1887 }); 1894 });
1888 } 1895 }
1889 if (node.nullOk) { 1896 if (node.nullOk) {
1890 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); 1897 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
1891 } 1898 }
1892 } 1899 }
1893 1900
1894 void visitTypeConversion(HTypeConversion node) { 1901 void visitTypeConversion(HTypeConversion node) {
1895 assert(isGenerateAtUseSite(node)); 1902 if (node.checked) {
floitsch 2012/05/07 11:06:56 not sure I like that all of this is in the codegen
ngeoffray 2012/05/07 13:15:42 As discussed, I will live it here, but we can revi
1896 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); 1903 Element element = node.type.computeType(compiler).element;
1904 compiler.registerIsCheck(element);
1905 SourceString helper;
1906 String additionalArgument;
1907 bool nativeCheck =
1908 compiler.emitter.nativeEmitter.requiresNativeIsCheck(element);
1909 beginExpression(JSPrecedence.CALL_PRECEDENCE);
1910
1911 if (element == compiler.stringClass) {
1912 helper = const SourceString('stringTypeCheck');
1913 } else if (element == compiler.doubleClass) {
1914 helper = const SourceString('doubleTypeCheck');
1915 } else if (element == compiler.numClass) {
1916 helper = const SourceString('numTypeCheck');
1917 } else if (element == compiler.boolClass) {
1918 helper = const SourceString('boolTypeCheck');
1919 } else if (element == compiler.functionClass || element.isTypedef()) {
1920 helper = const SourceString('functionTypeCheck');
1921 } else if (element == compiler.intClass) {
1922 helper = const SourceString('intTypeCheck');
1923 } else if (Elements.isStringSupertype(element, compiler)) {
1924 helper = const SourceString('stringSuperTypeCheck');
1925 } else if (element === compiler.listClass) {
1926 helper = const SourceString('listTypeCheck');
1927 } else {
1928 additionalArgument = compiler.namer.operatorIs(element);
1929 if (Elements.isListSupertype(element, compiler)) {
1930 if (nativeCheck) {
1931 helper = const SourceString('listSuperNativeTypeCheck');
1932 } else {
1933 helper = const SourceString('listSuperTypeCheck');
1934 }
1935 } else if (nativeCheck) {
1936 helper = const SourceString('callTypeCheck');
1937 } else {
1938 helper = const SourceString('propertyTypeCheck');
1939 }
1940 }
1941 Element helperElement = compiler.findHelper(helper);
1942 compiler.registerStaticUse(helperElement);
1943 buffer.add(compiler.namer.isolateAccess(helperElement));
1944 buffer.add('(');
1945 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE);
1946 if (additionalArgument !== null) buffer.add(", '$additionalArgument'");
1947 buffer.add(')');
1948 endExpression(JSPrecedence.CALL_PRECEDENCE);
1949 } else {
1950 use(node.inputs[0], expectedPrecedence);
1951 }
1897 } 1952 }
1898 } 1953 }
1899 1954
1900 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { 1955 class SsaOptimizedCodeGenerator extends SsaCodeGenerator {
1901 SsaOptimizedCodeGenerator(compiler, work, parameters, parameterNames) 1956 SsaOptimizedCodeGenerator(compiler, work, parameters, parameterNames)
1902 : super(compiler, work, parameters, parameterNames); 1957 : super(compiler, work, parameters, parameterNames);
1903 1958
1904 void beginGraph(HGraph graph) {} 1959 void beginGraph(HGraph graph) {}
1905 void endGraph(HGraph graph) {} 1960 void endGraph(HGraph graph) {}
1906 1961
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 startBailoutSwitch(); 2349 startBailoutSwitch();
2295 } 2350 }
2296 } 2351 }
2297 2352
2298 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 2353 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
2299 if (labeledBlockInfo.body.start.hasGuards()) { 2354 if (labeledBlockInfo.body.start.hasGuards()) {
2300 endBailoutSwitch(); 2355 endBailoutSwitch();
2301 } 2356 }
2302 } 2357 }
2303 } 2358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698