blob: a8de9c8610fbe079371a8065a7cf561785518ba7 [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"
Ben Murdoch85b71792012-04-11 18:30:58 +010034#include "code-stubs-mips.h"
Steve Block44f0eee2011-05-26 01:26:41 +010035#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 static bool ShouldGenerateLog(Expression* type);
Andrei Popescu31002712010-02-23 13:46:05 +000064
65 static void SetFunctionInfo(Handle<JSFunction> fun,
66 FunctionLiteral* lit,
67 bool is_toplevel,
68 Handle<Script> script);
69
Steve Block44f0eee2011-05-26 01:26:41 +010070 static bool RecordPositions(MacroAssembler* masm,
71 int pos,
72 bool right_here = false);
Andrei Popescu31002712010-02-23 13:46:05 +000073
Ben Murdoch85b71792012-04-11 18:30:58 +010074 // Constants related to patching of inlined load/store.
75 static int GetInlinedKeyedLoadInstructionsAfterPatch() {
76 // This is in correlation with the padding in MacroAssembler::Abort.
77 return FLAG_debug_code ? 45 : 20;
78 }
79
80 static const int kInlinedKeyedStoreInstructionsAfterPatch = 13;
81
82 static int GetInlinedNamedStoreInstructionsAfterPatch() {
83 ASSERT(Isolate::Current()->inlined_write_barrier_size() != -1);
84 // Magic number 5: instruction count after patched map load:
85 // li: 2 (liu & ori), Branch : 2 (bne & nop), sw : 1
86 return Isolate::Current()->inlined_write_barrier_size() + 5;
87 }
88
Andrei Popescu31002712010-02-23 13:46:05 +000089 private:
Andrei Popescu31002712010-02-23 13:46:05 +000090 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
91};
92
93
94} } // namespace v8::internal
95
96#endif // V8_MIPS_CODEGEN_MIPS_H_