Changeset 34838 in webkit for trunk/JavaScriptCore/VM/CodeGenerator.cpp
- Timestamp:
- Jun 27, 2008, 3:35:33 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/CodeGenerator.cpp
r34784 r34838 149 149 } 150 150 151 bool CodeGenerator::addVar(const Identifier& ident, RegisterID*& r0, bool isConstant)151 bool CodeGenerator::addVar(const Identifier& ident, bool isConstant, RegisterID*& r0) 152 152 { 153 153 int index = m_nextVar; … … 168 168 } 169 169 170 CodeGenerator::CodeGenerator(ProgramNode* programNode, const Debugger* debugger, const ScopeChain& scopeChain, SymbolTable* symbolTable, CodeBlock* codeBlock, VarStack& varStack, FunctionStack& functionStack, bool canCreateVariables) 170 bool CodeGenerator::addGlobalVar(const Identifier& ident, bool isConstant, RegisterID*& r0) 171 { 172 int index = m_nextVar; 173 SymbolTableEntry newEntry(index, isConstant ? ReadOnly : 0); 174 pair<SymbolTable::iterator, bool> result = symbolTable().add(ident.ustring().rep(), newEntry); 175 176 if (!result.second) 177 index = result.first->second.getIndex(); 178 else { 179 --m_nextVar; 180 m_locals.append(index + m_globalVarStorageOffset); 181 } 182 183 r0 = &m_locals[localsIndex(index)]; 184 return result.second; 185 } 186 187 CodeGenerator::CodeGenerator(ProgramNode* programNode, const Debugger* debugger, const ScopeChain& scopeChain, SymbolTable* symbolTable, CodeBlock* codeBlock, VarStack& varStack, FunctionStack& functionStack) 171 188 : m_shouldEmitDebugHooks(!!debugger) 172 189 , m_scopeChain(&scopeChain) … … 174 191 , m_scopeNode(programNode) 175 192 , m_codeBlock(codeBlock) 176 , m_thisRegister( Machine::ProgramCodeThisRegister)193 , m_thisRegister(RegisterFile::ProgramCodeThisRegister) 177 194 , m_finallyDepth(0) 178 195 , m_dynamicScopeDepth(0) … … 183 200 , m_lastOpcodeID(op_end) 184 201 { 185 // Global code can inherit previously defined symbols. 186 int size = symbolTable->size() + 1; // + 1 slot for "this" 202 // FIXME: Move code that modifies the global object to Machine::execute. 203 204 m_codeBlock->numVars = 1; // Allocate space for "this" 205 206 JSGlobalObject* globalObject = scopeChain.globalObject(); 207 ExecState* exec = globalObject->globalExec(); 208 RegisterFile* registerFile = &exec->globalData().machine->registerFile(); 209 210 // Shift register indexes in generated code to elide registers allocated by intermediate stack frames. 211 m_globalVarStorageOffset = -1 - RegisterFile::CallFrameHeaderSize - registerFile->size(); 187 212 188 213 // Add previously defined symbols to bookkeeping. 189 m_locals.resize(s ize);214 m_locals.resize(symbolTable->size()); 190 215 SymbolTable::iterator end = symbolTable->end(); 191 216 for (SymbolTable::iterator it = symbolTable->begin(); it != end; ++it) 192 m_locals[localsIndex(it->second.getIndex())].setIndex(it->second.getIndex()); 193 194 // Shift new symbols so they get stored prior to previously defined symbols. 195 m_nextVar -= size; 196 197 JSGlobalObject* globalObject = scopeChain.globalObject(); 198 199 ExecState* exec = globalObject->globalExec(); 200 201 // FIXME: Move the execution-related parts of this code to Machine::execute. 202 203 if (canCreateVariables) { 217 m_locals[localsIndex(it->second.getIndex())].setIndex(it->second.getIndex() + m_globalVarStorageOffset); 218 219 bool canOptimizeNewGlobals = symbolTable->size() + functionStack.size() + varStack.size() < registerFile->maxGlobals(); 220 if (canOptimizeNewGlobals) { 221 // Shift new symbols so they get stored prior to existing symbols. 222 m_nextVar -= symbolTable->size(); 223 204 224 for (size_t i = 0; i < functionStack.size(); ++i) { 205 225 FuncDeclNode* funcDecl = functionStack[i].get(); 206 226 globalObject->removeDirect(funcDecl->m_ident); // Make sure our new function is not shadowed by an old property. 207 emitNewFunction(add Var(funcDecl->m_ident, false), funcDecl);227 emitNewFunction(addGlobalVar(funcDecl->m_ident, false), funcDecl); 208 228 } 209 229 210 230 for (size_t i = 0; i < varStack.size(); ++i) { 211 231 if (!globalObject->hasProperty(exec, varStack[i].first)) 212 emitLoad(add Var(varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant), jsUndefined());232 emitLoad(addGlobalVar(varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant), jsUndefined()); 213 233 } 214 234 } else { … … 256 276 if (ident == propertyNames().arguments) 257 277 continue; 258 259 RegisterID* r0; 260 addVar(ident, r0, varStack[i].second & DeclarationStacks::IsConstant); 278 addVar(ident, varStack[i].second & DeclarationStacks::IsConstant); 261 279 } 262 280 … … 280 298 , m_scopeNode(evalNode) 281 299 , m_codeBlock(codeBlock) 282 , m_thisRegister( Machine::ProgramCodeThisRegister)300 , m_thisRegister(RegisterFile::ProgramCodeThisRegister) 283 301 , m_finallyDepth(0) 284 302 , m_dynamicScopeDepth(0) 285 303 , m_codeType(EvalCode) 286 304 , m_continueDepth(0) 287 , m_nextVar(-1)288 305 , m_globalData(&scopeChain.globalObject()->globalExec()->globalData()) 289 306 , m_lastOpcodeID(op_end) … … 817 834 818 835 // Reserve space for call frame. 819 Vector<RefPtr<RegisterID>, Machine::CallFrameHeaderSize> callFrame;820 for (int i = 0; i < Machine::CallFrameHeaderSize; ++i)836 Vector<RefPtr<RegisterID>, RegisterFile::CallFrameHeaderSize> callFrame; 837 for (int i = 0; i < RegisterFile::CallFrameHeaderSize; ++i) 821 838 callFrame.append(newTemporary()); 822 839 … … 848 865 { 849 866 // Reserve space for call frame. 850 Vector<RefPtr<RegisterID>, Machine::CallFrameHeaderSize> callFrame;851 for (int i = 0; i < Machine::CallFrameHeaderSize; ++i)867 Vector<RefPtr<RegisterID>, RegisterFile::CallFrameHeaderSize> callFrame; 868 for (int i = 0; i < RegisterFile::CallFrameHeaderSize; ++i) 852 869 callFrame.append(newTemporary()); 853 870
Note:
See TracChangeset
for help on using the changeset viewer.