Changeset 45609 in webkit for trunk/JavaScriptCore/bytecompiler
- Timestamp:
- Jul 7, 2009, 2:52:07 PM (16 years ago)
- Location:
- trunk/JavaScriptCore/bytecompiler
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r44711 r45609 197 197 } 198 198 199 void BytecodeGenerator::allocateConstants(size_t count) 200 { 201 m_codeBlock->m_numConstants = count; 202 if (!count) 203 return; 204 205 m_nextConstantIndex = m_calleeRegisters.size(); 206 207 for (size_t i = 0; i < count; ++i) 208 newRegister(); 209 m_lastConstant = &m_calleeRegisters.last(); 199 void BytecodeGenerator::preserveLastVar() 200 { 201 if ((m_firstConstantIndex = m_calleeRegisters.size()) != 0) 202 m_lastVar = &m_calleeRegisters.last(); 210 203 } 211 204 … … 223 216 , m_codeType(GlobalCode) 224 217 , m_nextGlobalIndex(-1) 218 , m_nextConstantOffset(0) 225 219 , m_globalConstantIndex(0) 226 220 , m_globalData(&scopeChain.globalObject()->globalExec()->globalData()) … … 273 267 newVars.append(addGlobalVar(varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant)); 274 268 275 allocateConstants(programNode->neededConstants());269 preserveLastVar(); 276 270 277 271 for (size_t i = 0; i < newVars.size(); ++i) … … 291 285 } 292 286 293 allocateConstants(programNode->neededConstants());287 preserveLastVar(); 294 288 } 295 289 } … … 306 300 , m_baseScopeDepth(0) 307 301 , m_codeType(FunctionCode) 302 , m_nextConstantOffset(0) 308 303 , m_globalConstantIndex(0) 309 304 , m_globalData(&scopeChain.globalObject()->globalExec()->globalData()) … … 373 368 addParameter(parameters[i]); 374 369 375 allocateConstants(functionBody->neededConstants());370 preserveLastVar(); 376 371 } 377 372 … … 388 383 , m_baseScopeDepth(codeBlock->baseScopeDepth()) 389 384 , m_codeType(EvalCode) 385 , m_nextConstantOffset(0) 390 386 , m_globalConstantIndex(0) 391 387 , m_globalData(&scopeChain.globalObject()->globalExec()->globalData()) … … 402 398 m_codeBlock->m_numParameters = 1; // Allocate space for "this" 403 399 404 allocateConstants(evalNode->neededConstants());400 preserveLastVar(); 405 401 } 406 402 … … 792 788 } 793 789 794 RegisterID* BytecodeGenerator::addConstant(JSValue v) 795 { 796 pair<JSValueMap::iterator, bool> result = m_jsValueMap.add(JSValue::encode(v), m_nextConstantIndex); 790 RegisterID* BytecodeGenerator::addConstantValue(JSValue v) 791 { 792 int index = m_nextConstantOffset; 793 794 pair<JSValueMap::iterator, bool> result = m_jsValueMap.add(JSValue::encode(v), m_nextConstantOffset); 797 795 if (result.second) { 798 RegisterID& constant = m_calleeRegisters[m_nextConstantIndex]; 799 800 ++m_nextConstantIndex; 801 796 m_constantPoolRegisters.append(FirstConstantRegisterIndex + m_nextConstantOffset); 797 ++m_nextConstantOffset; 802 798 m_codeBlock->addConstantRegister(JSValue(v)); 803 return &constant; 804 } 805 806 return ®isterFor(result.first->second); 807 } 808 809 unsigned BytecodeGenerator::addUnexpectedConstant(JSValue v) 810 { 811 return m_codeBlock->addUnexpectedConstant(v); 812 } 813 814 RegisterID* BytecodeGenerator::emitLoadGlobalObject(RegisterID* dst, JSObject* globalObject) 815 { 816 if (!m_globalConstantIndex) 817 m_globalConstantIndex = m_codeBlock->addUnexpectedConstant(globalObject); 818 emitOpcode(op_unexpected_load); 819 instructions().append(dst->index()); 820 instructions().append(m_globalConstantIndex); 821 return dst; 799 } else 800 index = result.first->second; 801 802 return &m_constantPoolRegisters[index]; 822 803 } 823 804 … … 899 880 && src1->isTemporary() 900 881 && m_codeBlock->isConstantRegisterIndex(src2->index()) 901 && m_codeBlock->constantRegister(src2->index() - m_codeBlock->m_numVars).jsValue().isString()) {902 const UString& value = asString(m_codeBlock->constantRegister(src2->index() - m_codeBlock->m_numVars).jsValue())->value();882 && m_codeBlock->constantRegister(src2->index()).jsValue().isString()) { 883 const UString& value = asString(m_codeBlock->constantRegister(src2->index()).jsValue())->value(); 903 884 if (value == "undefined") { 904 885 rewindUnaryOp(); … … 980 961 RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, JSValue v) 981 962 { 982 RegisterID* constantID = addConstant (v);963 RegisterID* constantID = addConstantValue(v); 983 964 if (dst) 984 965 return emitMove(dst, constantID); 985 966 return constantID; 986 }987 988 RegisterID* BytecodeGenerator::emitUnexpectedLoad(RegisterID* dst, bool b)989 {990 emitOpcode(op_unexpected_load);991 instructions().append(dst->index());992 instructions().append(addUnexpectedConstant(jsBoolean(b)));993 return dst;994 }995 996 RegisterID* BytecodeGenerator::emitUnexpectedLoad(RegisterID* dst, double d)997 {998 emitOpcode(op_unexpected_load);999 instructions().append(dst->index());1000 instructions().append(addUnexpectedConstant(jsNumber(globalData(), d)));1001 return dst;1002 967 } 1003 968 … … 1170 1135 1171 1136 // Global object is the base 1172 return emitLoad GlobalObject(dst, globalObject);1137 return emitLoad(dst, JSValue(globalObject)); 1173 1138 } 1174 1139 … … 1197 1162 1198 1163 // Global object is the base 1199 emitLoad GlobalObject(baseDst, globalObject);1164 emitLoad(baseDst, JSValue(globalObject)); 1200 1165 1201 1166 if (index != missingSymbolMarker() && !forceGlobalResolve) { … … 1832 1797 instructions().append(dst->index()); 1833 1798 instructions().append(static_cast<int>(type)); 1834 instructions().append(add UnexpectedConstant(message));1799 instructions().append(addConstantValue(message)->index()); 1835 1800 return dst; 1836 1801 } -
trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r45128 r45609 246 246 RegisterID* emitLoad(RegisterID* dst, const Identifier&); 247 247 RegisterID* emitLoad(RegisterID* dst, JSValue); 248 RegisterID* emitUnexpectedLoad(RegisterID* dst, bool);249 RegisterID* emitUnexpectedLoad(RegisterID* dst, double);250 RegisterID* emitLoadGlobalObject(RegisterID* dst, JSObject* globalObject);251 248 252 249 RegisterID* emitUnaryOp(OpcodeID, RegisterID* dst, RegisterID* src); … … 400 397 RegisterID* addParameter(const Identifier&); 401 398 402 void allocateConstants(size_t);399 void preserveLastVar(); 403 400 404 401 RegisterID& registerFor(int index) … … 421 418 unsigned addConstant(FuncExprNode*); 422 419 unsigned addConstant(const Identifier&); 423 RegisterID* addConstant(JSValue); 424 unsigned addUnexpectedConstant(JSValue); 420 RegisterID* addConstantValue(JSValue); 425 421 unsigned addRegExp(RegExp*); 426 422 … … 451 447 RegisterID m_argumentsRegister; 452 448 int m_activationRegisterIndex; 449 WTF::SegmentedVector<RegisterID, 32> m_constantPoolRegisters; 453 450 WTF::SegmentedVector<RegisterID, 32> m_calleeRegisters; 454 451 WTF::SegmentedVector<RegisterID, 32> m_parameters; … … 456 453 WTF::SegmentedVector<Label, 32> m_labels; 457 454 WTF::SegmentedVector<LabelScope, 8> m_labelScopes; 458 RefPtr<RegisterID> m_last Constant;455 RefPtr<RegisterID> m_lastVar; 459 456 int m_finallyDepth; 460 457 int m_dynamicScopeDepth; … … 467 464 int m_nextGlobalIndex; 468 465 int m_nextParameterIndex; 469 int m_nextConstantIndex; 466 int m_firstConstantIndex; 467 int m_nextConstantOffset; 470 468 unsigned m_globalConstantIndex; 471 469
Note:
See TracChangeset
for help on using the changeset viewer.