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/test-code-stub-assembler.cc

Issue 2469273003: [stubs] Add a utility class to generate code to access builtin arguments (Closed)
Patch Set: Review feedback 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
« no previous file with comments | « test/cctest/compiler/code-assembler-tester.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 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 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1], 1910 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1],
1911 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]); 1911 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
1912 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2], 1912 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2],
1913 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]); 1913 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
1914 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3], 1914 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3],
1915 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]); 1915 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
1916 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4], 1916 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4],
1917 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]); 1917 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
1918 } 1918 }
1919 1919
1920 TEST(Arguments) {
1921 Isolate* isolate(CcTest::InitIsolateOnce());
1922
1923 const int kNumParams = 4;
1924 CodeStubAssemblerTester m(isolate, kNumParams);
1925
1926 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1927
1928 m.Assert(m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12))));
1929 m.Assert(m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13))));
1930 m.Assert(m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14))));
1931
1932 m.Return(arguments.GetReceiver());
1933
1934 Handle<Code> code = m.GenerateCode();
1935 CHECK(!code.is_null());
1936
1937 FunctionTester ft(code, kNumParams);
1938 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1939 Handle<Smi>(Smi::FromInt(12), isolate),
1940 Handle<Smi>(Smi::FromInt(13), isolate),
1941 Handle<Smi>(Smi::FromInt(14), isolate))
1942 .ToHandleChecked();
1943 CHECK_EQ(*isolate->factory()->undefined_value(), *result);
1944 }
1945
1946 TEST(ArgumentsForEach) {
1947 Isolate* isolate(CcTest::InitIsolateOnce());
1948
1949 const int kNumParams = 4;
1950 CodeStubAssemblerTester m(isolate, kNumParams);
1951
1952 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1953
1954 CodeStubAssemblerTester::Variable sum(&m,
1955 MachineType::PointerRepresentation());
1956 CodeStubAssemblerTester::VariableList list({&sum}, m.zone());
1957
1958 sum.Bind(m.IntPtrConstant(0));
1959
1960 arguments.ForEach(list, [&m, &sum](CodeStubAssembler* assembler, Node* arg) {
1961 sum.Bind(assembler->IntPtrAdd(sum.value(), arg));
1962 });
1963
1964 m.Return(sum.value());
1965
1966 Handle<Code> code = m.GenerateCode();
1967 CHECK(!code.is_null());
1968
1969 FunctionTester ft(code, kNumParams);
1970 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1971 Handle<Smi>(Smi::FromInt(12), isolate),
1972 Handle<Smi>(Smi::FromInt(13), isolate),
1973 Handle<Smi>(Smi::FromInt(14), isolate))
1974 .ToHandleChecked();
1975 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result);
1976 }
1977
1920 } // namespace internal 1978 } // namespace internal
1921 } // namespace v8 1979 } // namespace v8
OLDNEW
« no previous file with comments | « 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