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

Side by Side Diff: pkg/compiler/lib/src/native/ssa.dart

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « pkg/compiler/lib/src/native/scanner.dart ('k') | pkg/compiler/lib/src/old_to_new_api.dart » ('j') | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import '../common.dart'; 5 import '../common.dart';
6 import '../compiler.dart' show 6 import '../compiler.dart' show Compiler;
7 Compiler;
8 import '../constants/values.dart'; 7 import '../constants/values.dart';
9 import '../dart_types.dart'; 8 import '../dart_types.dart';
10 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
11 import '../js/js.dart' as js; 10 import '../js/js.dart' as js;
12 import '../js_backend/js_backend.dart'; 11 import '../js_backend/js_backend.dart';
13 import '../js_emitter/js_emitter.dart' show 12 import '../js_emitter/js_emitter.dart' show CodeEmitterTask, NativeEmitter;
14 CodeEmitterTask,
15 NativeEmitter;
16 import '../ssa/builder.dart' show SsaBuilder; 13 import '../ssa/builder.dart' show SsaBuilder;
17 import '../ssa/nodes.dart' show 14 import '../ssa/nodes.dart' show HInstruction, HForeignCode, HReturn;
18 HInstruction,
19 HForeignCode,
20 HReturn;
21 import '../tree/tree.dart'; 15 import '../tree/tree.dart';
22 import '../universe/side_effects.dart' show 16 import '../universe/side_effects.dart' show SideEffects;
23 SideEffects;
24 17
25 final RegExp nativeRedirectionRegExp = new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$'); 18 final RegExp nativeRedirectionRegExp = new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$');
26 19
27 void handleSsaNative(SsaBuilder builder, Expression nativeBody) { 20 void handleSsaNative(SsaBuilder builder, Expression nativeBody) {
28 Compiler compiler = builder.compiler; 21 Compiler compiler = builder.compiler;
29 FunctionElement element = builder.target; 22 FunctionElement element = builder.target;
30 NativeEmitter nativeEmitter = builder.nativeEmitter; 23 NativeEmitter nativeEmitter = builder.nativeEmitter;
31 JavaScriptBackend backend = builder.backend; 24 JavaScriptBackend backend = builder.backend;
32 DiagnosticReporter reporter = compiler.reporter; 25 DiagnosticReporter reporter = compiler.reporter;
33 26
34 HInstruction convertDartClosure(ParameterElement parameter, 27 HInstruction convertDartClosure(
35 FunctionType type) { 28 ParameterElement parameter, FunctionType type) {
36 HInstruction local = builder.localsHandler.readLocal(parameter); 29 HInstruction local = builder.localsHandler.readLocal(parameter);
37 ConstantValue arityConstant = 30 ConstantValue arityConstant =
38 builder.constantSystem.createInt(type.computeArity()); 31 builder.constantSystem.createInt(type.computeArity());
39 HInstruction arity = builder.graph.addConstant(arityConstant, compiler); 32 HInstruction arity = builder.graph.addConstant(arityConstant, compiler);
40 // TODO(ngeoffray): For static methods, we could pass a method with a 33 // TODO(ngeoffray): For static methods, we could pass a method with a
41 // defined arity. 34 // defined arity.
42 Element helper = backend.helpers.closureConverter; 35 Element helper = backend.helpers.closureConverter;
43 builder.pushInvokeStatic(nativeBody, helper, [local, arity]); 36 builder.pushInvokeStatic(nativeBody, helper, [local, arity]);
44 HInstruction closure = builder.pop(); 37 HInstruction closure = builder.pop();
45 return closure; 38 return closure;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 85
93 String foreignParameters = arguments.join(','); 86 String foreignParameters = arguments.join(',');
94 String nativeMethodCall; 87 String nativeMethodCall;
95 if (element.kind == ElementKind.FUNCTION) { 88 if (element.kind == ElementKind.FUNCTION) {
96 nativeMethodCall = '$receiver$nativeMethodName($foreignParameters)'; 89 nativeMethodCall = '$receiver$nativeMethodName($foreignParameters)';
97 } else if (element.kind == ElementKind.GETTER) { 90 } else if (element.kind == ElementKind.GETTER) {
98 nativeMethodCall = '$receiver$nativeMethodName'; 91 nativeMethodCall = '$receiver$nativeMethodName';
99 } else if (element.kind == ElementKind.SETTER) { 92 } else if (element.kind == ElementKind.SETTER) {
100 nativeMethodCall = '$receiver$nativeMethodName = $foreignParameters'; 93 nativeMethodCall = '$receiver$nativeMethodName = $foreignParameters';
101 } else { 94 } else {
102 builder.reporter.internalError(element, 95 builder.reporter
103 'Unexpected kind: "${element.kind}".'); 96 .internalError(element, 'Unexpected kind: "${element.kind}".');
104 } 97 }
105 98
106 builder.push( 99 builder.push(new HForeignCode(
107 new HForeignCode( 100 // TODO(sra): This could be cached. The number of templates should
108 // TODO(sra): This could be cached. The number of templates should 101 // be proportional to the number of native methods, which is bounded
109 // be proportional to the number of native methods, which is bounded 102 // by the dart: libraries.
110 // by the dart: libraries. 103 js.js.uncachedExpressionTemplate(nativeMethodCall),
111 js.js.uncachedExpressionTemplate(nativeMethodCall), 104 backend.dynamicType,
112 backend.dynamicType, 105 inputs,
113 inputs, effects: new SideEffects())); 106 effects: new SideEffects()));
114 // TODO(johnniwinther): Provide source information. 107 // TODO(johnniwinther): Provide source information.
115 builder 108 builder
116 .close(new HReturn(builder.pop(), null)) 109 .close(new HReturn(builder.pop(), null))
117 .addSuccessor(builder.graph.exit); 110 .addSuccessor(builder.graph.exit);
118 } else { 111 } else {
119 if (parameters.parameterCount != 0) { 112 if (parameters.parameterCount != 0) {
120 reporter.internalError(nativeBody, 113 reporter.internalError(
114 nativeBody,
121 'native "..." syntax is restricted to ' 115 'native "..." syntax is restricted to '
122 'functions with zero parameters.'); 116 'functions with zero parameters.');
123 } 117 }
124 LiteralString jsCode = nativeBody.asLiteralString(); 118 LiteralString jsCode = nativeBody.asLiteralString();
125 builder.push(new HForeignCode.statement( 119 builder.push(new HForeignCode.statement(
126 js.js.statementTemplateYielding( 120 js.js.statementTemplateYielding(
127 new js.LiteralStatement(jsCode.dartString.slowToString())), 121 new js.LiteralStatement(jsCode.dartString.slowToString())),
128 <HInstruction>[], 122 <HInstruction>[],
129 new SideEffects(), 123 new SideEffects(),
130 null, 124 null,
131 backend.dynamicType)); 125 backend.dynamicType));
132 } 126 }
133 } 127 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/native/scanner.dart ('k') | pkg/compiler/lib/src/old_to_new_api.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698