Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | |
|
Jakob Kummerow
2013/11/07 09:01:06
nit: 2013
danno
2013/11/07 13:19:57
Done.
| |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 #include <stdlib.h> | |
| 29 | |
| 30 #include "v8.h" | |
| 31 | |
| 32 #include "macro-assembler.h" | |
| 33 #include "factory.h" | |
| 34 #include "platform.h" | |
| 35 #include "serialize.h" | |
| 36 #include "cctest.h" | |
| 37 | |
| 38 using namespace v8::internal; | |
| 39 | |
| 40 typedef int (*F0)(); | |
| 41 | |
| 42 #define __ masm-> | |
| 43 | |
| 44 | |
| 45 TEST(LoadAndStoreWithRepresentation) { | |
| 46 v8::internal::V8::Initialize(NULL); | |
| 47 | |
| 48 // Allocate an executable page of memory. | |
| 49 size_t actual_size; | |
| 50 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | |
| 51 &actual_size, | |
| 52 true)); | |
| 53 CHECK(buffer); | |
| 54 Isolate* isolate = CcTest::i_isolate(); | |
| 55 HandleScope handles(isolate); | |
| 56 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size)); | |
| 57 MacroAssembler* masm = &assembler; // Create a pointer for the __ macro. | |
| 58 masm->set_allow_stub_calls(false); | |
| 59 __ sub(esp, Immediate(1 * kPointerSize)); | |
| 60 Label exit; | |
| 61 | |
| 62 // Test 1. | |
| 63 __ mov(eax, Immediate(1)); // Test number. | |
| 64 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0)); | |
| 65 __ mov(ecx, Immediate(-1)); | |
| 66 __ Store(ecx, Operand(esp, 0 * kPointerSize), Representation::UInteger8()); | |
| 67 __ mov(ecx, Operand(esp, 0 * kPointerSize)); | |
| 68 __ mov(edx, Immediate(255)); | |
| 69 __ cmp(ecx, edx); | |
| 70 __ j(not_equal, &exit); | |
| 71 __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::UInteger8()); | |
| 72 __ cmp(ecx, edx); | |
| 73 __ j(not_equal, &exit); | |
| 74 | |
| 75 // Test 2. | |
| 76 __ mov(eax, Immediate(2)); // Test number. | |
| 77 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0)); | |
| 78 __ mov(ecx, Immediate(-1)); | |
| 79 __ Store(ecx, Operand(esp, 0 * kPointerSize), Representation::Integer8()); | |
| 80 __ mov(ecx, Operand(esp, 0 * kPointerSize)); | |
| 81 __ mov(edx, Immediate(255)); | |
| 82 __ cmp(ecx, edx); | |
| 83 __ j(not_equal, &exit); | |
| 84 __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::Integer8()); | |
| 85 __ mov(ecx, Immediate(-1)); | |
| 86 __ cmp(ecx, edx); | |
| 87 __ j(not_equal, &exit); | |
| 88 | |
| 89 // Test 3. | |
| 90 __ mov(eax, Immediate(3)); // Test number. | |
| 91 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0)); | |
| 92 __ mov(ecx, Immediate(-1)); | |
| 93 __ Store(ecx, Operand(esp, 0 * kPointerSize), Representation::Integer16()); | |
| 94 __ mov(ecx, Operand(esp, 0 * kPointerSize)); | |
| 95 __ mov(edx, Immediate(65535)); | |
| 96 __ cmp(ecx, edx); | |
| 97 __ j(not_equal, &exit); | |
| 98 __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::Integer16()); | |
| 99 __ mov(ecx, Immediate(-1)); | |
| 100 __ cmp(ecx, edx); | |
| 101 __ j(not_equal, &exit); | |
| 102 | |
| 103 // Test 4. | |
| 104 __ mov(eax, Immediate(4)); // Test number. | |
| 105 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0)); | |
| 106 __ mov(ecx, Immediate(-1)); | |
| 107 __ Store(ecx, Operand(esp, 0 * kPointerSize), Representation::UInteger16()); | |
| 108 __ mov(ecx, Operand(esp, 0 * kPointerSize)); | |
| 109 __ mov(edx, Immediate(65535)); | |
| 110 __ cmp(ecx, edx); | |
| 111 __ j(not_equal, &exit); | |
| 112 __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::UInteger16()); | |
| 113 __ cmp(ecx, edx); | |
| 114 __ j(not_equal, &exit); | |
| 115 | |
| 116 __ xor_(eax, eax); // Success. | |
| 117 __ bind(&exit); | |
| 118 __ add(esp, Immediate(1 * kPointerSize)); | |
| 119 __ ret(0); | |
| 120 | |
| 121 CodeDesc desc; | |
| 122 masm->GetCode(&desc); | |
| 123 // Call the function from C++. | |
| 124 int result = FUNCTION_CAST<F0>(buffer)(); | |
| 125 CHECK_EQ(0, result); | |
| 126 } | |
| 127 | |
| 128 #undef __ | |
| OLD | NEW |