blob: 67634aa13af283dce4f11ac5cbd28668c30651d1 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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#ifndef V8_CODE_STUBS_H_
29#define V8_CODE_STUBS_H_
30
31namespace v8 { namespace internal {
32
33
34// Stub is base classes of all stubs.
35class CodeStub BASE_EMBEDDED {
36 public:
37 enum Major {
38 CallFunction,
kasper.lund7276f142008-07-30 08:49:36 +000039 GenericBinaryOp,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000040 SmiOp,
41 Compare,
42 RecordWrite, // Last stub that allows stub calls inside.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000043 StackCheck,
44 UnarySub,
45 RevertToNumber,
kasper.lund7276f142008-07-30 08:49:36 +000046 ToBoolean,
ager@chromium.org7c537e22008-10-16 08:43:32 +000047 Instanceof,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000048 CounterOp,
49 ArgumentsAccess,
50 Runtime,
51 CEntry,
52 JSEntry,
53 GetProperty, // ARM only
54 SetProperty, // ARM only
55 InvokeBuiltin, // ARM only
56 JSExit, // ARM only
57 NUMBER_OF_IDS
58 };
59
60 // Retrieve the code for the stub. Generate the code if needed.
61 Handle<Code> GetCode();
62
63 static Major MajorKeyFromKey(uint32_t key) {
64 return static_cast<Major>(MajorKeyBits::decode(key));
65 };
66 static int MinorKeyFromKey(uint32_t key) {
67 return MinorKeyBits::decode(key);
68 };
69 static const char* MajorName(Major major_key);
70
71 virtual ~CodeStub() {}
72
mads.s.ager31e71382008-08-13 09:32:07 +000073 protected:
74 static const int kMajorBits = 5;
ager@chromium.org9085a012009-05-11 19:22:57 +000075 static const int kMinorBits = kBitsPerInt - kSmiTagSize - kMajorBits;
mads.s.ager31e71382008-08-13 09:32:07 +000076
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000077 private:
78 // Generates the assembler code for the stub.
79 virtual void Generate(MacroAssembler* masm) = 0;
80
81 // Returns information for computing the number key.
82 virtual Major MajorKey() = 0;
83 virtual int MinorKey() = 0;
84
85 // Returns a name for logging/debugging purposes.
ager@chromium.org7c537e22008-10-16 08:43:32 +000086 virtual const char* GetName() { return MajorName(MajorKey()); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000087
88#ifdef DEBUG
89 virtual void Print() { PrintF("%s\n", GetName()); }
90#endif
91
92 // Computes the key based on major and minor.
93 uint32_t GetKey() {
94 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
95 return MinorKeyBits::encode(MinorKey()) |
96 MajorKeyBits::encode(MajorKey());
97 }
98
99 bool AllowsStubCalls() { return MajorKey() <= RecordWrite; }
100
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000101 class MajorKeyBits: public BitField<uint32_t, 0, kMajorBits> {};
102 class MinorKeyBits: public BitField<uint32_t, kMajorBits, kMinorBits> {};
103
104 friend class BreakPointIterator;
105};
106
107} } // namespace v8::internal
108
109#endif // V8_CODE_STUBS_H_