mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 16:31:07 +00:00
[vm, kernel] Tool for dumping kernel files with VM-specific metadata
Change-Id: I7f7b3cd797e30283821741583983dbe939e5132e Reviewed-on: https://dart-review.googlesource.com/30960 Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
d4475cb445
commit
c812f6ab33
|
@ -66,9 +66,15 @@ void writeLibraryToText(Library library, {String path}) {
|
|||
}
|
||||
|
||||
void writeProgramToText(Program program,
|
||||
{String path, bool showExternal: false, bool showOffsets: false}) {
|
||||
{String path,
|
||||
bool showExternal: false,
|
||||
bool showOffsets: false,
|
||||
bool showMetadata: false}) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
new Printer(buffer, showExternal: showExternal, showOffsets: showOffsets)
|
||||
new Printer(buffer,
|
||||
showExternal: showExternal,
|
||||
showOffsets: showOffsets,
|
||||
showMetadata: showMetadata)
|
||||
.writeProgramFile(program);
|
||||
if (path == null) {
|
||||
print(buffer);
|
||||
|
|
|
@ -222,11 +222,13 @@ class Printer extends Visitor<Null> {
|
|||
final NameSystem syntheticNames;
|
||||
final StringSink sink;
|
||||
final Annotator annotator;
|
||||
final Map<String, MetadataRepository<dynamic>> metadata;
|
||||
ImportTable importTable;
|
||||
int indentation = 0;
|
||||
int column = 0;
|
||||
bool showExternal;
|
||||
bool showOffsets;
|
||||
bool showMetadata;
|
||||
|
||||
static int SPACE = 0;
|
||||
static int WORD = 1;
|
||||
|
@ -237,16 +239,19 @@ class Printer extends Visitor<Null> {
|
|||
{NameSystem syntheticNames,
|
||||
this.showExternal,
|
||||
this.showOffsets: false,
|
||||
this.showMetadata: false,
|
||||
this.importTable,
|
||||
this.annotator})
|
||||
this.annotator,
|
||||
this.metadata})
|
||||
: this.syntheticNames = syntheticNames ?? new NameSystem();
|
||||
|
||||
Printer._inner(Printer parent, this.importTable)
|
||||
Printer._inner(Printer parent, this.importTable, this.metadata)
|
||||
: sink = parent.sink,
|
||||
syntheticNames = parent.syntheticNames,
|
||||
annotator = parent.annotator,
|
||||
showExternal = parent.showExternal,
|
||||
showOffsets = parent.showOffsets;
|
||||
showOffsets = parent.showOffsets,
|
||||
showMetadata = parent.showMetadata;
|
||||
|
||||
bool shouldHighlight(Node node) {
|
||||
return false;
|
||||
|
@ -387,7 +392,8 @@ class Printer extends Visitor<Null> {
|
|||
}
|
||||
|
||||
endLine();
|
||||
var inner = new Printer._inner(this, imports);
|
||||
var inner =
|
||||
new Printer._inner(this, imports, library.enclosingProgram?.metadata);
|
||||
library.typedefs.forEach(inner.writeNode);
|
||||
library.classes.forEach(inner.writeNode);
|
||||
library.fields.forEach(inner.writeNode);
|
||||
|
@ -396,7 +402,7 @@ class Printer extends Visitor<Null> {
|
|||
|
||||
void writeProgramFile(Program program) {
|
||||
ImportTable imports = new ProgramImportTable(program);
|
||||
var inner = new Printer._inner(this, imports);
|
||||
var inner = new Printer._inner(this, imports, program.metadata);
|
||||
writeWord('main');
|
||||
writeSpaced('=');
|
||||
inner.writeMemberReferenceFromReference(program.mainMethodName);
|
||||
|
@ -504,6 +510,9 @@ class Printer extends Visitor<Null> {
|
|||
if (showOffsets && node is TreeNode) {
|
||||
writeWord("[${node.fileOffset}]");
|
||||
}
|
||||
if (showMetadata && node is TreeNode) {
|
||||
writeMetadata(node);
|
||||
}
|
||||
|
||||
node.accept(this);
|
||||
|
||||
|
@ -519,6 +528,17 @@ class Printer extends Visitor<Null> {
|
|||
}
|
||||
}
|
||||
|
||||
void writeMetadata(TreeNode node) {
|
||||
if (metadata != null) {
|
||||
for (var md in metadata.values) {
|
||||
final nodeMetadata = md.mapping[node];
|
||||
if (nodeMetadata != null) {
|
||||
writeWord("[@${md.tag}=${nodeMetadata}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeAnnotatedType(DartType type, String annotation) {
|
||||
writeType(type);
|
||||
if (annotation != null) {
|
||||
|
|
36
pkg/vm/bin/dump_kernel.dart
Normal file
36
pkg/vm/bin/dump_kernel.dart
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) 2017, 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:io';
|
||||
|
||||
import 'package:kernel/kernel.dart' show Program, writeProgramToText;
|
||||
import 'package:kernel/binary/ast_from_binary.dart'
|
||||
show BinaryBuilderWithMetadata;
|
||||
|
||||
import 'package:vm/metadata/direct_call.dart' show DirectCallMetadataRepository;
|
||||
|
||||
final String _usage = '''
|
||||
Usage: dump_kernel input.dill output.txt
|
||||
Dumps kernel binary file with VM-specific metadata.
|
||||
''';
|
||||
|
||||
main(List<String> arguments) async {
|
||||
if (arguments.length != 2) {
|
||||
print(_usage);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
final input = arguments[0];
|
||||
final output = arguments[1];
|
||||
|
||||
final program = new Program();
|
||||
|
||||
// Register VM-specific metadata.
|
||||
program.addMetadataRepository(new DirectCallMetadataRepository());
|
||||
|
||||
final List<int> bytes = new File(input).readAsBytesSync();
|
||||
new BinaryBuilderWithMetadata(bytes).readProgram(program);
|
||||
|
||||
writeProgramToText(program, path: output, showMetadata: true);
|
||||
}
|
|
@ -8,10 +8,19 @@ import 'package:kernel/ast.dart';
|
|||
|
||||
/// Metadata for annotating method invocations converted to direct calls.
|
||||
class DirectCallMetadata {
|
||||
final Member target;
|
||||
final Reference _targetReference;
|
||||
final bool checkReceiverForNull;
|
||||
|
||||
DirectCallMetadata(this.target, this.checkReceiverForNull);
|
||||
DirectCallMetadata(Member target, bool checkReceiverForNull)
|
||||
: this.byReference(getMemberReference(target), checkReceiverForNull);
|
||||
|
||||
DirectCallMetadata.byReference(
|
||||
this._targetReference, this.checkReceiverForNull);
|
||||
|
||||
Member get target => _targetReference.asMember;
|
||||
|
||||
@override
|
||||
String toString() => "${target}${checkReceiverForNull ? '??' : ''}";
|
||||
}
|
||||
|
||||
/// Repository for [DirectCallMetadata].
|
||||
|
@ -32,11 +41,12 @@ class DirectCallMetadataRepository
|
|||
|
||||
@override
|
||||
DirectCallMetadata readFromBinary(BinarySource source) {
|
||||
var target = source.readCanonicalNameReference()?.getReference()?.asMember;
|
||||
if (target == null) {
|
||||
final targetReference = source.readCanonicalNameReference()?.getReference();
|
||||
if (targetReference == null) {
|
||||
throw 'DirectCallMetadata should have a non-null target';
|
||||
}
|
||||
var checkReceiverForNull = (source.readByte() != 0);
|
||||
return new DirectCallMetadata(target, checkReceiverForNull);
|
||||
final checkReceiverForNull = (source.readByte() != 0);
|
||||
return new DirectCallMetadata.byReference(
|
||||
targetReference, checkReceiverForNull);
|
||||
}
|
||||
}
|
||||
|
|
36
pkg/vm/tool/dump_kernel
Executable file
36
pkg/vm/tool/dump_kernel
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2017, 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.
|
||||
|
||||
# Script for dumping kernel files with VM-specific metadata.
|
||||
|
||||
set -e
|
||||
|
||||
function follow_links() {
|
||||
file="$1"
|
||||
while [ -h "$file" ]; do
|
||||
# On Mac OS, readlink -f doesn't work.
|
||||
file="$(readlink "$file")"
|
||||
done
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
|
||||
PROG_NAME="$(follow_links "$BASH_SOURCE")"
|
||||
|
||||
# Handle the case where dart-sdk/bin has been symlinked to.
|
||||
CUR_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
|
||||
|
||||
SDK_DIR="$CUR_DIR/../../.."
|
||||
|
||||
if [[ `uname` == 'Darwin' ]]; then
|
||||
OUT_DIR="$SDK_DIR/xcodebuild"
|
||||
else
|
||||
OUT_DIR="$SDK_DIR/out"
|
||||
fi
|
||||
|
||||
export DART_CONFIGURATION=${DART_CONFIGURATION:-ReleaseX64}
|
||||
BIN_DIR="$OUT_DIR/$DART_CONFIGURATION"
|
||||
|
||||
"$BIN_DIR"/dart "${SDK_DIR}/pkg/vm/bin/dump_kernel.dart" "$@"
|
Loading…
Reference in a new issue