0c016fca91
Review URL: https://codereview.chromium.org//51953009 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29678 260f80e4-7a28-3924-810f-c04153c831b5
39 lines
1.5 KiB
Dart
39 lines
1.5 KiB
Dart
// Copyright (c) 2013, 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.
|
|
|
|
import 'dart:async';
|
|
import 'package:expect/expect.dart';
|
|
|
|
import 'memory_source_file_helper.dart';
|
|
|
|
Future<Map<String, String>> generate(String code,
|
|
[List<String> options = const []]) {
|
|
Uri script = currentDirectory.resolveUri(Platform.script);
|
|
Uri libraryRoot = script.resolve('../../../sdk/');
|
|
Uri packageRoot = script.resolve('./packages/');
|
|
|
|
var provider = new MemorySourceFileProvider({ 'main.dart': code });
|
|
var handler = new FormattingDiagnosticHandler(provider);
|
|
|
|
Compiler compiler = new Compiler(provider.readStringFromUri,
|
|
null,
|
|
handler.diagnosticHandler,
|
|
libraryRoot,
|
|
packageRoot,
|
|
options,
|
|
{});
|
|
Uri uri = Uri.parse('memory:main.dart');
|
|
return compiler.run(uri).then((success) {
|
|
Expect.isTrue(success);
|
|
Map<String, String> result = new Map<String, String>();
|
|
for (var element in compiler.backend.generatedCode.keys) {
|
|
if (element.getCompilationUnit().script.uri != uri) continue;
|
|
var name = element.name;
|
|
var code = compiler.backend.assembleCode(element);
|
|
result[name] = code;
|
|
}
|
|
return result;
|
|
});
|
|
}
|