5215ec6ef2
The commit breaks package:compiler.
This reverts commit 5edca8c4d3.
BUG=
Review-Url: https://codereview.chromium.org/2614663007 .
63 lines
1.9 KiB
Dart
63 lines
1.9 KiB
Dart
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
/// Conventions for paths:
|
|
///
|
|
/// - Use the [Uri] class for paths that may have the `file`, `dart` or
|
|
/// `package` scheme. Never use [Uri] for relative paths.
|
|
/// - Use [String]s for all filenames and paths that have no scheme prefix.
|
|
/// - Never translate a `dart:` or `package:` URI into a `file:` URI, instead
|
|
/// translate it to a [String] if the file system path is needed.
|
|
/// - Only use [File] from dart:io at the last moment when it is needed.
|
|
///
|
|
library kernel;
|
|
|
|
import 'ast.dart';
|
|
import 'binary/ast_to_binary.dart';
|
|
import 'binary/loader.dart';
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
import 'repository.dart';
|
|
import 'text/ast_to_text.dart';
|
|
|
|
export 'ast.dart';
|
|
export 'repository.dart';
|
|
|
|
Program loadProgramFromBinary(String path, [Repository repository]) {
|
|
repository ??= new Repository();
|
|
return new BinaryLoader(repository).loadProgram(path);
|
|
}
|
|
|
|
Future writeProgramToBinary(Program program, String path) {
|
|
var sink = new File(path).openWrite();
|
|
var future;
|
|
try {
|
|
new BinaryPrinter(sink).writeProgramFile(program);
|
|
} finally {
|
|
future = sink.close();
|
|
}
|
|
return future;
|
|
}
|
|
|
|
void writeLibraryToText(Library library, {String path}) {
|
|
StringBuffer buffer = new StringBuffer();
|
|
new Printer(buffer).writeLibraryFile(library);
|
|
if (path == null) {
|
|
print(buffer);
|
|
} else {
|
|
new File(path).writeAsStringSync('$buffer');
|
|
}
|
|
}
|
|
|
|
void writeProgramToText(Program program,
|
|
{String path, bool showExternal: false}) {
|
|
StringBuffer buffer = new StringBuffer();
|
|
new Printer(buffer, showExternal: showExternal).writeProgramFile(program);
|
|
if (path == null) {
|
|
print(buffer);
|
|
} else {
|
|
new File(path).writeAsStringSync('$buffer');
|
|
}
|
|
}
|