Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: test/cctest/test-types.cc

Issue 224733023: Reland "Refactoring to allow adding new structured types" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/types-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 UNREACHABLE(); 169 UNREACHABLE();
170 } 170 }
171 171
172 private: 172 private:
173 Region* region_; 173 Region* region_;
174 }; 174 };
175 175
176 176
177 // Testing auxiliaries (breaking the Type abstraction). 177 // Testing auxiliaries (breaking the Type abstraction).
178 struct ZoneRep { 178 struct ZoneRep {
179 static bool IsTagged(Type* t, int tag) { 179 struct Struct { int tag; int length; void* args[1]; };
180 return !IsBitset(t) 180
181 && reinterpret_cast<intptr_t>(AsTagged(t)->at(0)) == tag; 181 static bool IsStruct(Type* t, int tag) {
182 return !IsBitset(t) && AsStruct(t)->tag == tag;
182 } 183 }
183 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; } 184 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; }
184 static bool IsClass(Type* t) { return IsTagged(t, 0); } 185 static bool IsClass(Type* t) { return IsStruct(t, 0); }
185 static bool IsConstant(Type* t) { return IsTagged(t, 1); } 186 static bool IsConstant(Type* t) { return IsStruct(t, 1); }
186 static bool IsUnion(Type* t) { return IsTagged(t, 2); } 187 static bool IsUnion(Type* t) { return IsStruct(t, 2); }
187 188
188 static ZoneList<void*>* AsTagged(Type* t) { 189 static Struct* AsStruct(Type* t) {
189 return reinterpret_cast<ZoneList<void*>*>(t); 190 return reinterpret_cast<Struct*>(t);
190 } 191 }
191 static int AsBitset(Type* t) { 192 static int AsBitset(Type* t) {
192 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1); 193 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1);
193 } 194 }
194 static Map* AsClass(Type* t) { 195 static Map* AsClass(Type* t) {
195 return *reinterpret_cast<Map**>(AsTagged(t)->at(2)); 196 return *static_cast<Map**>(AsStruct(t)->args[1]);
196 } 197 }
197 static Object* AsConstant(Type* t) { 198 static Object* AsConstant(Type* t) {
198 return *reinterpret_cast<Object**>(AsTagged(t)->at(2)); 199 return *static_cast<Object**>(AsStruct(t)->args[1]);
199 } 200 }
200 static ZoneList<Type*>* AsUnion(Type* t) { 201 static Struct* AsUnion(Type* t) {
201 return reinterpret_cast<ZoneList<Type*>*>(AsTagged(t)); 202 return AsStruct(t);
202 } 203 }
204 static int Length(Struct* structured) { return structured->length; }
203 205
204 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } 206 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
205 }; 207 };
206 208
207 209
208 struct HeapRep { 210 struct HeapRep {
211 typedef FixedArray Struct;
212
213 static bool IsStruct(Handle<HeapType> t, int tag) {
214 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag;
215 }
209 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } 216 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); }
210 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); } 217 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); }
211 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); } 218 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); }
212 static bool IsUnion(Handle<HeapType> t) { return t->IsFixedArray(); } 219 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 2); }
213 220
221 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); }
214 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } 222 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); }
215 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); } 223 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); }
216 static Object* AsConstant(Handle<HeapType> t) { 224 static Object* AsConstant(Handle<HeapType> t) {
217 return Box::cast(*t)->value(); 225 return Box::cast(*t)->value();
218 } 226 }
219 static FixedArray* AsUnion(Handle<HeapType> t) { 227 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); }
220 return FixedArray::cast(*t); 228 static int Length(Struct* structured) { return structured->length() - 1; }
221 }
222 229
223 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } 230 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
224 }; 231 };
225 232
226 233
227 template<class Type, class TypeHandle, class Region, class Rep> 234 template<class Type, class TypeHandle, class Region, class Rep>
228 struct Tests : Rep { 235 struct Tests : Rep {
229 Isolate* isolate; 236 Isolate* isolate;
230 HandleScope scope; 237 HandleScope scope;
231 Zone zone; 238 Zone zone;
(...skipping 13 matching lines...) Expand all
245 CHECK_EQ(Rep::IsUnion(type1), Rep::IsUnion(type2)); 252 CHECK_EQ(Rep::IsUnion(type1), Rep::IsUnion(type2));
246 CHECK_EQ(type1->NumClasses(), type2->NumClasses()); 253 CHECK_EQ(type1->NumClasses(), type2->NumClasses());
247 CHECK_EQ(type1->NumConstants(), type2->NumConstants()); 254 CHECK_EQ(type1->NumConstants(), type2->NumConstants());
248 if (Rep::IsBitset(type1)) { 255 if (Rep::IsBitset(type1)) {
249 CHECK_EQ(Rep::AsBitset(type1), Rep::AsBitset(type2)); 256 CHECK_EQ(Rep::AsBitset(type1), Rep::AsBitset(type2));
250 } else if (Rep::IsClass(type1)) { 257 } else if (Rep::IsClass(type1)) {
251 CHECK_EQ(Rep::AsClass(type1), Rep::AsClass(type2)); 258 CHECK_EQ(Rep::AsClass(type1), Rep::AsClass(type2));
252 } else if (Rep::IsConstant(type1)) { 259 } else if (Rep::IsConstant(type1)) {
253 CHECK_EQ(Rep::AsConstant(type1), Rep::AsConstant(type2)); 260 CHECK_EQ(Rep::AsConstant(type1), Rep::AsConstant(type2));
254 } else if (Rep::IsUnion(type1)) { 261 } else if (Rep::IsUnion(type1)) {
255 CHECK_EQ(Rep::AsUnion(type1)->length(), Rep::AsUnion(type2)->length()); 262 CHECK_EQ(
263 Rep::Length(Rep::AsUnion(type1)), Rep::Length(Rep::AsUnion(type2)));
256 } 264 }
257 CHECK(type1->Is(type2)); 265 CHECK(type1->Is(type2));
258 CHECK(type2->Is(type1)); 266 CHECK(type2->Is(type1));
259 } 267 }
260 268
261 void CheckSub(TypeHandle type1, TypeHandle type2) { 269 void CheckSub(TypeHandle type1, TypeHandle type2) {
262 CHECK(type1->Is(type2)); 270 CHECK(type1->Is(type2));
263 CHECK(!type2->Is(type1)); 271 CHECK(!type2->Is(type1));
264 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 272 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
265 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2)); 273 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2));
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 ZoneTests().Intersect(); 885 ZoneTests().Intersect();
878 HeapTests().Intersect(); 886 HeapTests().Intersect();
879 } 887 }
880 888
881 889
882 TEST(Convert) { 890 TEST(Convert) {
883 CcTest::InitializeVM(); 891 CcTest::InitializeVM();
884 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 892 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
885 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 893 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
886 } 894 }
OLDNEW
« no previous file with comments | « src/types-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698