644df9b9fb
This reverts commit c430a0ac0b.
Reason for revert: Will break flutter_frontend_server when rolled into google3
Original change's description:
> Reland: [kernel] Rename Name.name to Name.text
>
> Change-Id: I5240b0ff09faf35184998920202d7600dc97766d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162746
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Johnni Winther <johnniwinther@google.com>
TBR=jensj@google.com,johnniwinther@google.com
Change-Id: Ib6961f49dd416171c5d5935c490d79d6f7be779e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162748
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
108 lines
2.9 KiB
Dart
108 lines
2.9 KiB
Dart
// 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.
|
|
|
|
library vm.bytecode.recognized_methods;
|
|
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/type_environment.dart' show StaticTypeContext;
|
|
|
|
import 'dbc.dart';
|
|
import 'generics.dart' show getStaticType;
|
|
|
|
class RecognizedMethods {
|
|
static const binaryIntOps = <String, Opcode>{
|
|
'+': Opcode.kAddInt,
|
|
'-': Opcode.kSubInt,
|
|
'*': Opcode.kMulInt,
|
|
'~/': Opcode.kTruncDivInt,
|
|
'%': Opcode.kModInt,
|
|
'&': Opcode.kBitAndInt,
|
|
'|': Opcode.kBitOrInt,
|
|
'^': Opcode.kBitXorInt,
|
|
'<<': Opcode.kShlInt,
|
|
'>>': Opcode.kShrInt,
|
|
'==': Opcode.kCompareIntEq,
|
|
'>': Opcode.kCompareIntGt,
|
|
'<': Opcode.kCompareIntLt,
|
|
'>=': Opcode.kCompareIntGe,
|
|
'<=': Opcode.kCompareIntLe,
|
|
};
|
|
|
|
static const binaryDoubleOps = <String, Opcode>{
|
|
'+': Opcode.kAddDouble,
|
|
'-': Opcode.kSubDouble,
|
|
'*': Opcode.kMulDouble,
|
|
'/': Opcode.kDivDouble,
|
|
'==': Opcode.kCompareDoubleEq,
|
|
'>': Opcode.kCompareDoubleGt,
|
|
'<': Opcode.kCompareDoubleLt,
|
|
'>=': Opcode.kCompareDoubleGe,
|
|
'<=': Opcode.kCompareDoubleLe,
|
|
};
|
|
|
|
final StaticTypeContext staticTypeContext;
|
|
|
|
RecognizedMethods(this.staticTypeContext);
|
|
|
|
DartType staticType(Expression expr) =>
|
|
getStaticType(expr, staticTypeContext);
|
|
|
|
bool isInt(DartType type) =>
|
|
type == staticTypeContext.typeEnvironment.coreTypes.intLegacyRawType;
|
|
|
|
bool isDouble(DartType type) =>
|
|
type == staticTypeContext.typeEnvironment.coreTypes.doubleLegacyRawType;
|
|
|
|
Opcode specializedBytecodeFor(MethodInvocation node) {
|
|
final args = node.arguments;
|
|
if (!args.named.isEmpty) {
|
|
return null;
|
|
}
|
|
|
|
final Expression receiver = node.receiver;
|
|
final String selector = node.name.name;
|
|
|
|
switch (args.positional.length) {
|
|
case 0:
|
|
return specializedBytecodeForUnaryOp(selector, receiver);
|
|
case 1:
|
|
return specializedBytecodeForBinaryOp(
|
|
selector, receiver, args.positional.single);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
Opcode specializedBytecodeForUnaryOp(String selector, Expression arg) {
|
|
if (selector == 'unary-') {
|
|
final argType = staticType(arg);
|
|
if (isInt(argType)) {
|
|
return Opcode.kNegateInt;
|
|
} else if (isDouble(argType)) {
|
|
return Opcode.kNegateDouble;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
Opcode specializedBytecodeForBinaryOp(
|
|
String selector, Expression a, Expression b) {
|
|
if (selector == '==' && (a is NullLiteral || b is NullLiteral)) {
|
|
return Opcode.kEqualsNull;
|
|
}
|
|
|
|
final aType = staticType(a);
|
|
final bType = staticType(b);
|
|
|
|
if (isInt(aType) && isInt(bType)) {
|
|
return binaryIntOps[selector];
|
|
}
|
|
if (isDouble(aType) && isDouble(bType)) {
|
|
return binaryDoubleOps[selector];
|
|
}
|
|
return null;
|
|
}
|
|
}
|