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

Unified Diff: test/cctest/compiler/test-code-stub-assembler.cc

Issue 1705073005: CodeStubAssembler can generate code for builtins (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rename Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/raw-machine-assembler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/compiler/test-code-stub-assembler.cc
diff --git a/test/cctest/compiler/test-code-stub-assembler.cc b/test/cctest/compiler/test-code-stub-assembler.cc
index 0306561020abe41e5342f9cc209062f67bd9d208..2bf785b422627c35a4b946aaec387cbe4575111d 100644
--- a/test/cctest/compiler/test-code-stub-assembler.cc
+++ b/test/cctest/compiler/test-code-stub-assembler.cc
@@ -13,12 +13,19 @@ namespace compiler {
class CodeStubAssemblerTester : public CodeStubAssembler {
public:
+ // Test generating code for a stub.
CodeStubAssemblerTester(Isolate* isolate,
const CallInterfaceDescriptor& descriptor)
: CodeStubAssembler(isolate, isolate->runtime_zone(), descriptor,
Code::ComputeFlags(Code::STUB), "test"),
scope_(isolate) {}
+ // Test generating code for a JS function (e.g. builtins).
+ CodeStubAssemblerTester(Isolate* isolate, int parameter_count)
+ : CodeStubAssembler(isolate, isolate->runtime_zone(), parameter_count,
+ Code::ComputeFlags(Code::FUNCTION), "test"),
+ scope_(isolate) {}
+
private:
HandleScope scope_;
LocalContext context_;
@@ -247,6 +254,83 @@ TEST(FixedArrayAccessSmiIndex) {
CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
+TEST(LoadHeapNumberValue) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ VoidDescriptor descriptor(isolate);
+ CodeStubAssemblerTester m(isolate, descriptor);
+ Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234);
+ m.Return(m.SmiTag(
+ m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number)))));
+ Handle<Code> code = m.GenerateCode();
+ FunctionTester ft(descriptor, code);
+ MaybeHandle<Object> result = ft.Call();
+ CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value());
+}
+
+TEST(LoadInstanceType) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ VoidDescriptor descriptor(isolate);
+ CodeStubAssemblerTester m(isolate, descriptor);
+ Handle<HeapObject> undefined = isolate->factory()->undefined_value();
+ m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined))));
+ Handle<Code> code = m.GenerateCode();
+ FunctionTester ft(descriptor, code);
+ MaybeHandle<Object> result = ft.Call();
+ CHECK_EQ(InstanceType::ODDBALL_TYPE,
+ Handle<Smi>::cast(result.ToHandleChecked())->value());
+}
+
+namespace {
+
+class TestBitField : public BitField<unsigned, 3, 3> {};
+
+} // namespace
+
+TEST(BitFieldDecode) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ VoidDescriptor descriptor(isolate);
+ CodeStubAssemblerTester m(isolate, descriptor);
+ m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f))));
+ Handle<Code> code = m.GenerateCode();
+ FunctionTester ft(descriptor, code);
+ MaybeHandle<Object> result = ft.Call();
+ // value = 00101111
+ // mask = 00111000
+ // result = 101
+ CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value());
+}
+
+namespace {
+
+Handle<JSFunction> CreateFunctionFromCode(int parameter_count_with_receiver,
+ Handle<Code> code) {
+ Isolate* isolate = code->GetIsolate();
+ Handle<String> name = isolate->factory()->InternalizeUtf8String("test");
+ Handle<JSFunction> function =
+ isolate->factory()->NewFunctionWithoutPrototype(name, code);
+ function->shared()->set_internal_formal_parameter_count(
+ parameter_count_with_receiver - 1); // Implicit undefined receiver.
+ return function;
+}
+
+} // namespace
+
+TEST(JSFunction) {
+ const int kNumParams = 3; // Receiver, left, right.
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ CodeStubAssemblerTester m(isolate, kNumParams);
+ m.Return(m.SmiTag(
+ m.Int32Add(m.SmiToInt32(m.Parameter(1)), m.SmiToInt32(m.Parameter(2)))));
+ Handle<Code> code = m.GenerateCode();
+ Handle<JSFunction> function = CreateFunctionFromCode(kNumParams, code);
+ Handle<Object> args[] = {Handle<Smi>(Smi::FromInt(23), isolate),
+ Handle<Smi>(Smi::FromInt(34), isolate)};
+ MaybeHandle<Object> result =
+ Execution::Call(isolate, function, isolate->factory()->undefined_value(),
+ arraysize(args), args);
+ CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/raw-machine-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698