1d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke// Copyright 2010 the V8 project authors. All rights reserved.
2eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// Redistribution and use in source and binary forms, with or without
3eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// modification, are permitted provided that the following conditions are
4eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// met:
5eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//
6eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//     * Redistributions of source code must retain the above copyright
7eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//       notice, this list of conditions and the following disclaimer.
8eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//     * Redistributions in binary form must reproduce the above
9eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//       copyright notice, this list of conditions and the following
10eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//       disclaimer in the documentation and/or other materials provided
11eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//       with the distribution.
12eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//     * Neither the name of Google Inc. nor the names of its
13eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//       contributors may be used to endorse or promote products derived
14eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//       from this software without specific prior written permission.
15eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke//
16eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
28eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke#include "v8.h"
29eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
304515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke#include "codegen-inl.h"
314515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke#include "data-flow.h"
32eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke#include "fast-codegen.h"
33d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke#include "scopes.h"
34eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
35eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarkenamespace v8 {
36eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarkenamespace internal {
37eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
38d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke#define BAILOUT(reason)                         \
39d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  do {                                          \
40d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    if (FLAG_trace_bailout) {                   \
41d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke      PrintF("%s\n", reason);                   \
42d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    }                                           \
43d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    has_supported_syntax_ = false;              \
44d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    return;                                     \
45d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  } while (false)
46eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
47eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
48d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke#define CHECK_BAILOUT                           \
49d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  do {                                          \
50d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    if (!has_supported_syntax_) return;         \
51d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  } while (false)
52eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
53eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuvoid FastCodeGenSyntaxChecker::Check(CompilationInfo* info) {
554515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  info_ = info;
564515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
574515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // We do not specialize if we do not have a receiver or if it is not a
584515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // JS object with fast mode properties.
594515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  if (!info->has_receiver()) BAILOUT("No receiver");
604515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  if (!info->receiver()->IsJSObject()) BAILOUT("Receiver is not an object");
614515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  Handle<JSObject> object = Handle<JSObject>::cast(info->receiver());
624515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  if (!object->HasFastProperties()) BAILOUT("Receiver is in dictionary mode");
63eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
64d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  // We do not support stack or heap slots (both of which require
65d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  // allocation).
663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  Scope* scope = info->scope();
67d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  if (scope->num_stack_slots() > 0) {
68d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    BAILOUT("Function has stack-allocated locals");
69eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke  }
70d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  if (scope->num_heap_slots() > 0) {
71d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    BAILOUT("Function has context-allocated locals");
72eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke  }
73eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
74d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  VisitDeclarations(scope->declarations());
75d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  CHECK_BAILOUT;
76eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
77d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  // We do not support empty function bodies.
783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  if (info->function()->body()->is_empty()) {
793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu    BAILOUT("Function has an empty body");
803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  }
813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  VisitStatements(info->function()->body());
82eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
83eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
84eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
85d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitDeclarations(
86d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    ZoneList<Declaration*>* decls) {
87d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  if (!decls->is_empty()) BAILOUT("Function has declarations");
88eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
89eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
90eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
91d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitStatements(ZoneList<Statement*>* stmts) {
92402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  if (stmts->length() != 1) {
93402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    BAILOUT("Function body is not a singleton statement.");
94eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke  }
95402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  Visit(stmts->at(0));
96d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
97eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
98eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
99d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitDeclaration(Declaration* decl) {
100d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  UNREACHABLE();
101eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
102eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
103eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
104d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitBlock(Block* stmt) {
105eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke  VisitStatements(stmt->statements());
106eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
107eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
108eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
109d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitExpressionStatement(
110d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    ExpressionStatement* stmt) {
111d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  Visit(stmt->expression());
112eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
113eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
114eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
115d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitEmptyStatement(EmptyStatement* stmt) {
116d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  // Supported.
117eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
118eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
119eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
120d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitIfStatement(IfStatement* stmt) {
121d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("IfStatement");
122eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
123eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
124eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
125d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitContinueStatement(ContinueStatement* stmt) {
126d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("Continuestatement");
127eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
128eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
129eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
130d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitBreakStatement(BreakStatement* stmt) {
131d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("BreakStatement");
132eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
133eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
134eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
135d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitReturnStatement(ReturnStatement* stmt) {
136d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("ReturnStatement");
137d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
138eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
139eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
140d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitWithEnterStatement(
141d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    WithEnterStatement* stmt) {
142d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("WithEnterStatement");
143eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
144eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
145eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
146d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitWithExitStatement(WithExitStatement* stmt) {
147d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("WithExitStatement");
148d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
149eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
150eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
151d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitSwitchStatement(SwitchStatement* stmt) {
152d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("SwitchStatement");
153eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
154eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
155eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
156d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitDoWhileStatement(DoWhileStatement* stmt) {
157d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("DoWhileStatement");
158eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
159eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
160eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
161d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitWhileStatement(WhileStatement* stmt) {
162d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("WhileStatement");
163eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
164eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
165eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
166d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitForStatement(ForStatement* stmt) {
167d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("ForStatement");
168d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
169eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
170eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
171d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitForInStatement(ForInStatement* stmt) {
172d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("ForInStatement");
173d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
174eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
175eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
176d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitTryCatchStatement(TryCatchStatement* stmt) {
177d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("TryCatchStatement");
178d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
179eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
180eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
181d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitTryFinallyStatement(
182d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    TryFinallyStatement* stmt) {
183d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("TryFinallyStatement");
184eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
185eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
186eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
187d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitDebuggerStatement(
188d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    DebuggerStatement* stmt) {
189d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("DebuggerStatement");
190d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
191eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
192eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
193d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitFunctionLiteral(FunctionLiteral* expr) {
194d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("FunctionLiteral");
195d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
196eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
197eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
198d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitFunctionBoilerplateLiteral(
199d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    FunctionBoilerplateLiteral* expr) {
200d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("FunctionBoilerplateLiteral");
201d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
202eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
203eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
204d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitConditional(Conditional* expr) {
205d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("Conditional");
206eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
207eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
208eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
209d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitSlot(Slot* expr) {
210eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke  UNREACHABLE();
211eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
212eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
213eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
214d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitVariableProxy(VariableProxy* expr) {
215d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  // Only global variable references are supported.
216d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  Variable* var = expr->var();
2173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  if (!var->is_global() || var->is_this()) BAILOUT("Non-global variable");
2183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
2193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  // Check if the global variable is existing and non-deletable.
2203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  if (info()->has_global_object()) {
2213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu    LookupResult lookup;
2223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu    info()->global_object()->Lookup(*expr->name(), &lookup);
223402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (!lookup.IsProperty()) {
224402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("Non-existing global variable");
225402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    }
226402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    // We do not handle global variables with accessors or interceptors.
227402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (lookup.type() != NORMAL) {
228402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("Global variable with accessors or interceptors.");
229402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    }
230402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    // We do not handle deletable global variables.
231402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (!lookup.IsDontDelete()) {
232402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("Deletable global variable");
2333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu    }
2343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  }
235eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
236eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
237eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
238d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitLiteral(Literal* expr) {
239d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("Literal");
240d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
241eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
242eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
243d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitRegExpLiteral(RegExpLiteral* expr) {
244d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("RegExpLiteral");
245d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
246eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
247eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
248d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitObjectLiteral(ObjectLiteral* expr) {
249d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("ObjectLiteral");
250eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
251eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
252eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
253d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitArrayLiteral(ArrayLiteral* expr) {
254d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("ArrayLiteral");
255eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
256eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
257eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
258d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitCatchExtensionObject(
259d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    CatchExtensionObject* expr) {
260d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("CatchExtensionObject");
261eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
262eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
263eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
264d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitAssignment(Assignment* expr) {
265d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  // Simple assignments to (named) this properties are supported.
266d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  if (expr->op() != Token::ASSIGN) BAILOUT("Non-simple assignment");
267eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
268d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  Property* prop = expr->target()->AsProperty();
269d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  if (prop == NULL) BAILOUT("Non-property assignment");
270d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  VariableProxy* proxy = prop->obj()->AsVariableProxy();
271d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  if (proxy == NULL || !proxy->var()->is_this()) {
272d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    BAILOUT("Non-this-property assignment");
273eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke  }
274d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  if (!prop->key()->IsPropertyName()) {
275d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke    BAILOUT("Non-named-property assignment");
276eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke  }
277d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke
2784515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // We will only specialize for fields on the object itself.
2794515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Expression::IsPropertyName implies that the name is a literal
2804515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // symbol but we do not assume that.
2814515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  Literal* key = prop->key()->AsLiteral();
2824515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  if (key != NULL && key->handle()->IsString()) {
2834515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    Handle<Object> receiver = info()->receiver();
2844515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    Handle<String> name = Handle<String>::cast(key->handle());
2854515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    LookupResult lookup;
2864515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    receiver->Lookup(*name, &lookup);
287402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (!lookup.IsProperty()) {
288402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("Assigned property not found at compile time");
289402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    }
2904515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    if (lookup.holder() != *receiver) BAILOUT("Non-own property assignment");
2914515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    if (!lookup.type() == FIELD) BAILOUT("Non-field property assignment");
2924515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  } else {
2934515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    UNREACHABLE();
2944515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    BAILOUT("Unexpected non-string-literal property key");
2954515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  }
2964515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
297d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  Visit(expr->value());
298eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
299eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
300eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
301d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitThrow(Throw* expr) {
302d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("Throw");
303eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
304eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
305eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
306d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitProperty(Property* expr) {
307402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // We support named this property references.
308402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  VariableProxy* proxy = expr->obj()->AsVariableProxy();
309402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  if (proxy == NULL || !proxy->var()->is_this()) {
310402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    BAILOUT("Non-this-property reference");
311402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
312402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  if (!expr->key()->IsPropertyName()) {
313402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    BAILOUT("Non-named-property reference");
314402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
315402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
316402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // We will only specialize for fields on the object itself.
317402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // Expression::IsPropertyName implies that the name is a literal
318402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // symbol but we do not assume that.
319402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  Literal* key = expr->key()->AsLiteral();
320402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  if (key != NULL && key->handle()->IsString()) {
321402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Handle<Object> receiver = info()->receiver();
322402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Handle<String> name = Handle<String>::cast(key->handle());
323402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    LookupResult lookup;
324402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    receiver->Lookup(*name, &lookup);
325402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (!lookup.IsProperty()) {
326402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("Referenced property not found at compile time");
327402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    }
328402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (lookup.holder() != *receiver) BAILOUT("Non-own property reference");
329402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (!lookup.type() == FIELD) BAILOUT("Non-field property reference");
330402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  } else {
331402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    UNREACHABLE();
332402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    BAILOUT("Unexpected non-string-literal property key");
333402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
334eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
335eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
336eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
337d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitCall(Call* expr) {
338d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("Call");
339d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
340eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
341eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
342d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitCallNew(CallNew* expr) {
343d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("CallNew");
344d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
345eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
346eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
347d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitCallRuntime(CallRuntime* expr) {
348d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("CallRuntime");
349eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
350eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
351eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
352d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitUnaryOperation(UnaryOperation* expr) {
353d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("UnaryOperation");
354eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
355eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
356eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
357d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitCountOperation(CountOperation* expr) {
358d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("CountOperation");
359eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
360eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
361eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
362d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitBinaryOperation(BinaryOperation* expr) {
363402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // We support bitwise OR.
364402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  switch (expr->op()) {
365402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::COMMA:
366402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation COMMA");
367402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::OR:
368402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation OR");
369402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::AND:
370402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation AND");
371402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
372402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::BIT_OR:
373402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      // We support expressions nested on the left because they only require
374402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      // a pair of registers to keep all intermediate values in registers
375402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      // (i.e., the expression stack has height no more than two).
376402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      if (!expr->right()->IsLeaf()) BAILOUT("expression nested on right");
377402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
378402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      // We do not allow subexpressions with side effects because we
379402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      // (currently) bail out to the beginning of the full function.  The
380402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      // only expressions with side effects that we would otherwise handle
381402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      // are assignments.
382402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      if (expr->left()->AsAssignment() != NULL ||
383402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu          expr->right()->AsAssignment() != NULL) {
384402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu        BAILOUT("subexpression of binary operation has side effects");
385402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      }
386402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
387402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      Visit(expr->left());
388402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      CHECK_BAILOUT;
389402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      Visit(expr->right());
390402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      break;
391402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
392402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::BIT_XOR:
393402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation BIT_XOR");
394402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::BIT_AND:
395402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation BIT_AND");
396402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::SHL:
397402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation SHL");
398402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::SAR:
399402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation SAR");
400402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::SHR:
401402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation SHR");
402402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::ADD:
403402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation ADD");
404402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::SUB:
405402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation SUB");
406402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::MUL:
407402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation MUL");
408402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::DIV:
409402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation DIV");
410402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    case Token::MOD:
411402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      BAILOUT("BinaryOperation MOD");
412402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    default:
413402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      UNREACHABLE();
414402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
415eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
416eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
417eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
418d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitCompareOperation(CompareOperation* expr) {
419d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("CompareOperation");
420eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke}
421eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
422eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
423d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarkevoid FastCodeGenSyntaxChecker::VisitThisFunction(ThisFunction* expr) {
424d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  BAILOUT("ThisFunction");
425d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke}
426d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke
427d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke#undef BAILOUT
428d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke#undef CHECK_BAILOUT
429eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
430eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke
4314515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke#define __ ACCESS_MASM(masm())
4324515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuHandle<Code> FastCodeGenerator::MakeCode(CompilationInfo* info) {
4344515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Label the AST before calling MakeCodePrologue, so AST node numbers are
4354515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // printed with the AST.
4364515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  AstLabeler labeler;
4373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  labeler.Label(info);
4384515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
439402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  LivenessAnalyzer analyzer;
440402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  analyzer.Analyze(info->function());
441402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
4423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  CodeGenerator::MakeCodePrologue(info);
4434515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4444515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  const int kInitialBufferSize = 4 * KB;
4454515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  MacroAssembler masm(NULL, kInitialBufferSize);
4464515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4474515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Generate the fast-path code.
4483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  FastCodeGenerator fast_cgen(&masm);
4493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  fast_cgen.Generate(info);
4504515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  if (fast_cgen.HasStackOverflow()) {
4514515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    ASSERT(!Top::has_pending_exception());
4524515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    return Handle<Code>::null();
4534515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  }
4544515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4554515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Generate the full code for the function in bailout mode, using the same
4564515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // macro assembler.
4573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  CodeGenerator cgen(&masm);
4584515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  CodeGeneratorScope scope(&cgen);
459402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  info->set_mode(CompilationInfo::SECONDARY);
460402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  cgen.Generate(info);
4614515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  if (cgen.HasStackOverflow()) {
4624515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    ASSERT(!Top::has_pending_exception());
4634515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    return Handle<Code>::null();
4644515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  }
4654515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4664515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP);
4673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  return CodeGenerator::MakeCodeEpilogue(&masm, flags, info);
4684515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
4694515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4704515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4714515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitDeclaration(Declaration* decl) {
4724515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
4734515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
4744515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4754515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4764515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitBlock(Block* stmt) {
4774515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  VisitStatements(stmt->statements());
4784515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
4794515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4804515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4814515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
4824515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  Visit(stmt->expression());
4834515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
4844515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4854515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4864515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
4874515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Nothing to do.
4884515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
4894515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4904515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4914515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitIfStatement(IfStatement* stmt) {
4924515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
4934515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
4944515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4954515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
4964515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
4974515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
4984515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
4994515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5004515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5014515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
5024515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5034515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5044515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5054515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5064515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
5074515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5084515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5094515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5104515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5114515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) {
5124515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5134515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5144515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5154515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5164515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitWithExitStatement(WithExitStatement* stmt) {
5174515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5184515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5194515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5204515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5214515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
5224515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5234515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5244515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5254515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5264515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
5274515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5284515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5294515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5304515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5314515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
5324515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5334515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5344515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5354515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5364515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitForStatement(ForStatement* stmt) {
5374515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5384515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5394515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5404515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5414515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
5424515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5434515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5444515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5454515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5464515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
5474515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5484515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5494515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5504515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5514515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
5524515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5534515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5544515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5554515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5564515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
5574515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5584515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5594515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5604515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5614515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
5624515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5634515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5644515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5654515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5664515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitFunctionBoilerplateLiteral(
5674515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    FunctionBoilerplateLiteral* expr) {
5684515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5694515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5704515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5714515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5724515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitConditional(Conditional* expr) {
5734515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5744515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5754515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5764515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5774515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitSlot(Slot* expr) {
5784515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
5794515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
5804515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5814515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
5824515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
5834515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  ASSERT(expr->var()->is_global() && !expr->var()->is_this());
5843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  // Check if we can compile a global variable load directly from the cell.
5853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  ASSERT(info()->has_global_object());
5863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  LookupResult lookup;
5873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  info()->global_object()->Lookup(*expr->name(), &lookup);
588402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // We only support normal (non-accessor/interceptor) DontDelete properties
589402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // for now.
590402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  ASSERT(lookup.IsProperty());
591402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  ASSERT_EQ(NORMAL, lookup.type());
5923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  ASSERT(lookup.IsDontDelete());
5933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  Handle<Object> cell(info()->global_object()->GetPropertyCell(&lookup));
594402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
595402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // Global variable lookups do not have side effects, so we do not need to
596402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // emit code if we are in an effect context.
597402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  if (!destination().is(no_reg)) {
598402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Comment cmnt(masm(), ";; Global");
599402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (FLAG_print_ir) {
600402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      SmartPointer<char> name = expr->name()->ToCString();
601402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      PrintF("%d: t%d = Global(%s)  // last_use = %d\n", expr->num(),
602402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu             expr->num(), *name, expr->var_def()->last_use()->num());
603402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    }
604402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    EmitGlobalVariableLoad(cell);
605402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
6064515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6074515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6084515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6094515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitLiteral(Literal* expr) {
6104515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6114515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6124515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6134515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6144515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
6154515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6164515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6174515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6184515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6194515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
6204515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6214515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6224515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6234515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6244515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
6254515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6264515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6274515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6284515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6294515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* expr) {
6304515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6314515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6324515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6334515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6344515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitAssignment(Assignment* expr) {
635402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // Known to be a simple this property assignment.  Effectively a unary
636402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // operation.
637402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  { Register my_destination = destination();
638402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    set_destination(accumulator0());
639402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Visit(expr->value());
640402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    set_destination(my_destination);
641402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
6424515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6434515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  Property* prop = expr->target()->AsProperty();
6444515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  ASSERT_NOT_NULL(prop);
6454515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  ASSERT_NOT_NULL(prop->obj()->AsVariableProxy());
6464515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  ASSERT(prop->obj()->AsVariableProxy()->var()->is_this());
6474515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  ASSERT(prop->key()->IsPropertyName());
6484515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  Handle<String> name =
6494515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke      Handle<String>::cast(prop->key()->AsLiteral()->handle());
6504515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
651402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  Comment cmnt(masm(), ";; Store to this");
6524515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  if (FLAG_print_ir) {
6534515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke    SmartPointer<char> name_string = name->ToCString();
654402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    PrintF("%d: ", expr->num());
655402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (!destination().is(no_reg)) PrintF("t%d = ", expr->num());
656402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    PrintF("Store(this, \"%s\", t%d)  // last_use(this) = %d\n", *name_string,
657402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu           expr->value()->num(),
658402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu           expr->var_def()->last_use()->num());
6594515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  }
6604515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6614515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  EmitThisPropertyStore(name);
6624515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6634515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6644515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6654515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitThrow(Throw* expr) {
6664515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6674515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6684515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6694515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6704515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitProperty(Property* expr) {
671402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  ASSERT_NOT_NULL(expr->obj()->AsVariableProxy());
672402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  ASSERT(expr->obj()->AsVariableProxy()->var()->is_this());
673402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  ASSERT(expr->key()->IsPropertyName());
674402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  if (!destination().is(no_reg)) {
675402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Handle<String> name =
676402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu        Handle<String>::cast(expr->key()->AsLiteral()->handle());
677402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
678402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Comment cmnt(masm(), ";; Load from this");
679402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (FLAG_print_ir) {
680402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      SmartPointer<char> name_string = name->ToCString();
681402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu      PrintF("%d: t%d = Load(this, \"%s\")  // last_use(this) = %d\n",
682402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu             expr->num(), expr->num(), *name_string,
683402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu             expr->var_def()->last_use()->num());
684402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    }
685402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    EmitThisPropertyLoad(name);
686402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
6874515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6884515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6894515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6904515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitCall(Call* expr) {
6914515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6924515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6934515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6944515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6954515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitCallNew(CallNew* expr) {
6964515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
6974515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
6984515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
6994515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7004515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
7014515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
7024515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
7034515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7044515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7054515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
7064515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
7074515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
7084515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7094515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7104515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
7114515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
7124515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
7134515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7144515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7154515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
716402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // We support limited binary operations: bitwise OR only allowed to be
717402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // nested on the left.
718402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  ASSERT(expr->op() == Token::BIT_OR);
719402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  ASSERT(expr->right()->IsLeaf());
720402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
721402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  { Register my_destination = destination();
722402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    set_destination(accumulator1());
723402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Visit(expr->left());
724402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    set_destination(accumulator0());
725402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    Visit(expr->right());
726402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    set_destination(my_destination);
727402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
728402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
729402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  Comment cmnt(masm(), ";; BIT_OR");
730402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  if (FLAG_print_ir) {
731402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    PrintF("%d: ", expr->num());
732402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    if (!destination().is(no_reg)) PrintF("t%d = ", expr->num());
733402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu    PrintF("BIT_OR(t%d, t%d)\n", expr->left()->num(), expr->right()->num());
734402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  }
735402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  EmitBitOr();
7364515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
7374515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7384515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7394515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
7404515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
7414515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
7424515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7434515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7444515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevoid FastCodeGenerator::VisitThisFunction(ThisFunction* expr) {
7454515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  UNREACHABLE();
7464515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}
7474515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7484515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke#undef __
7494515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
7504515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
751eab96aab0834f21954b5d6aa6366bcfb348ed811Leon Clarke} }  // namespace v8::internal
752