| #!/usr/bin/env bash |
| # Copyright (c) 2018, 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 generating bytecode in a kernel file using Dart 2 pipeline and |
| # interpreting the resulting bytecode. |
| |
| # Usage |
| # pkg/vm/tool/test_bytecode ~/foo.dart |
| |
| # Note: To generate bytecode in the platform dill file as well, change the value |
| # of the constant 'isKernelBytecodeEnabled' in file |
| # pkg/vm/lib/bytecode/gen_bytecode.dart from 'false' to 'true'. |
| |
| set -e |
| |
| # Pick the architecture and mode to build and test. |
| BUILD_FLAGS="-m debug -a x64" |
| BUILD_SUBDIR="DebugX64" |
| |
| 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/../../.." |
| BUILD_DIR="$SDK_DIR/out/$BUILD_SUBDIR" |
| |
| # Verify that the VM supports the interpreter, if not, rebuild it. |
| REBUILD=0 |
| if [ -f $BUILD_DIR/dart ] |
| then |
| $BUILD_DIR/dart --trace-interpreter-after=-1 \ |
| $SDK_DIR/runtime/tests/vm/dart/hello_world_test.dart > /dev/null 2>&1 \ |
| || REBUILD=1 |
| else |
| REBUILD=1 |
| fi |
| if [ $REBUILD -ne 0 ] |
| then |
| echo "Rebuilding VM to support interpreter" |
| rm -rf $BUILD_DIR |
| $SDK_DIR/tools/gn.py $BUILD_FLAGS --gn-args=dart_use_interpreter=true |
| $SDK_DIR/tools/build.py $BUILD_FLAGS runtime |
| fi |
| |
| # Generate dill file containing bytecode for input dart source. |
| $CUR_DIR/gen_kernel --platform $BUILD_DIR/vm_platform_strong.dill \ |
| --gen-bytecode $@ -o $BUILD_DIR/test_bytecode.dill |
| |
| # Dump bytecode in generated vm_platform_strong.dill file to platform.txt. |
| # $BUILD_DIR/dart $SDK_DIR/pkg/vm/bin/dump_kernel.dart \ |
| # $BUILD_DIR/vm_platform_strong.dill $BUILD_DIR/platform.txt |
| |
| # Dump bytecode in generated test_bytecode.dill file to test_bytecode.txt. |
| # $BUILD_DIR/dart $SDK_DIR/pkg/vm/bin/dump_kernel.dart \ |
| # $BUILD_DIR/test_bytecode.dill $BUILD_DIR/test_bytecode.txt |
| |
| # Required flags. |
| DART_VM_FLAGS="--optimization-counter-threshold=-1 $DART_VM_FLAGS" |
| |
| # Optional flags examples. Uncomment as needed. |
| # DART_VM_FLAGS="--force-log-flush --isolate-log-filter=\"\" $DART_VM_FLAGS" |
| # DART_VM_FLAGS="--dump-kernel-bytecode $DART_VM_FLAGS" |
| # DART_VM_FLAGS="--trace-interpreter-after=0 $DART_VM_FLAGS" |
| |
| # Execute dill file. |
| exec $BUILD_DIR/dart $DART_VM_FLAGS $BUILD_DIR/test_bytecode.dill |
| |