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

Unified Diff: pkg/compiler/lib/src/kernel/kernel.dart

Issue 2338093002: Build entire program with kernel for conversion to ssa. (Closed)
Patch Set: some tweaks Created 4 years, 3 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
« no previous file with comments | « pkg/compiler/lib/src/js_backend/kernel_task.dart ('k') | pkg/compiler/lib/src/kernel/kernel_visitor.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/kernel/kernel.dart
diff --git a/pkg/compiler/lib/src/kernel/kernel.dart b/pkg/compiler/lib/src/kernel/kernel.dart
index d5f115173f61d748e4fb666294e2a07031288f59..fa53c0e163885f446efda9e43488590bf0f6f0b3 100644
--- a/pkg/compiler/lib/src/kernel/kernel.dart
+++ b/pkg/compiler/lib/src/kernel/kernel.dart
@@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE.md file.
+import 'dart:async';
import 'dart:collection' show Queue;
import 'package:kernel/ast.dart' as ir;
@@ -18,8 +19,10 @@ import '../elements/elements.dart'
ClassElement,
ConstructorElement,
Element,
+ ExportElement,
FieldElement,
FunctionElement,
+ ImportElement,
LibraryElement,
MixinApplicationElement,
TypeVariableElement;
@@ -117,6 +120,10 @@ class Kernel {
return new ir.Name(name, irLibrary);
}
+ Future<ir.Library> loadLibrary(Uri uri) async {
+ return libraryToIr(await compiler.libraryLoader.loadLibrary(uri));
+ }
+
ir.Library libraryToIr(LibraryElement library) {
library = library.declaration;
return libraries.putIfAbsent(library, () {
@@ -489,6 +496,10 @@ class Kernel {
throw message;
}
+ forEachLibraryElement(f(LibraryElement library)) {
+ return compiler.libraryLoader.libraries.forEach(f);
+ }
+
ConstructorTarget computeEffectiveTarget(
ConstructorElement constructor, DartType type) {
constructor = constructor.implementation;
@@ -505,6 +516,59 @@ class Kernel {
return new ConstructorTarget(constructor, type);
}
+ /// Compute all the dependencies on the library with [uri] (including the
+ /// library itself). This is useful for creating a Kernel IR `Program`.
+ List<ir.Library> libraryDependencies(Uri uri) {
+ List<ir.Library> result = <ir.Library>[];
+ Queue<LibraryElement> notProcessed = new Queue<LibraryElement>();
+ Set<LibraryElement> seen = new Set<LibraryElement>();
+ LibraryElement library = compiler.libraryLoader.lookupLibrary(uri);
+ void processLater(LibraryElement library) {
+ if (library != null) {
+ notProcessed.addLast(library);
+ }
+ }
+
+ processLater(library);
+ seen.add(library);
+ LibraryElement core =
+ compiler.libraryLoader.lookupLibrary(Uri.parse("dart:core"));
+ if (seen.add(core)) {
+ // `dart:core` is implicitly imported by most libraries, and for some
+ // reason not included in `library.imports` below.
+ processLater(core);
+ }
+ while (notProcessed.isNotEmpty) {
+ LibraryElement library = notProcessed.removeFirst();
+ ir.Library irLibrary = libraryToIr(library);
+ for (ImportElement import in library.imports) {
+ if (seen.add(import.importedLibrary)) {
+ processLater(import.importedLibrary);
+ }
+ }
+ for (ExportElement export in library.exports) {
+ if (seen.add(export.exportedLibrary)) {
+ processLater(export.exportedLibrary);
+ }
+ }
+ for (ImportElement import in library.implementation.imports) {
+ if (seen.add(import.importedLibrary)) {
+ processLater(import.importedLibrary);
+ }
+ }
+ for (ExportElement export in library.implementation.exports) {
+ if (seen.add(export.exportedLibrary)) {
+ processLater(export.exportedLibrary);
+ }
+ }
+ if (irLibrary != null) {
+ result.add(irLibrary);
+ }
+ }
+ processWorkQueue();
+ return result;
+ }
+
/// Returns true if [element] is synthesized to recover or represent a
/// semantic error, for example, missing, duplicated, or ambiguous elements.
/// However, returns false for elements that have an unrecoverable syntax
« no previous file with comments | « pkg/compiler/lib/src/js_backend/kernel_task.dart ('k') | pkg/compiler/lib/src/kernel/kernel_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698