blob: fecd321fad481b03e7f91d7dd012657b3dd0450e [file] [log] [blame]
Ben Murdoch257744e2011-11-30 15:57:28 +00001// Copyright 2011 the V8 project authors. All rights reserved.
Andrei Popescu31002712010-02-23 13:46:05 +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
29#ifndef V8_MIPS_CODEGEN_MIPS_H_
30#define V8_MIPS_CODEGEN_MIPS_H_
31
Steve Block44f0eee2011-05-26 01:26:41 +010032
33#include "ast.h"
34#include "code-stubs-mips.h"
35#include "ic-inl.h"
36
Andrei Popescu31002712010-02-23 13:46:05 +000037namespace v8 {
38namespace internal {
39
40// Forward declarations
41class CompilationInfo;
Andrei Popescu31002712010-02-23 13:46:05 +000042
Andrei Popescu31002712010-02-23 13:46:05 +000043enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
Steve Block44f0eee2011-05-26 01:26:41 +010044
45// -------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +000046// CodeGenerator
47
48class CodeGenerator: public AstVisitor {
49 public:
Steve Block44f0eee2011-05-26 01:26:41 +010050 static bool MakeCode(CompilationInfo* info);
Andrei Popescu31002712010-02-23 13:46:05 +000051
52 // Printing of AST, etc. as requested by flags.
53 static void MakeCodePrologue(CompilationInfo* info);
54
55 // Allocate and install the code.
56 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
57 Code::Flags flags,
58 CompilationInfo* info);
59
Steve Block44f0eee2011-05-26 01:26:41 +010060 // Print the code after compiling it.
61 static void PrintCode(Handle<Code> code, CompilationInfo* info);
62
Andrei Popescu31002712010-02-23 13:46:05 +000063#ifdef ENABLE_LOGGING_AND_PROFILING
64 static bool ShouldGenerateLog(Expression* type);
65#endif
66
67 static void SetFunctionInfo(Handle<JSFunction> fun,
68 FunctionLiteral* lit,
69 bool is_toplevel,
70 Handle<Script> script);
71
Steve Block44f0eee2011-05-26 01:26:41 +010072 static bool RecordPositions(MacroAssembler* masm,
73 int pos,
74 bool right_here = false);
Andrei Popescu31002712010-02-23 13:46:05 +000075
Steve Block44f0eee2011-05-26 01:26:41 +010076 // Constants related to patching of inlined load/store.
77 static int GetInlinedKeyedLoadInstructionsAfterPatch() {
78 // This is in correlation with the padding in MacroAssembler::Abort.
79 return FLAG_debug_code ? 45 : 20;
80 }
Ben Murdoch257744e2011-11-30 15:57:28 +000081
82 static const int kInlinedKeyedStoreInstructionsAfterPatch = 13;
83
Steve Block44f0eee2011-05-26 01:26:41 +010084 static int GetInlinedNamedStoreInstructionsAfterPatch() {
85 ASSERT(Isolate::Current()->inlined_write_barrier_size() != -1);
86 // Magic number 5: instruction count after patched map load:
87 // li: 2 (liu & ori), Branch : 2 (bne & nop), sw : 1
88 return Isolate::Current()->inlined_write_barrier_size() + 5;
89 }
Andrei Popescu31002712010-02-23 13:46:05 +000090
91 private:
Andrei Popescu31002712010-02-23 13:46:05 +000092 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
93};
94
95
96} } // namespace v8::internal
97
98#endif // V8_MIPS_CODEGEN_MIPS_H_