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

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

Issue 145083007: Type representation converter (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 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.cc ('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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 Handle<i::JSObject> object2; 112 Handle<i::JSObject> object2;
113 Handle<i::JSArray> array; 113 Handle<i::JSArray> array;
114 114
115 TypeHandle Union(TypeHandle t1, TypeHandle t2) { 115 TypeHandle Union(TypeHandle t1, TypeHandle t2) {
116 return Type::Union(t1, t2, region_); 116 return Type::Union(t1, t2, region_);
117 } 117 }
118 TypeHandle Intersect(TypeHandle t1, TypeHandle t2) { 118 TypeHandle Intersect(TypeHandle t1, TypeHandle t2) {
119 return Type::Intersect(t1, t2, region_); 119 return Type::Intersect(t1, t2, region_);
120 } 120 }
121 121
122 template<class Type2, class TypeHandle2>
123 TypeHandle Convert(TypeHandle2 t) {
124 return Type::template Convert<Type2>(t, region_);
125 }
126
127 TypeHandle Fuzz(int depth = 5) {
128 switch (random() % (depth == 0 ? 3 : 20)) {
129 case 0: { // bitset
130 int n = 0
131 #define COUNT_BITSET_TYPES(type, value) + 1
132 BITSET_TYPE_LIST(COUNT_BITSET_TYPES)
133 #undef COUNT_BITSET_TYPES
134 ;
135 int i = random() % n;
136 #define PICK_BITSET_TYPES(type, value) \
137 if (i-- == 0) return Type::type(region_);
138 BITSET_TYPE_LIST(PICK_BITSET_TYPES)
139 #undef PICK_BITSET_TYPES
140 UNREACHABLE();
141 }
142 case 1: // class
143 switch (random() % 2) {
144 case 0: return ObjectClass;
145 case 1: return ArrayClass;
146 }
147 UNREACHABLE();
148 case 2: // constant
149 switch (random() % 6) {
150 case 0: return SmiConstant;
151 case 1: return Signed32Constant;
152 case 2: return ObjectConstant1;
153 case 3: return ObjectConstant2;
154 case 4: return ArrayConstant1;
155 case 5: return ArrayConstant2;
156 }
157 UNREACHABLE();
158 default: { // union
159 int n = random() % 10;
160 TypeHandle type = None;
161 for (int i = 0; i < n; ++i) {
162 type = Type::Union(type, Fuzz(depth - 1), region_);
163 }
164 return type;
165 }
166 }
167 UNREACHABLE();
168 }
169
122 private: 170 private:
123 Region* region_; 171 Region* region_;
124 }; 172 };
125 173
126 174
127 // Testing auxiliaries (breaking the Type abstraction). 175 // Testing auxiliaries (breaking the Type abstraction).
128 struct ZoneRep { 176 struct ZoneRep {
129 static bool IsTagged(Type* t, int tag) { 177 static bool IsTagged(Type* t, int tag) {
130 return !IsBitset(t) 178 return !IsBitset(t)
131 && reinterpret_cast<intptr_t>(AsTagged(t)->at(0)) == tag; 179 && reinterpret_cast<intptr_t>(AsTagged(t)->at(0)) == tag;
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 T.Union( 797 T.Union(
750 T.ObjectConstant1, 798 T.ObjectConstant1,
751 T.Union(T.ArrayConstant1, T.ObjectConstant2))), 799 T.Union(T.ArrayConstant1, T.ObjectConstant2))),
752 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 800 T.Union(T.ObjectConstant2, T.ObjectConstant1));
753 CheckEqual( 801 CheckEqual(
754 T.Intersect( 802 T.Intersect(
755 T.Union(T.ObjectConstant2, T.ArrayConstant1), 803 T.Union(T.ObjectConstant2, T.ArrayConstant1),
756 T.Union(T.ObjectConstant1, T.ArrayConstant2)), 804 T.Union(T.ObjectConstant1, T.ArrayConstant2)),
757 T.ArrayConstant1); 805 T.ArrayConstant1);
758 } 806 }
807
808 template<class Type2, class TypeHandle2, class Region2, class Rep2>
809 void Convert() {
810 Types<Type2, TypeHandle2, Region2> T2(
811 Rep2::ToRegion(&zone, isolate), isolate);
812 for (int i = 0; i < 100; ++i) {
813 TypeHandle type = T.Fuzz();
814 CheckEqual(type, T.Convert<Type2>(T2.Convert<Type>(type)));
815 }
816 }
759 }; 817 };
760 818
761 typedef Tests<Type, Type*, Zone, ZoneRep> ZoneTests; 819 typedef Tests<Type, Type*, Zone, ZoneRep> ZoneTests;
762 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests; 820 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests;
763 821
764 822
765 TEST(Bitset) { 823 TEST(Bitset) {
766 CcTest::InitializeVM(); 824 CcTest::InitializeVM();
767 ZoneTests().Bitset(); 825 ZoneTests().Bitset();
768 HeapTests().Bitset(); 826 HeapTests().Bitset();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 ZoneTests().Union(); 860 ZoneTests().Union();
803 HeapTests().Union(); 861 HeapTests().Union();
804 } 862 }
805 863
806 864
807 TEST(Intersect) { 865 TEST(Intersect) {
808 CcTest::InitializeVM(); 866 CcTest::InitializeVM();
809 ZoneTests().Intersect(); 867 ZoneTests().Intersect();
810 HeapTests().Intersect(); 868 HeapTests().Intersect();
811 } 869 }
870
871
872 TEST(Convert) {
873 CcTest::InitializeVM();
874 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
875 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
876 }
OLDNEW
« no previous file with comments | « src/types.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698