4ee6a66270
The change in [0] increased the language version of pkg/dart2wasm. That in return changes how the package is formatted by the autoformatter. This CL runs now the formatter to re-format the code. Unfortunately this makes blame lists worse. But not doing it will make us have to disable auto-formatting before saving files which is very annoying. [0] https://dart-review.googlesource.com/c/sdk/+/487944 Change-Id: I6953fe0d6a824b2b79a26bbadb0bb977cec70b7a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490821 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
58 lines
1.6 KiB
Dart
58 lines
1.6 KiB
Dart
// Copyright (c) 2026, 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 'package:kernel/ast.dart';
|
|
|
|
import 'kernel_nodes.dart';
|
|
import 'util.dart' as util;
|
|
|
|
enum ExternType { memory }
|
|
|
|
final class MemoryLimits {
|
|
final int minSize;
|
|
final int? maxSize;
|
|
|
|
MemoryLimits({required this.minSize, this.maxSize});
|
|
|
|
/// Read the `MemoryType` annotation on a member.
|
|
static MemoryLimits? readAnnotation(KernelNodes nodes, Member member) {
|
|
final memoryType = util.getPragma<InstanceConstant>(
|
|
nodes.coreTypes,
|
|
member,
|
|
'wasm:memory-type',
|
|
);
|
|
if (memoryType == null ||
|
|
memoryType.classNode != nodes.wasmMemoryTypeClass) {
|
|
return null;
|
|
}
|
|
|
|
final (minSize, maxSize) = _readMemoryType(nodes, memoryType);
|
|
|
|
return MemoryLimits(minSize: minSize, maxSize: maxSize);
|
|
}
|
|
|
|
static (int, int?) _readMemoryType(
|
|
KernelNodes nodes,
|
|
InstanceConstant constant,
|
|
) {
|
|
final limits = constant.fieldValues.values.single;
|
|
return _readLimits(nodes, limits as InstanceConstant);
|
|
}
|
|
|
|
static (int, int?) _readLimits(KernelNodes nodes, InstanceConstant constant) {
|
|
final minimum =
|
|
(constant.fieldValues[nodes.wasmLimitsMinimum.fieldReference]
|
|
as IntConstant)
|
|
.value;
|
|
final maximumConstant =
|
|
constant.fieldValues[nodes.wasmLimitsMaximum.fieldReference];
|
|
final maximum = switch (maximumConstant) {
|
|
IntConstant(:final value) => value,
|
|
_ => null,
|
|
};
|
|
|
|
return (minimum, maximum);
|
|
}
|
|
}
|