Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / v8 / src / codegen.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
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 #ifndef V8_CODEGEN_H_
29 #define V8_CODEGEN_H_
30
31 #include "code-stubs.h"
32 #include "runtime.h"
33
34 // Include the declaration of the architecture defined class CodeGenerator.
35 // The contract  to the shared code is that the the CodeGenerator is a subclass
36 // of Visitor and that the following methods are available publicly:
37 //   MakeCode
38 //   MakeCodePrologue
39 //   MakeCodeEpilogue
40 //   masm
41 //   frame
42 //   script
43 //   has_valid_frame
44 //   SetFrame
45 //   DeleteFrame
46 //   allocator
47 //   AddDeferred
48 //   in_spilled_code
49 //   set_in_spilled_code
50 //   RecordPositions
51 //
52 // These methods are either used privately by the shared code or implemented as
53 // shared code:
54 //   CodeGenerator
55 //   ~CodeGenerator
56 //   Generate
57 //   ComputeLazyCompile
58 //   BuildFunctionInfo
59 //   ProcessDeclarations
60 //   DeclareGlobals
61 //   CheckForInlineRuntimeCall
62 //   AnalyzeCondition
63 //   CodeForFunctionPosition
64 //   CodeForReturnPosition
65 //   CodeForStatementPosition
66 //   CodeForDoWhileConditionPosition
67 //   CodeForSourcePosition
68
69 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
70
71 #if V8_TARGET_ARCH_IA32
72 #include "ia32/codegen-ia32.h"
73 #elif V8_TARGET_ARCH_X64
74 #include "x64/codegen-x64.h"
75 #elif V8_TARGET_ARCH_ARM
76 #include "arm/codegen-arm.h"
77 #elif V8_TARGET_ARCH_MIPS
78 #include "mips/codegen-mips.h"
79 #else
80 #error Unsupported target architecture.
81 #endif
82
83 namespace v8 {
84 namespace internal {
85
86
87 class CompilationInfo;
88
89
90 class CodeGenerator {
91  public:
92   // Printing of AST, etc. as requested by flags.
93   static void MakeCodePrologue(CompilationInfo* info, const char* kind);
94
95   // Allocate and install the code.
96   static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
97                                        Code::Flags flags,
98                                        CompilationInfo* info);
99
100   // Print the code after compiling it.
101   static void PrintCode(Handle<Code> code, CompilationInfo* info);
102
103   static bool ShouldGenerateLog(Isolate* isolate, Expression* type);
104
105   static bool RecordPositions(MacroAssembler* masm,
106                               int pos,
107                               bool right_here = false);
108
109  private:
110   DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
111 };
112
113
114 // Results of the library implementation of transcendental functions may differ
115 // from the one we use in our generated code.  Therefore we use the same
116 // generated code both in runtime and compiled code.
117 typedef double (*UnaryMathFunction)(double x);
118
119 UnaryMathFunction CreateExpFunction();
120 UnaryMathFunction CreateSqrtFunction();
121
122
123 class ElementsTransitionGenerator : public AllStatic {
124  public:
125   // If |mode| is set to DONT_TRACK_ALLOCATION_SITE,
126   // |allocation_memento_found| may be NULL.
127   static void GenerateMapChangeElementsTransition(MacroAssembler* masm,
128       AllocationSiteMode mode,
129       Label* allocation_memento_found);
130   static void GenerateSmiToDouble(MacroAssembler* masm,
131                                   AllocationSiteMode mode,
132                                   Label* fail);
133   static void GenerateDoubleToObject(MacroAssembler* masm,
134                                      AllocationSiteMode mode,
135                                      Label* fail);
136
137  private:
138   DISALLOW_COPY_AND_ASSIGN(ElementsTransitionGenerator);
139 };
140
141 static const int kNumberDictionaryProbes = 4;
142
143
144 } }  // namespace v8::internal
145
146 #endif  // V8_CODEGEN_H_