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

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2469273003: [stubs] Add a utility class to generate code to access builtin arguments (Closed)
Patch Set: Fix build Created 4 years, 1 month 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
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 "src/base/utils/random-number-generator.h" 5 #include "src/base/utils/random-number-generator.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/code-stub-assembler.h" 7 #include "src/code-stub-assembler.h"
8 #include "src/compiler/node.h" 8 #include "src/compiler/node.h"
9 #include "src/ic/stub-cache.h" 9 #include "src/ic/stub-cache.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1], 1914 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1],
1915 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]); 1915 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
1916 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2], 1916 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2],
1917 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]); 1917 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
1918 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3], 1918 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3],
1919 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]); 1919 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
1920 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4], 1920 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4],
1921 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]); 1921 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
1922 } 1922 }
1923 1923
1924 TEST(Arguments) {
1925 Isolate* isolate(CcTest::InitIsolateOnce());
1926
1927 const int kNumParams = 4;
1928 CodeStubAssemblerTester m(isolate, kNumParams);
1929
1930 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1931
1932 m.Assert(m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12))));
1933 m.Assert(m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13))));
1934 m.Assert(m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14))));
1935
1936 m.Return(arguments.GetReceiver());
1937
1938 Handle<Code> code = m.GenerateCode();
1939 CHECK(!code.is_null());
1940
1941 FunctionTester ft(code, kNumParams);
1942 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1943 Handle<Smi>(Smi::FromInt(12), isolate),
1944 Handle<Smi>(Smi::FromInt(13), isolate),
1945 Handle<Smi>(Smi::FromInt(14), isolate))
1946 .ToHandleChecked();
1947 CHECK_EQ(*isolate->factory()->undefined_value(), *result);
1948 }
1949
1950 TEST(ArgumentsForEach) {
1951 Isolate* isolate(CcTest::InitIsolateOnce());
1952
1953 const int kNumParams = 4;
1954 CodeStubAssemblerTester m(isolate, kNumParams);
1955
1956 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1957
1958 CodeStubAssemblerTester::Variable sum(&m,
1959 MachineType::PointerRepresentation());
1960 CodeStubAssemblerTester::VariableList list({&sum}, m.zone());
1961
1962 sum.Bind(m.IntPtrConstant(0));
1963
1964 arguments.ForEach(list, [&m, &sum](CodeStubAssembler* assembler, Node* arg) {
1965 sum.Bind(assembler->IntPtrAdd(sum.value(), arg));
1966 });
1967
1968 m.Return(sum.value());
1969
1970 Handle<Code> code = m.GenerateCode();
1971 CHECK(!code.is_null());
1972
1973 FunctionTester ft(code, kNumParams);
1974 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1975 Handle<Smi>(Smi::FromInt(12), isolate),
1976 Handle<Smi>(Smi::FromInt(13), isolate),
1977 Handle<Smi>(Smi::FromInt(14), isolate))
1978 .ToHandleChecked();
1979 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result);
1980 }
1981
1924 } // namespace internal 1982 } // namespace internal
1925 } // namespace v8 1983 } // namespace v8
OLDNEW
« src/code-stub-assembler.cc ('K') | « test/cctest/compiler/code-assembler-tester.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698