initial import
[vuplus_webkit] / Source / JavaScriptCore / dfg / DFGGPRInfo.h
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef DFGGPRInfo_h
27 #define DFGGPRInfo_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include <assembler/MacroAssembler.h>
32 #include <dfg/DFGRegisterBank.h>
33
34 namespace JSC { namespace DFG {
35
36 typedef MacroAssembler::RegisterID GPRReg;
37 #define InvalidGPRReg ((GPRReg)-1)
38
39 class GPRInfo {
40 public:
41     typedef GPRReg RegisterType;
42     static const unsigned numberOfRegisters = 9;
43
44     // These registers match the old JIT.
45     static const GPRReg cachedResultRegister = X86Registers::eax;
46     static const GPRReg timeoutCheckRegister = X86Registers::r12;
47     static const GPRReg callFrameRegister = X86Registers::r13;
48     static const GPRReg tagTypeNumberRegister = X86Registers::r14;
49     static const GPRReg tagMaskRegister = X86Registers::r15;
50     // Temporary registers.
51     static const GPRReg regT0 = X86Registers::eax;
52     static const GPRReg regT1 = X86Registers::edx;
53     static const GPRReg regT2 = X86Registers::ecx;
54     static const GPRReg regT3 = X86Registers::ebx;
55     static const GPRReg regT4 = X86Registers::edi;
56     static const GPRReg regT5 = X86Registers::esi;
57     static const GPRReg regT6 = X86Registers::r8;
58     static const GPRReg regT7 = X86Registers::r9;
59     static const GPRReg regT8 = X86Registers::r10;
60     // These constants provide the names for the general purpose argument & return value registers.
61     static const GPRReg argumentGPR0 = X86Registers::edi; // regT4
62     static const GPRReg argumentGPR1 = X86Registers::esi; // regT5
63     static const GPRReg argumentGPR2 = X86Registers::edx; // regT1
64     static const GPRReg argumentGPR3 = X86Registers::ecx; // regT2
65     static const GPRReg returnValueGPR = X86Registers::eax; // regT0
66     static const GPRReg returnValueGPR2 = X86Registers::edx; // regT1
67
68     static GPRReg toRegister(unsigned index)
69     {
70         ASSERT(index < numberOfRegisters);
71         static const GPRReg registerForIndex[numberOfRegisters] = { regT0, regT1, regT2, regT3, regT4, regT5, regT6, regT7, regT8 };
72         return registerForIndex[index];
73     }
74
75     static unsigned toIndex(GPRReg reg)
76     {
77         ASSERT(reg != InvalidGPRReg);
78         ASSERT(reg < 16);
79         static const unsigned indexForRegister[16] = { 0, 2, 1, 3, InvalidIndex, InvalidIndex, 5, 4, 6, 7, 8, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex };
80         unsigned result = indexForRegister[reg];
81         ASSERT(result != InvalidIndex);
82         return result;
83     }
84
85 #ifndef NDEBUG
86     static const char* debugName(GPRReg reg)
87     {
88         ASSERT(reg != InvalidGPRReg);
89         ASSERT(reg < 16);
90         static const char* nameForRegister[16] = {
91             "rax", "rcx", "rdx", "rbx",
92             "rsp", "rbp", "rsi", "rdi",
93             "r8", "r9", "r10", "r11",
94             "r12", "r13", "r14", "r15"
95         };
96         return nameForRegister[reg];
97     }
98 #endif
99 private:
100
101     static const unsigned InvalidIndex = 0xffffffff;
102 };
103
104 typedef RegisterBank<GPRInfo>::iterator gpr_iterator;
105
106 } } // namespace JSC::DFG
107
108 #endif
109 #endif