diff options
Diffstat (limited to 'Source/JavaScriptCore/bytecompiler')
4 files changed, 34 insertions, 19 deletions
diff --git a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp index 6fa0ce96b..4a6f4653e 100644 --- a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp +++ b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp @@ -119,6 +119,15 @@ namespace JSC { expected by the callee. */ +void Label::setLocation(unsigned location) +{ + m_location = location; + + unsigned size = m_unresolvedJumps.size(); + for (unsigned i = 0; i < size; ++i) + m_generator->m_instructions[m_unresolvedJumps[i].second].u.operand = m_location - m_unresolvedJumps[i].first; +} + #ifndef NDEBUG void ResolveResult::checkValidity() { @@ -171,8 +180,8 @@ JSObject* BytecodeGenerator::generate() m_codeBlock->setThisRegister(m_thisRegister.index()); m_scopeNode->emitBytecode(*this); - - m_codeBlock->setInstructionCount(m_codeBlock->instructions().size()); + + m_codeBlock->instructions() = RefCountedArray<Instruction>(m_instructions); if (s_dumpsGeneratedCode) m_codeBlock->dump(m_scopeChain->globalObject->globalExec()); @@ -607,7 +616,7 @@ PassRefPtr<Label> BytecodeGenerator::newLabel() m_labels.removeLast(); // Allocate new label ID. - m_labels.append(m_codeBlock); + m_labels.append(this); return &m_labels.last(); } diff --git a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h index d61b42b76..e7fe236e5 100644 --- a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h +++ b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h @@ -32,7 +32,7 @@ #define BytecodeGenerator_h #include "CodeBlock.h" -#include "HashTraits.h" +#include <wtf/HashTraits.h> #include "Instruction.h" #include "Label.h" #include "LabelScope.h" @@ -48,6 +48,7 @@ namespace JSC { class Identifier; + class Label; class ScopeChainNode; class CallArguments { @@ -532,6 +533,8 @@ namespace JSC { ScopeChainNode* scopeChain() const { return m_scopeChain.get(); } private: + friend class Label; + void emitOpcode(OpcodeID); ValueProfile* emitProfiledOpcode(OpcodeID); void retrieveLastBinaryOp(int& dstIndex, int& src1Index, int& src2Index); @@ -611,7 +614,7 @@ namespace JSC { RegisterID* emitInitLazyRegister(RegisterID*); - Vector<Instruction>& instructions() { return m_codeBlock->instructions(); } + Vector<Instruction>& instructions() { return m_instructions; } SymbolTable& symbolTable() { return *m_symbolTable; } bool shouldOptimizeLocals() @@ -644,6 +647,8 @@ namespace JSC { void createArgumentsIfNecessary(); void createActivationIfNecessary(); RegisterID* createLazyRegisterIfNecessary(RegisterID*); + + Vector<Instruction> m_instructions; bool m_shouldEmitDebugHooks; bool m_shouldEmitProfileHooks; diff --git a/Source/JavaScriptCore/bytecompiler/Label.h b/Source/JavaScriptCore/bytecompiler/Label.h index 8cab1dbc0..21fa46309 100644 --- a/Source/JavaScriptCore/bytecompiler/Label.h +++ b/Source/JavaScriptCore/bytecompiler/Label.h @@ -39,21 +39,14 @@ namespace JSC { class Label { public: - explicit Label(CodeBlock* codeBlock) + explicit Label(BytecodeGenerator* generator) : m_refCount(0) , m_location(invalidLocation) - , m_codeBlock(codeBlock) + , m_generator(generator) { } - void setLocation(unsigned location) - { - m_location = location; - - unsigned size = m_unresolvedJumps.size(); - for (unsigned i = 0; i < size; ++i) - m_codeBlock->instructions()[m_unresolvedJumps[i].second].u.operand = m_location - m_unresolvedJumps[i].first; - } + void setLocation(unsigned); int bind(int opcode, int offset) const { @@ -81,7 +74,7 @@ namespace JSC { int m_refCount; unsigned m_location; - CodeBlock* m_codeBlock; + BytecodeGenerator* m_generator; mutable JumpVector m_unresolvedJumps; }; diff --git a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp index 2d4181912..bb95cafb6 100644 --- a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp +++ b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp @@ -871,7 +871,15 @@ RegisterID* UnaryOpNode::emitBytecode(BytecodeGenerator& generator, RegisterID* return generator.emitUnaryOp(opcodeID(), generator.finalDestination(dst), src); } - +// ------------------------------ BitwiseNotNode ----------------------------------- + +RegisterID* BitwiseNotNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) +{ + RefPtr<RegisterID> src2 = generator.emitLoad(generator.newTemporary(), jsNumber(-1)); + RegisterID* src1 = generator.emitNode(m_expr); + return generator.emitBinaryOp(op_bitxor, generator.finalDestination(dst, src1), src1, src2.get(), OperandTypes(m_expr->resultDescriptor(), ResultType::numberTypeIsInt32())); +} + // ------------------------------ LogicalNotNode ----------------------------------- void LogicalNotNode::emitBytecodeInConditionContext(BytecodeGenerator& generator, Label* trueTarget, Label* falseTarget, bool fallThroughMeansTrue) @@ -2009,8 +2017,8 @@ RegisterID* TryNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) inline void ScopeNode::emitStatementsBytecode(BytecodeGenerator& generator, RegisterID* dst) { - if (m_data->m_statements) - m_data->m_statements->emitBytecode(generator, dst); + if (m_statements) + m_statements->emitBytecode(generator, dst); } // ------------------------------ ProgramNode ----------------------------- |