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

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

Issue 2147403002: V8. ASM-2-WASM. Fixes issue 628446. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « src/asmjs/asm-typer.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cstring> 5 #include <cstring>
6 #include <functional> 6 #include <functional>
7 #include <iostream> 7 #include <iostream>
8 #include <memory> 8 #include <memory>
9 9
10 #include "src/asmjs/asm-typer.h" 10 #include "src/asmjs/asm-typer.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 AsmTyperHarnessBuilder* WithReturnType(AsmType* type) { 171 AsmTyperHarnessBuilder* WithReturnType(AsmType* type) {
172 CHECK(type->IsReturnType()); 172 CHECK(type->IsReturnType());
173 CHECK(typer_->return_type_ == AsmType::None()); 173 CHECK(typer_->return_type_ == AsmType::None());
174 typer_->return_type_ = type; 174 typer_->return_type_ = type;
175 return this; 175 return this;
176 } 176 }
177 177
178 AsmTyperHarnessBuilder* WithStdlib(VariableName var_name) { 178 AsmTyperHarnessBuilder* WithStdlib(VariableName var_name) {
179 auto* var = DeclareVariable(var_name); 179 auto* var = DeclareVariable(var_name);
180 auto* var_info = new (zone_) AsmTyper::VariableInfo(); 180 auto* var_info =
181 var_info->set_mutability(AsmTyper::VariableInfo::kImmutableGlobal); 181 AsmTyper::VariableInfo::ForSpecialSymbol(zone_, AsmTyper::kStdlib);
182 var_info->set_standard_member(AsmTyper::kStdlib);
183 CHECK(typer_->AddGlobal(var, var_info)); 182 CHECK(typer_->AddGlobal(var, var_info));
184 return this; 183 return this;
185 } 184 }
186 185
187 AsmTyperHarnessBuilder* WithHeap(VariableName var_name) { 186 AsmTyperHarnessBuilder* WithHeap(VariableName var_name) {
188 auto* var = DeclareVariable(var_name); 187 auto* var = DeclareVariable(var_name);
189 auto* var_info = new (zone_) AsmTyper::VariableInfo(); 188 auto* var_info =
190 var_info->set_mutability(AsmTyper::VariableInfo::kImmutableGlobal); 189 AsmTyper::VariableInfo::ForSpecialSymbol(zone_, AsmTyper::kHeap);
191 var_info->set_standard_member(AsmTyper::kHeap);
192 CHECK(typer_->AddGlobal(var, var_info)); 190 CHECK(typer_->AddGlobal(var, var_info));
193 return this; 191 return this;
194 } 192 }
195 193
196 AsmTyperHarnessBuilder* WithFFI(VariableName var_name) { 194 AsmTyperHarnessBuilder* WithFFI(VariableName var_name) {
197 auto* var = DeclareVariable(var_name); 195 auto* var = DeclareVariable(var_name);
198 auto* var_info = 196 auto* var_info =
199 new (zone_) AsmTyper::VariableInfo(AsmType::FFIType(zone_)); 197 AsmTyper::VariableInfo::ForSpecialSymbol(zone_, AsmTyper::kFFI);
200 var_info->set_mutability(AsmTyper::VariableInfo::kImmutableGlobal);
201 var_info->set_standard_member(AsmTyper::kFFI);
202 CHECK(typer_->AddGlobal(var, var_info)); 198 CHECK(typer_->AddGlobal(var, var_info));
203 return this; 199 return this;
204 } 200 }
205 201
206 bool Succeeds() { 202 bool Succeeds() {
207 CHECK(validation_type_ == ValidateModule || 203 CHECK(validation_type_ == ValidateModule ||
208 validation_type_ == ValidateGlobals || 204 validation_type_ == ValidateGlobals ||
209 validation_type_ == ValidateFunctionTables || 205 validation_type_ == ValidateFunctionTables ||
210 validation_type_ == ValidateExport || 206 validation_type_ == ValidateExport ||
211 validation_type_ == ValidateFunction || 207 validation_type_ == ValidateFunction ||
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 auto* ret = iw::AsmType::FunctionTableType(zone, 2, d2s); 899 auto* ret = iw::AsmType::FunctionTableType(zone, 2, d2s);
904 return ret; 900 return ret;
905 }; 901 };
906 902
907 const struct { 903 const struct {
908 const char* expression; 904 const char* expression;
909 const char* error_message; 905 const char* error_message;
910 } kTests[] = { 906 } kTests[] = {
911 {"noy_a_function();", "Unanotated call to a function must be a call to"}, 907 {"noy_a_function();", "Unanotated call to a function must be a call to"},
912 {"a = 0;", "Undeclared identifier"}, 908 {"a = 0;", "Undeclared identifier"},
909 // we can't verify the module's name being referenced here because
910 // expression validation does not invoke ValidateModule, which sets up the
911 // module information in the AsmTyper.
912 {"stdlib", "accessed by ordinary expressions"},
913 {"ffi", "accessed by ordinary expressions"},
914 {"heap", "accessed by ordinary expressions"},
915 {"d2d", "accessed by ordinary expression"},
916 {"fround", "accessed by ordinary expression"},
917 {"d2s_tbl", "accessed by ordinary expression"},
913 {"ilocal = +1.0", "Type mismatch in assignment"}, 918 {"ilocal = +1.0", "Type mismatch in assignment"},
914 {"!dlocal", "Invalid type for !"}, 919 {"!dlocal", "Invalid type for !"},
915 {"2 * dlocal", "Invalid types for intish *"}, 920 {"2 * dlocal", "Invalid types for intish *"},
916 {"dlocal * 2", "Invalid types for intish *"}, 921 {"dlocal * 2", "Invalid types for intish *"},
917 {"1048577 * ilocal", "Invalid operands for *"}, 922 {"1048577 * ilocal", "Invalid operands for *"},
918 {"1048577 / ilocal", "Invalid operands for /"}, 923 {"1048577 / ilocal", "Invalid operands for /"},
919 {"1048577 % dlocal", "Invalid operands for %"}, 924 {"1048577 % dlocal", "Invalid operands for %"},
920 {"1048577 * dlocal", "Invalid operands for *"}, 925 {"1048577 * dlocal", "Invalid operands for *"},
921 {"1048577 / dlocal", "Invalid operands for /"}, 926 {"1048577 / dlocal", "Invalid operands for /"},
922 {"1048577 % ilocal", "Invalid operands for %"}, 927 {"1048577 % ilocal", "Invalid operands for %"},
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 // *VIOLATION* the following is invalid, but because of desugaring it is 987 // *VIOLATION* the following is invalid, but because of desugaring it is
983 // accepted. 988 // accepted.
984 // {"HEAP32[0 >> 1] = 0", "Invalid heap access index"}, 989 // {"HEAP32[0 >> 1] = 0", "Invalid heap access index"},
985 {"HEAP8[fround(0.0)] = 0", "Invalid heap access index for byte array"}, 990 {"HEAP8[fround(0.0)] = 0", "Invalid heap access index for byte array"},
986 {"HEAP8[iish] = 0", "Invalid heap access index for byte array"}, 991 {"HEAP8[iish] = 0", "Invalid heap access index for byte array"},
987 }; 992 };
988 993
989 for (size_t ii = 0; ii < arraysize(kTests); ++ii) { 994 for (size_t ii = 0; ii < arraysize(kTests); ++ii) {
990 const auto* test = kTests + ii; 995 const auto* test = kTests + ii;
991 if (!ValidationOf(Expression(test->expression)) 996 if (!ValidationOf(Expression(test->expression))
997 ->WithStdlib(DynamicGlobal("stdlib"))
998 ->WithFFI(DynamicGlobal("ffi"))
999 ->WithHeap(DynamicGlobal("heap"))
992 ->WithLocal(DynamicGlobal("iish"), iw::AsmType::Intish()) 1000 ->WithLocal(DynamicGlobal("iish"), iw::AsmType::Intish())
993 ->WithLocal(DynamicGlobal("ilocal"), iw::AsmType::Int()) 1001 ->WithLocal(DynamicGlobal("ilocal"), iw::AsmType::Int())
994 ->WithLocal(DynamicGlobal("dlocal"), iw::AsmType::Double()) 1002 ->WithLocal(DynamicGlobal("dlocal"), iw::AsmType::Double())
995 ->WithLocal(DynamicGlobal("dlocal2"), iw::AsmType::Double()) 1003 ->WithLocal(DynamicGlobal("dlocal2"), iw::AsmType::Double())
996 ->WithLocal(DynamicGlobal("not_a_function"), iw::AsmType::Int()) 1004 ->WithLocal(DynamicGlobal("not_a_function"), iw::AsmType::Int())
997 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround) 1005 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround)
998 ->WithImport(DynamicGlobal("FFI"), iw::AsmTyper::kFFI) 1006 ->WithImport(DynamicGlobal("FFI"), iw::AsmTyper::kFFI)
999 ->WithGlobal(DynamicGlobal("d2d"), d2d) 1007 ->WithGlobal(DynamicGlobal("d2d"), d2d)
1000 ->WithGlobal(DynamicGlobal("d2s_tbl"), d2s_tbl) 1008 ->WithGlobal(DynamicGlobal("d2s_tbl"), d2s_tbl)
1001 ->WithGlobal(DynamicGlobal("HEAP32"), iw::AsmType::Int32Array()) 1009 ->WithGlobal(DynamicGlobal("HEAP32"), iw::AsmType::Int32Array())
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 ->WithGlobal(DynamicGlobal("ifd2f_tbl"), ifd2f_tbl) 1764 ->WithGlobal(DynamicGlobal("ifd2f_tbl"), ifd2f_tbl)
1757 ->WithGlobal(DynamicGlobal("ifd2d_tbl"), ifd2d_tbl) 1765 ->WithGlobal(DynamicGlobal("ifd2d_tbl"), ifd2d_tbl)
1758 ->WithGlobal(DynamicGlobal("ifd2i_tbl"), ifd2i_tbl) 1766 ->WithGlobal(DynamicGlobal("ifd2i_tbl"), ifd2i_tbl)
1759 ->SucceedsWithExactType(test->load_type)) { 1767 ->SucceedsWithExactType(test->load_type)) {
1760 std::cerr << "Test:\n" << test->expression; 1768 std::cerr << "Test:\n" << test->expression;
1761 CHECK(false); 1769 CHECK(false);
1762 } 1770 }
1763 } 1771 }
1764 } 1772 }
1765 1773
1774 TEST(CannotReferenceModuleName) {
1775 v8::V8::Initialize();
1776
1777 const struct {
1778 const char* module;
1779 const char* error_message;
1780 } kTests[] = {
1781 {"function asm() {\n"
1782 " 'use asm';\n"
1783 " function f() { asm; }\n"
1784 "}",
1785 "accessed by ordinary expressions"},
1786 {"function asm() { 'use asm'; return asm; }", "Module cannot export"},
1787 };
1788
1789 for (size_t ii = 0; ii < arraysize(kTests); ++ii) {
1790 const auto* test = kTests + ii;
1791 if (!ValidationOf(Module(test->module))
1792 ->FailsWithMessage(test->error_message)) {
1793 std::cerr << "Test:\n" << test->module;
1794 CHECK(false);
1795 }
1796 }
1797 }
1798
1766 } // namespace 1799 } // namespace
OLDNEW
« no previous file with comments | « src/asmjs/asm-typer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698