1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "platform/assert.h" |
6 | #include "vm/globals.h" |
7 | #if defined(TARGET_ARCH_X64) |
8 | |
9 | #include "vm/compiler/assembler/assembler.h" |
10 | #include "vm/object.h" |
11 | #include "vm/unit_test.h" |
12 | |
13 | namespace dart { |
14 | |
15 | #define __ assembler-> |
16 | |
17 | // Generate a simple dart code sequence. |
18 | // This is used to test Code and Instruction object creation. |
19 | void GenerateIncrement(compiler::Assembler* assembler) { |
20 | __ movq(RAX, compiler::Immediate(0)); |
21 | __ pushq(RAX); |
22 | __ incq(compiler::Address(RSP, 0)); |
23 | __ movq(RCX, compiler::Address(RSP, 0)); |
24 | __ incq(RCX); |
25 | __ popq(RAX); |
26 | __ movq(RAX, RCX); |
27 | __ ret(); |
28 | } |
29 | |
30 | // Generate a dart code sequence that embeds a string object in it. |
31 | // This is used to test Embedded String objects in the instructions. |
32 | void GenerateEmbedStringInCode(compiler::Assembler* assembler, |
33 | const char* str) { |
34 | const String& string_object = |
35 | String::ZoneHandle(String::New(str, Heap::kOld)); |
36 | __ EnterStubFrame(); |
37 | __ LoadObject(RAX, string_object); |
38 | __ LeaveStubFrame(); |
39 | __ ret(); |
40 | } |
41 | |
42 | // Generate a dart code sequence that embeds a smi object in it. |
43 | // This is used to test Embedded Smi objects in the instructions. |
44 | void GenerateEmbedSmiInCode(compiler::Assembler* assembler, intptr_t value) { |
45 | const Smi& smi_object = Smi::ZoneHandle(Smi::New(value)); |
46 | __ movq(RAX, compiler::Immediate(static_cast<int64_t>(smi_object.raw()))); |
47 | __ ret(); |
48 | } |
49 | |
50 | } // namespace dart |
51 | |
52 | #endif // defined TARGET_ARCH_X64 |
53 | |