Skip to content

Commit b1946a5

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[vm/ffi] Rename NativeFundamentalType to NativePrimitiveType
These types are called object types in the C standard (ISO/IEC 9899:2011) and fundamental types in C++ (https://en.cppreference.com/w/cpp/language/types) but more commonly they are called primitive types (https://en.wikipedia.org/wiki/Primitive_data_type). Change-Id: I78ac9bee162e547a7b9b04cf142b274602c53d18 Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64-try,vm-ffi-android-debug-arm-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170429 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent 88de61b commit b1946a5

9 files changed

+70
-65
lines changed

runtime/vm/compiler/backend/flow_graph_compiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,8 +2748,8 @@ void FlowGraphCompiler::EmitNativeMove(
27482748
const intptr_t dst_container_size = dst_container_type.SizeInBytes();
27492749

27502750
// This function does not know how to do larger mem copy moves yet.
2751-
ASSERT(src_payload_type.IsFundamental());
2752-
ASSERT(dst_payload_type.IsFundamental());
2751+
ASSERT(src_payload_type.IsPrimitive());
2752+
ASSERT(dst_payload_type.IsPrimitive());
27532753

27542754
// This function does not deal with sign conversions yet.
27552755
ASSERT(src_payload_type.IsSigned() == dst_payload_type.IsSigned());

runtime/vm/compiler/backend/flow_graph_compiler_arm.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,8 +1446,8 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
14461446
ASSERT(src_container_type.IsFloat() == dst_container_type.IsFloat());
14471447
ASSERT(src_container_type.IsInt() == dst_container_type.IsInt());
14481448
ASSERT(src_payload_type.IsSigned() == dst_payload_type.IsSigned());
1449-
ASSERT(src_payload_type.IsFundamental());
1450-
ASSERT(dst_payload_type.IsFundamental());
1449+
ASSERT(src_payload_type.IsPrimitive());
1450+
ASSERT(dst_payload_type.IsPrimitive());
14511451
const intptr_t src_size = src_payload_type.SizeInBytes();
14521452
const intptr_t dst_size = dst_payload_type.SizeInBytes();
14531453
const bool sign_or_zero_extend = dst_size > src_size;

runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,8 +1393,8 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
13931393
ASSERT(src_type.IsFloat() == dst_type.IsFloat());
13941394
ASSERT(src_type.IsInt() == dst_type.IsInt());
13951395
ASSERT(src_type.IsSigned() == dst_type.IsSigned());
1396-
ASSERT(src_type.IsFundamental());
1397-
ASSERT(dst_type.IsFundamental());
1396+
ASSERT(src_type.IsPrimitive());
1397+
ASSERT(dst_type.IsPrimitive());
13981398
const intptr_t src_size = src_type.SizeInBytes();
13991399
const intptr_t dst_size = dst_type.SizeInBytes();
14001400
const bool sign_or_zero_extend = dst_size > src_size;
@@ -1420,7 +1420,7 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
14201420
UNIMPLEMENTED();
14211421
}
14221422
} else {
1423-
switch (src_type.AsFundamental().representation()) {
1423+
switch (src_type.AsPrimitive().representation()) {
14241424
case compiler::ffi::kInt8: // Sign extend operand.
14251425
__ sxtb(dst_reg, src_reg);
14261426
return;

runtime/vm/compiler/backend/flow_graph_compiler_ia32.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,8 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
13021302
ASSERT(src_type.IsFloat() == dst_type.IsFloat());
13031303
ASSERT(src_type.IsInt() == dst_type.IsInt());
13041304
ASSERT(src_type.IsSigned() == dst_type.IsSigned());
1305-
ASSERT(src_type.IsFundamental());
1306-
ASSERT(dst_type.IsFundamental());
1305+
ASSERT(src_type.IsPrimitive());
1306+
ASSERT(dst_type.IsPrimitive());
13071307
const intptr_t src_size = src_type.SizeInBytes();
13081308
const intptr_t dst_size = dst_type.SizeInBytes();
13091309
const bool sign_or_zero_extend = dst_size > src_size;
@@ -1322,7 +1322,7 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
13221322
ASSERT(dst_size == 4);
13231323
__ movl(dst_reg, src_reg);
13241324
} else {
1325-
switch (src_type.AsFundamental().representation()) {
1325+
switch (src_type.AsPrimitive().representation()) {
13261326
case compiler::ffi::kInt8: // Sign extend operand.
13271327
__ movsxb(dst_reg, ByteRegisterOf(src_reg));
13281328
return;
@@ -1410,7 +1410,7 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
14101410
ASSERT(dst_size == 4);
14111411
__ movl(dst_reg, src_addr);
14121412
} else {
1413-
switch (src_type.AsFundamental().representation()) {
1413+
switch (src_type.AsPrimitive().representation()) {
14141414
case compiler::ffi::kInt8: // Sign extend operand.
14151415
__ movsxb(dst_reg, src_addr);
14161416
return;

runtime/vm/compiler/backend/flow_graph_compiler_x64.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,8 +1354,8 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
13541354
ASSERT(src_type.IsFloat() == dst_type.IsFloat());
13551355
ASSERT(src_type.IsInt() == dst_type.IsInt());
13561356
ASSERT(src_type.IsSigned() == dst_type.IsSigned());
1357-
ASSERT(src_type.IsFundamental());
1358-
ASSERT(dst_type.IsFundamental());
1357+
ASSERT(src_type.IsPrimitive());
1358+
ASSERT(dst_type.IsPrimitive());
13591359
const intptr_t src_size = src_type.SizeInBytes();
13601360
const intptr_t dst_size = dst_type.SizeInBytes();
13611361
const bool sign_or_zero_extend = dst_size > src_size;
@@ -1381,7 +1381,7 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
13811381
UNIMPLEMENTED();
13821382
}
13831383
} else {
1384-
switch (src_type.AsFundamental().representation()) {
1384+
switch (src_type.AsPrimitive().representation()) {
13851385
case compiler::ffi::kInt8: // Sign extend operand.
13861386
__ movsxb(dst_reg, src_reg);
13871387
return;
@@ -1479,7 +1479,7 @@ void FlowGraphCompiler::EmitNativeMoveArchitecture(
14791479
UNIMPLEMENTED();
14801480
}
14811481
} else {
1482-
switch (src_type.AsFundamental().representation()) {
1482+
switch (src_type.AsPrimitive().representation()) {
14831483
case compiler::ffi::kInt8: // Sign extend operand.
14841484
__ movsxb(dst_reg, src_addr);
14851485
return;

runtime/vm/compiler/ffi/native_calling_convention.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ static const NativeType& ConvertIfSoftFp(Zone* zone, const NativeType& rep) {
3535
if (SoftFpAbi() && rep.IsFloat()) {
3636
ASSERT(rep.IsFloat());
3737
if (rep.SizeInBytes() == 4) {
38-
return *new (zone) NativeFundamentalType(kInt32);
38+
return *new (zone) NativePrimitiveType(kInt32);
3939
}
4040
if (rep.SizeInBytes() == 8) {
41-
return *new (zone) NativeFundamentalType(kInt64);
41+
return *new (zone) NativePrimitiveType(kInt64);
4242
}
4343
}
4444
return rep;

runtime/vm/compiler/ffi/native_location.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ Location NativeStackLocation::AsLocation() const {
117117
}
118118
} else {
119119
ASSERT(payload_type().IsFloat());
120-
if (payload_type().AsFundamental().representation() == kFloat) {
120+
if (payload_type().AsPrimitive().representation() == kFloat) {
121121
return Location::StackSlot(offset_in_words(), base_register_);
122122
} else {
123-
ASSERT(payload_type().AsFundamental().representation() == kDouble);
123+
ASSERT(payload_type().AsPrimitive().representation() == kDouble);
124124
return Location::DoubleStackSlot(offset_in_words(), base_register_);
125125
}
126126
}

runtime/vm/compiler/ffi/native_type.cc

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ namespace compiler {
1919

2020
namespace ffi {
2121

22-
const NativeFundamentalType& NativeType::AsFundamental() const {
23-
ASSERT(IsFundamental());
24-
return static_cast<const NativeFundamentalType&>(*this);
22+
const NativePrimitiveType& NativeType::AsPrimitive() const {
23+
ASSERT(IsPrimitive());
24+
return static_cast<const NativePrimitiveType&>(*this);
2525
}
2626

27-
bool NativeFundamentalType::IsInt() const {
27+
bool NativePrimitiveType::IsInt() const {
2828
switch (representation_) {
2929
case kInt8:
3030
case kUint8:
@@ -40,16 +40,16 @@ bool NativeFundamentalType::IsInt() const {
4040
}
4141
}
4242

43-
bool NativeFundamentalType::IsFloat() const {
43+
bool NativePrimitiveType::IsFloat() const {
4444
return representation_ == kFloat || representation_ == kDouble ||
4545
representation_ == kHalfDouble;
4646
}
4747

48-
bool NativeFundamentalType::IsVoid() const {
48+
bool NativePrimitiveType::IsVoid() const {
4949
return representation_ == kVoid;
5050
}
5151

52-
bool NativeFundamentalType::IsSigned() const {
52+
bool NativePrimitiveType::IsSigned() const {
5353
ASSERT(IsInt() || IsFloat());
5454
switch (representation_) {
5555
case kInt8:
@@ -84,11 +84,11 @@ static const intptr_t fundamental_size_in_bytes[kVoid + 1] = {
8484
0, // kVoid,
8585
};
8686

87-
intptr_t NativeFundamentalType::SizeInBytes() const {
87+
intptr_t NativePrimitiveType::SizeInBytes() const {
8888
return fundamental_size_in_bytes[representation_];
8989
}
9090

91-
intptr_t NativeFundamentalType::AlignmentInBytesStack() const {
91+
intptr_t NativePrimitiveType::AlignmentInBytesStack() const {
9292
switch (CallingConventions::kArgumentStackAlignment) {
9393
case kAlignedToWordSize:
9494
// The default is to align stack arguments to word size.
@@ -108,7 +108,7 @@ intptr_t NativeFundamentalType::AlignmentInBytesStack() const {
108108
}
109109
}
110110

111-
intptr_t NativeFundamentalType::AlignmentInBytesField() const {
111+
intptr_t NativePrimitiveType::AlignmentInBytesField() const {
112112
switch (CallingConventions::kFieldAlignment) {
113113
case kAlignedToValueSize:
114114
// The default is to align fields to their own size.
@@ -127,7 +127,7 @@ intptr_t NativeFundamentalType::AlignmentInBytesField() const {
127127
}
128128

129129
#if !defined(DART_PRECOMPILED_RUNTIME)
130-
bool NativeFundamentalType::IsExpressibleAsRepresentation() const {
130+
bool NativePrimitiveType::IsExpressibleAsRepresentation() const {
131131
switch (representation_) {
132132
case kInt8:
133133
case kUint8:
@@ -149,7 +149,7 @@ bool NativeFundamentalType::IsExpressibleAsRepresentation() const {
149149
}
150150
}
151151

152-
Representation NativeFundamentalType::AsRepresentation() const {
152+
Representation NativePrimitiveType::AsRepresentation() const {
153153
ASSERT(IsExpressibleAsRepresentation());
154154
switch (representation_) {
155155
case kInt32:
@@ -171,14 +171,14 @@ Representation NativeFundamentalType::AsRepresentation() const {
171171
}
172172
#endif // !defined(DART_PRECOMPILED_RUNTIME)
173173

174-
bool NativeFundamentalType::Equals(const NativeType& other) const {
175-
if (!other.IsFundamental()) {
174+
bool NativePrimitiveType::Equals(const NativeType& other) const {
175+
if (!other.IsPrimitive()) {
176176
return false;
177177
}
178-
return other.AsFundamental().representation_ == representation_;
178+
return other.AsPrimitive().representation_ == representation_;
179179
}
180180

181-
static FundamentalType split_fundamental(FundamentalType in) {
181+
static PrimitiveType split_fundamental(PrimitiveType in) {
182182
switch (in) {
183183
case kInt16:
184184
return kInt8;
@@ -199,14 +199,14 @@ static FundamentalType split_fundamental(FundamentalType in) {
199199
}
200200
}
201201

202-
NativeFundamentalType& NativeFundamentalType::Split(Zone* zone,
203-
intptr_t index) const {
202+
NativePrimitiveType& NativePrimitiveType::Split(Zone* zone,
203+
intptr_t index) const {
204204
ASSERT(index == 0 || index == 1);
205205
auto new_rep = split_fundamental(representation());
206-
return *new (zone) NativeFundamentalType(new_rep);
206+
return *new (zone) NativePrimitiveType(new_rep);
207207
}
208208

209-
static FundamentalType TypeRepresentation(classid_t class_id) {
209+
static PrimitiveType TypeRepresentation(classid_t class_id) {
210210
switch (class_id) {
211211
case kFfiInt8Cid:
212212
return kInt8;
@@ -245,7 +245,7 @@ static FundamentalType TypeRepresentation(classid_t class_id) {
245245
NativeType& NativeType::FromTypedDataClassId(Zone* zone, classid_t class_id) {
246246
// TODO(36730): Support composites.
247247
const auto fundamental_rep = TypeRepresentation(class_id);
248-
return *new (zone) NativeFundamentalType(fundamental_rep);
248+
return *new (zone) NativePrimitiveType(fundamental_rep);
249249
}
250250

251251
NativeType& NativeType::FromAbstractType(Zone* zone, const AbstractType& type) {
@@ -254,7 +254,7 @@ NativeType& NativeType::FromAbstractType(Zone* zone, const AbstractType& type) {
254254
}
255255

256256
#if !defined(DART_PRECOMPILED_RUNTIME)
257-
static FundamentalType fundamental_rep(Representation rep) {
257+
static PrimitiveType fundamental_rep(Representation rep) {
258258
switch (rep) {
259259
case kUnboxedDouble:
260260
return kDouble;
@@ -272,10 +272,9 @@ static FundamentalType fundamental_rep(Representation rep) {
272272
UNREACHABLE();
273273
}
274274

275-
NativeFundamentalType& NativeType::FromUnboxedRepresentation(
276-
Zone* zone,
277-
Representation rep) {
278-
return *new (zone) NativeFundamentalType(fundamental_rep(rep));
275+
NativePrimitiveType& NativeType::FromUnboxedRepresentation(Zone* zone,
276+
Representation rep) {
277+
return *new (zone) NativePrimitiveType(fundamental_rep(rep));
279278
}
280279
#endif // !defined(DART_PRECOMPILED_RUNTIME)
281280

@@ -286,7 +285,7 @@ const char* NativeType::ToCString() const {
286285
return Thread::Current()->zone()->MakeCopyOfString(buffer);
287286
}
288287

289-
static const char* FundamentalTypeToCString(FundamentalType rep) {
288+
static const char* PrimitiveTypeToCString(PrimitiveType rep) {
290289
switch (rep) {
291290
case kInt8:
292291
return "int8";
@@ -321,16 +320,16 @@ void NativeType::PrintTo(BaseTextBuffer* f) const {
321320
f->AddString("I");
322321
}
323322

324-
void NativeFundamentalType::PrintTo(BaseTextBuffer* f) const {
325-
f->Printf("%s", FundamentalTypeToCString(representation_));
323+
void NativePrimitiveType::PrintTo(BaseTextBuffer* f) const {
324+
f->Printf("%s", PrimitiveTypeToCString(representation_));
326325
}
327326

328327
const NativeType& NativeType::WidenTo4Bytes(Zone* zone) const {
329328
if (IsInt() && SizeInBytes() <= 2) {
330329
if (IsSigned()) {
331-
return *new (zone) NativeFundamentalType(kInt32);
330+
return *new (zone) NativePrimitiveType(kInt32);
332331
} else {
333-
return *new (zone) NativeFundamentalType(kUint32);
332+
return *new (zone) NativePrimitiveType(kUint32);
334333
}
335334
}
336335
return *this;

runtime/vm/compiler/ffi/native_type.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace compiler {
2323

2424
namespace ffi {
2525

26-
class NativeFundamentalType;
26+
class NativePrimitiveType;
2727

2828
// NativeTypes are the types used in calling convention specifications:
2929
// integers, floats, and composites.
@@ -38,13 +38,13 @@ class NativeFundamentalType;
3838
//
3939
// Instead, NativeTypes support representations not supported in Dart's unboxed
4040
// Representations, such as:
41-
// * Fundamental types (https://en.cppreference.com/w/cpp/language/types):
41+
// * Primitive types:
4242
// * int8_t
4343
// * int16_t
4444
// * uint8_t
4545
// * uint16t
4646
// * void
47-
// * Compound types (https://en.cppreference.com/w/cpp/language/type):
47+
// * Compound types:
4848
// * Struct
4949
// * Union
5050
//
@@ -55,12 +55,12 @@ class NativeType : public ZoneAllocated {
5555
static NativeType& FromTypedDataClassId(Zone* zone, classid_t class_id);
5656

5757
#if !defined(DART_PRECOMPILED_RUNTIME)
58-
static NativeFundamentalType& FromUnboxedRepresentation(Zone* zone,
59-
Representation rep);
58+
static NativePrimitiveType& FromUnboxedRepresentation(Zone* zone,
59+
Representation rep);
6060
#endif
6161

62-
virtual bool IsFundamental() const { return false; }
63-
const NativeFundamentalType& AsFundamental() const;
62+
virtual bool IsPrimitive() const { return false; }
63+
const NativePrimitiveType& AsPrimitive() const;
6464

6565
virtual bool IsInt() const { return false; }
6666
virtual bool IsFloat() const { return false; }
@@ -111,7 +111,7 @@ class NativeType : public ZoneAllocated {
111111
NativeType() {}
112112
};
113113

114-
enum FundamentalType {
114+
enum PrimitiveType {
115115
kInt8,
116116
kUint8,
117117
kInt16,
@@ -127,13 +127,19 @@ enum FundamentalType {
127127
// TODO(37470): Add packed data structures.
128128
};
129129

130-
class NativeFundamentalType : public NativeType {
130+
// Represents a primitive native type.
131+
//
132+
// These are called object types in the C standard (ISO/IEC 9899:2011) and
133+
// fundamental types in C++ (https://en.cppreference.com/w/cpp/language/types)
134+
// but more commonly these are called primitive types
135+
// (https://en.wikipedia.org/wiki/Primitive_data_type).
136+
class NativePrimitiveType : public NativeType {
131137
public:
132-
explicit NativeFundamentalType(FundamentalType rep) : representation_(rep) {}
138+
explicit NativePrimitiveType(PrimitiveType rep) : representation_(rep) {}
133139

134-
FundamentalType representation() const { return representation_; }
140+
PrimitiveType representation() const { return representation_; }
135141

136-
virtual bool IsFundamental() const { return true; }
142+
virtual bool IsPrimitive() const { return true; }
137143

138144
virtual bool IsInt() const;
139145
virtual bool IsFloat() const;
@@ -151,14 +157,14 @@ class NativeFundamentalType : public NativeType {
151157
#endif // !defined(DART_PRECOMPILED_RUNTIME)
152158

153159
virtual bool Equals(const NativeType& other) const;
154-
virtual NativeFundamentalType& Split(Zone* zone, intptr_t part) const;
160+
virtual NativePrimitiveType& Split(Zone* zone, intptr_t part) const;
155161

156162
virtual void PrintTo(BaseTextBuffer* f) const;
157163

158-
virtual ~NativeFundamentalType() {}
164+
virtual ~NativePrimitiveType() {}
159165

160166
private:
161-
const FundamentalType representation_;
167+
const PrimitiveType representation_;
162168
};
163169

164170
} // namespace ffi

0 commit comments

Comments
 (0)