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
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.
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.
31 #include "code-stubs.h"
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:
49 // set_in_spilled_code
52 // These methods are either used privately by the shared code or implemented as
59 // ProcessDeclarations
61 // CheckForInlineRuntimeCall
63 // CodeForFunctionPosition
64 // CodeForReturnPosition
65 // CodeForStatementPosition
66 // CodeForDoWhileConditionPosition
67 // CodeForSourcePosition
69 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
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"
80 #error Unsupported target architecture.
87 class CompilationInfo;
92 // Printing of AST, etc. as requested by flags.
93 static void MakeCodePrologue(CompilationInfo* info, const char* kind);
95 // Allocate and install the code.
96 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
98 CompilationInfo* info);
100 // Print the code after compiling it.
101 static void PrintCode(Handle<Code> code, CompilationInfo* info);
103 static bool ShouldGenerateLog(Isolate* isolate, Expression* type);
105 static bool RecordPositions(MacroAssembler* masm,
107 bool right_here = false);
110 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
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);
119 UnaryMathFunction CreateExpFunction();
120 UnaryMathFunction CreateSqrtFunction();
123 class ElementsTransitionGenerator : public AllStatic {
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,
133 static void GenerateDoubleToObject(MacroAssembler* masm,
134 AllocationSiteMode mode,
138 DISALLOW_COPY_AND_ASSIGN(ElementsTransitionGenerator);
141 static const int kNumberDictionaryProbes = 4;
144 } } // namespace v8::internal
146 #endif // V8_CODEGEN_H_