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

Side by Side Diff: test/cctest/asmjs/test-asm-lexer.cc

Issue 2751693002: [wasm][asm.js] Adding custom asm.js lexer. (Closed)
Patch Set: fix warning Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
vogelheim 2017/03/14 13:36:38 nitpick: 2017
vogelheim 2017/03/14 13:36:38 Please consider using unittests/.., rather than cc
bradn 2017/03/15 07:53:04 Done.
bradn 2017/03/15 07:53:04 Done. Thanks for the suggestion!
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/asmjs/asm-lexer.h"
6 #include "src/v8.h"
7 #include "test/cctest/cctest.h"
8
9 namespace v8 {
10 namespace internal {
11
12 #define SKIP(t) \
13 do { \
14 CHECK_EQ((t), lexer.Token()); \
15 lexer.Next(); \
16 } while (0);
17
18 #define TOK(t) AsmJsLexer::kToken_##t
19
20 #define SKIP_GLOBAL() \
21 do { \
22 CHECK(lexer.IsGlobal()); \
23 lexer.Next(); \
24 } while (0);
25
26 #define SKIP_LOCAL() \
27 do { \
28 CHECK(lexer.IsLocal()); \
29 lexer.Next(); \
30 } while (0);
31
32 #define CHECK_FOR_END() CHECK(lexer.Token() == AsmJsLexer::kEndOfInput);
33
34 #define SETUP_SOURCE(ssource) \
35 v8::V8::Initialize(); \
36 v8::Isolate* isolate = CcTest::isolate(); \
37 v8::HandleScope handles(isolate); \
38 i::Isolate* i_isolate = CcTest::i_isolate(); \
39 i::Factory* factory = i_isolate->factory(); \
40 i::Handle<i::String> source = factory->InternalizeUtf8String(ssource); \
41 i::Handle<i::Script> script = factory->NewScript(source); \
42 AsmJsLexer lexer(i_isolate, script, 0, source->length());
43
44 TEST(SimpleFunction) {
45 SETUP_SOURCE("function foo() { return; }");
46 SKIP(TOK(function));
47 DCHECK_EQ("foo", lexer.name());
48 SKIP_GLOBAL();
49 SKIP('(');
50 SKIP(')');
51 SKIP('{');
52 SKIP(TOK(return ));
53 SKIP(';');
54 SKIP('}');
55 CHECK_FOR_END();
56 }
57
58 TEST(JSKeywords) {
59 SETUP_SOURCE(
60 "arguments break case const continue\n"
61 "default do else eval for function\n"
62 "if new return switch var while\n");
63 SKIP(TOK(arguments));
64 SKIP(TOK(break));
65 SKIP(TOK(case));
66 SKIP(TOK(const));
67 SKIP(TOK(continue));
68 SKIP(TOK(default));
69 SKIP(TOK(do));
70 SKIP(TOK(else));
71 SKIP(TOK(eval));
72 SKIP(TOK(for));
73 SKIP(TOK(function));
74 SKIP(TOK(if));
75 SKIP(TOK(new));
76 SKIP(TOK(return ));
77 SKIP(TOK(switch));
78 SKIP(TOK(var));
79 SKIP(TOK(while));
80 CHECK_FOR_END();
81 }
82
83 TEST(JSOperatorsSpread) {
84 SETUP_SOURCE(
85 "+ - * / % & | ^ ~ << >> >>>\n"
86 "< > <= >= == !=\n");
87 SKIP('+');
88 SKIP('-');
89 SKIP('*');
90 SKIP('/');
91 SKIP('%');
92 SKIP('&');
93 SKIP('|');
94 SKIP('^');
95 SKIP('~');
96 SKIP(TOK(SHL));
97 SKIP(TOK(SAR));
98 SKIP(TOK(SHR));
99 SKIP('<');
100 SKIP('>');
101 SKIP(TOK(LE));
102 SKIP(TOK(GE));
103 SKIP(TOK(EQ));
104 SKIP(TOK(NE));
105 CHECK_FOR_END();
106 }
107
108 TEST(JSOperatorsTight) {
109 SETUP_SOURCE(
110 "+-*/%&|^~<<>> >>>\n"
111 "<><=>= ==!=\n");
112 SKIP('+');
113 SKIP('-');
114 SKIP('*');
115 SKIP('/');
116 SKIP('%');
117 SKIP('&');
118 SKIP('|');
119 SKIP('^');
120 SKIP('~');
121 SKIP(TOK(SHL));
122 SKIP(TOK(SAR));
123 SKIP(TOK(SHR));
124 SKIP('<');
125 SKIP('>');
126 SKIP(TOK(LE));
127 SKIP(TOK(GE));
128 SKIP(TOK(EQ));
129 SKIP(TOK(NE));
130 CHECK_FOR_END();
131 }
132
133 TEST(UsesOfAsm) {
134 SETUP_SOURCE("'use asm' \"use asm\"\n");
135 SKIP(TOK(UseAsm));
136 SKIP(TOK(UseAsm));
137 CHECK_FOR_END();
138 }
139
140 TEST(GlobalAssignment) {
141 SETUP_SOURCE("var x = x + x;");
142 SKIP(TOK(var));
143 CHECK_EQ("x", lexer.name());
144 AsmJsLexer::token_t x = lexer.Token();
145 SKIP_GLOBAL();
146 SKIP('=');
147 SKIP(x);
148 SKIP('+');
149 SKIP(x);
150 SKIP(';');
151 CHECK_FOR_END();
152 }
153
154 TEST(LocalAssignment) {
155 SETUP_SOURCE("var x = x + x;");
156 lexer.SetLocalScope(true);
157 SKIP(TOK(var));
158 CHECK_EQ("x", lexer.name());
159 AsmJsLexer::token_t x = lexer.Token();
160 SKIP_LOCAL();
161 SKIP('=');
162 SKIP(x);
163 SKIP('+');
164 SKIP(x);
165 SKIP(';');
166 CHECK_FOR_END();
167 }
168
169 TEST(Numbers) {
170 SETUP_SOURCE("1 1.2 0x1f 1.e3");
171
172 CHECK(lexer.IsUnsigned());
173 CHECK_EQ(1, lexer.AsUnsigned());
174 lexer.Next();
175
176 CHECK(lexer.IsDouble());
177 CHECK_EQ(1.2, lexer.AsDouble());
178 lexer.Next();
179
180 CHECK(lexer.IsUnsigned());
181 CHECK_EQ(31, lexer.AsUnsigned());
182 lexer.Next();
183
184 CHECK(lexer.IsDouble());
185 CHECK_EQ(1.0e3, lexer.AsDouble());
186 lexer.Next();
187
188 CHECK_FOR_END();
189 }
190
191 TEST(Rewind1) {
192 SETUP_SOURCE("+ - * /");
193 SKIP('+');
194 lexer.Rewind();
195 SKIP('+');
196 SKIP('-');
197 lexer.Rewind();
198 SKIP('-');
199 SKIP('*');
200 lexer.Rewind();
201 SKIP('*');
202 SKIP('/');
203 lexer.Rewind();
204 SKIP('/');
205 CHECK_FOR_END();
206 }
207
208 TEST(Comments) {
209 SETUP_SOURCE(
210 "var // This is a test /* */\n"
211 "function /* this */ ^");
212 SKIP(TOK(var));
213 SKIP(TOK(function));
214 SKIP('^');
215 CHECK_FOR_END();
216 }
217
218 } // namespace internal
219 } // namespace v8
OLDNEW
« src/asmjs/asm-names.h ('K') | « test/cctest/BUILD.gn ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698