Files
Tess Strickland 1fb0c0c231 [vm,dynamic_modules] Add record-coverage bytecode option.
This CL only adds the option and appropriate uses of it. Followup
CLs will use it to actually generate appropriate instructions and
metadata for collecting coverage information.

TEST=ci (just adding flag)

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try
Change-Id: I194154ef926abe7dae8bb93f397fb68029e2db3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501500
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2026-05-12 07:46:06 -07:00

53 lines
1.7 KiB
Dart

// Copyright (c) 2025, 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:typed_data' show Uint8List;
import 'package:dart2bytecode/bytecode_generator.dart' show generateBytecode;
import 'package:dart2bytecode/options.dart' show BytecodeOptions;
import 'package:kernel/ast.dart' show Component, Library;
import 'package:kernel/binary/ast_to_binary.dart' show BytesSink;
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
import 'package:kernel/core_types.dart' show CoreTypes;
import 'package:kernel/target/targets.dart' show Target;
import '../../vm/bin/kernel_service.dart' as kernel_service;
Uint8List _generateBytecode(
Component component,
List<Library> libraries,
CoreTypes coreTypes,
ClassHierarchy hierarchy,
Target target,
bool enableAsserts, {
Set<Library> extraLoadedLibraries = const {},
}) {
final byteSink = new BytesSink();
generateBytecode(
component,
byteSink,
libraries: libraries,
extraLoadedLibraries: extraLoadedLibraries,
coreTypes: coreTypes,
hierarchy: hierarchy,
target: target,
options: BytecodeOptions(
enableAsserts: enableAsserts,
emitSourcePositions: true,
emitLocalVarInfo: true,
emitInstanceFieldInitializers: true,
embedSourceText: true,
recordCoverage: true,
),
);
return byteSink.builder.takeBytes();
}
// Wire up bytecode generator to the kernel service to avoid
// circular dependency between package:vm and package:dart2bytecode.
main([args]) {
kernel_service.bytecodeGenerator = _generateBytecode;
return kernel_service.main(args);
}