WebKit Bugzilla
Attachment 345812 Details for
Bug 187373
: New bytecode format for JSC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-187373-20180725232057.patch (text/plain), 140.13 KB, created by
Tadeu Zagallo
on 2018-07-25 19:21:00 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Tadeu Zagallo
Created:
2018-07-25 19:21:00 PDT
Size:
140.13 KB
patch
obsolete
>Subversion Revision: 234092 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index ef79ffda4221f29db15ccadf6d983a72b0d87a86..ec2e4fef865dc31a635711d09568bbe54b4caddd 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,25 @@ >+2018-07-05 Tadeu Zagallo <tzagallo@apple.com> >+ >+ New bytecode format for JSC >+ https://bugs.webkit.org/show_bug.cgi?id=187373 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Work in progress for the new bytecode format. For now, there's just a >+ handful of docs that I've experimenting with as to how should we >+ declare the opcodes, how should we generate the code and what the >+ generated code should look like. >+ >+ * wip_bytecode/README.md: Briefly documents the goals of for the new >+ bytecode and how it's going work. Still missing a lot of info though. >+ * wip_bytecode/bytecode_generator.rb: Some hacky ruby that I'm >+ considering using for the generating the C++ code for the opcodes >+ * wip_bytecode/bytecode_structs.cpp: Some hacky C++ experiments of >+ what could/should the API for the generated opcodes look like. >+ * wip_bytecode/opcodes.yaml: A list of all the opcodes, with names and >+ types for its arguments and metadata. No idea why it ended up being a >+ yaml file, but if all is well I'll migrate it to the ruby syntax above. >+ > 2018-07-22 Yusuke Suzuki <utatane.tea@gmail.com> > > [JSC] GetByIdVariant and InByIdVariant do not need slot base if they are not "hit" variants >diff --git a/Source/JavaScriptCore/bytecode/CodeBlock.cpp b/Source/JavaScriptCore/bytecode/CodeBlock.cpp >index d051ab37da10f70fde0fff97f37d201033ab7310..510c6323ce2e86a6904fb0ebd1db715851aaf130 100644 >--- a/Source/JavaScriptCore/bytecode/CodeBlock.cpp >+++ b/Source/JavaScriptCore/bytecode/CodeBlock.cpp >@@ -542,7 +542,7 @@ bool CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, Unlink > > unsigned opLength = opcodeLength(pc[0].u.opcode); > >- instructions[i] = Interpreter::getOpcode(pc[0].u.opcode); >+ instructions[i] = pc[0].u.opcode; > for (size_t j = 1; j < opLength; ++j) { > if (sizeof(int32_t) != sizeof(intptr_t)) > instructions[i + j].u.pointer = 0; >@@ -1132,7 +1132,7 @@ void CodeBlock::propagateTransitions(const ConcurrentJSLocker&, SlotVisitor& vis > const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions(); > for (size_t i = 0; i < propertyAccessInstructions.size(); ++i) { > Instruction* instruction = &instructions()[propertyAccessInstructions[i]]; >- switch (Interpreter::getOpcodeID(instruction[0])) { >+ switch (instruction[0].u.opcode) { > case op_put_by_id: { > StructureID oldStructureID = instruction[4].u.structureID; > StructureID newStructureID = instruction[6].u.structureID; >@@ -1245,7 +1245,7 @@ void CodeBlock::determineLiveness(const ConcurrentJSLocker&, SlotVisitor& visito > > void CodeBlock::clearLLIntGetByIdCache(Instruction* instruction) > { >- instruction[0].u.opcode = LLInt::getOpcode(op_get_by_id); >+ instruction[0].u.opcode = op_get_by_id; > instruction[4].u.pointer = nullptr; > instruction[5].u.pointer = nullptr; > instruction[6].u.pointer = nullptr; >@@ -1257,7 +1257,7 @@ void CodeBlock::finalizeLLIntInlineCaches() > const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions(); > for (size_t size = propertyAccessInstructions.size(), i = 0; i < size; ++i) { > Instruction* curInstruction = &instructions()[propertyAccessInstructions[i]]; >- switch (Interpreter::getOpcodeID(curInstruction[0])) { >+ switch (curInstruction[0].u.opcode) { > case op_get_by_id: { > StructureID oldStructureID = curInstruction[4].u.structureID; > if (!oldStructureID || Heap::isMarked(vm.heap.structureIDTable().get(oldStructureID))) >@@ -1349,7 +1349,7 @@ void CodeBlock::finalizeLLIntInlineCaches() > break; > } > default: >- OpcodeID opcodeID = Interpreter::getOpcodeID(curInstruction[0]); >+ OpcodeID opcodeID = curInstruction[0].u.opcode; > ASSERT_WITH_MESSAGE_UNUSED(opcodeID, false, "Unhandled opcode in CodeBlock::finalizeUnconditionally, %s(%d) at bc %u", opcodeNames[opcodeID], opcodeID, propertyAccessInstructions[i]); > } > } >@@ -1359,7 +1359,7 @@ void CodeBlock::finalizeLLIntInlineCaches() > m_llintGetByIdWatchpointMap.removeIf([&] (const StructureWatchpointMap::KeyValuePairType& pair) -> bool { > auto clear = [&] () { > Instruction* instruction = std::get<1>(pair.key); >- OpcodeID opcode = Interpreter::getOpcodeID(*instruction); >+ OpcodeID opcode = instruction->u.opcode; > if (opcode == op_get_by_id_proto_load || opcode == op_get_by_id_unset) { > if (Options::verboseOSR()) > dataLogF("Clearing LLInt property access.\n"); >@@ -1695,7 +1695,7 @@ CallSiteIndex CodeBlock::newExceptionHandlingCallSiteIndex(CallSiteIndex origina > > void CodeBlock::ensureCatchLivenessIsComputedForBytecodeOffsetSlow(unsigned bytecodeOffset) > { >- ASSERT(Interpreter::getOpcodeID(m_instructions[bytecodeOffset]) == op_catch); >+ ASSERT(m_instructions[bytecodeOffset].u.opcode == op_catch); > BytecodeLivenessAnalysis& bytecodeLiveness = livenessAnalysis(); > > // We get the live-out set of variables at op_catch, not the live-in. This >diff --git a/Source/JavaScriptCore/bytecode/Instruction.h b/Source/JavaScriptCore/bytecode/Instruction.h >index c133578b3263d3029845e48379a35960704a6efd..da9cedca8c64ce414ab7c5dd21fe6d47f01c7cff 100644 >--- a/Source/JavaScriptCore/bytecode/Instruction.h >+++ b/Source/JavaScriptCore/bytecode/Instruction.h >@@ -60,7 +60,7 @@ struct Instruction { > { > } > >- Instruction(Opcode opcode) >+ explicit Instruction(OpcodeID opcode) > { > #if !ENABLE(COMPUTED_GOTO_OPCODES) > // We have to initialize one of the pointer members to ensure that >@@ -120,7 +120,7 @@ struct Instruction { > > union { > void* pointer; >- Opcode opcode; >+ OpcodeID opcode; > int operand; > unsigned unsignedValue; > WriteBarrierBase<Structure> structure; >diff --git a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp >index 00afc9f96c2a95c17735f1634cbe70576cac3d17..e18e98a109172aa8adf111494b21c042db25038d 100644 >--- a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp >+++ b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp >@@ -159,10 +159,7 @@ ParserError BytecodeGenerator::generate() > > for (auto& tuple : m_catchesToEmit) { > Ref<Label> realCatchTarget = newEmittedLabel(); >- emitOpcode(op_catch); >- instructions().append(std::get<1>(tuple)); >- instructions().append(std::get<2>(tuple)); >- instructions().append(0); >+ OpCatch::emit(this, std::get<1>(tuple), std::get<2>(tuple)); > > TryData* tryData = std::get<0>(tuple); > emitJump(tryData->target.get()); >@@ -448,20 +445,12 @@ BytecodeGenerator::BytecodeGenerator(VM& vm, FunctionNode* functionNode, Unlinke > entry.disableWatching(*m_vm); > functionSymbolTable->set(NoLockingNecessary, name, entry); > } >- emitOpcode(op_put_to_scope); >- instructions().append(m_lexicalEnvironmentRegister->index()); >- instructions().append(UINT_MAX); >- instructions().append(virtualRegisterForArgument(1 + i).offset()); >- instructions().append(GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization).operand()); >- instructions().append(symbolTableConstantIndex); >- instructions().append(offset.offset()); >+ OpPutToScope::emit(this, m_lexicalEnvironmentRegister->index(), UINT_MAX, virtualRegisterForArgument(1 + i), GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization).operand(), symbolTableConstantIndex, offset); > } > > // This creates a scoped arguments object and copies the overflow arguments into the > // scope. It's the equivalent of calling ScopedArguments::createByCopying(). >- emitOpcode(op_create_scoped_arguments); >- instructions().append(m_argumentsRegister->index()); >- instructions().append(m_lexicalEnvironmentRegister->index()); >+ OpCreateScopedArguments::emit(this, m_argumentsRegister, m_lexicalEnvironmentRegister); > } else { > // We're going to put all parameters into the DirectArguments object. First ensure > // that the symbol table knows that this is happening. >@@ -470,8 +459,7 @@ BytecodeGenerator::BytecodeGenerator(VM& vm, FunctionNode* functionNode, Unlinke > functionSymbolTable->set(NoLockingNecessary, name, SymbolTableEntry(VarOffset(DirectArgumentsOffset(i)))); > } > >- emitOpcode(op_create_direct_arguments); >- instructions().append(m_argumentsRegister->index()); >+ OpCreateDirectArgument::emit(this, m_argumentsRegister); > } > } else if (isSimpleParameterList) { > // Create the formal parameters the normal way. Any of them could be captured, or not. If >@@ -495,20 +483,13 @@ BytecodeGenerator::BytecodeGenerator(VM& vm, FunctionNode* functionNode, Unlinke > static_cast<const BindingNode*>(parameters.at(i).first)->boundProperty(); > functionSymbolTable->set(NoLockingNecessary, name, SymbolTableEntry(VarOffset(offset))); > >- emitOpcode(op_put_to_scope); >- instructions().append(m_lexicalEnvironmentRegister->index()); >- instructions().append(addConstant(ident)); >- instructions().append(virtualRegisterForArgument(1 + i).offset()); >- instructions().append(GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization).operand()); >- instructions().append(symbolTableConstantIndex); >- instructions().append(offset.offset()); >+ OpPutToScope::emit(this, m_lexicalEnvironmentRegister, addConstant(ident), virtualRegisterForArgument(1 + i), GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), symbolTableConstantIndex, offset); > } > } > > if (needsArguments && (codeBlock->isStrictMode() || !isSimpleParameterList)) { > // Allocate a cloned arguments object. >- emitOpcode(op_create_cloned_arguments); >- instructions().append(m_argumentsRegister->index()); >+ OpCreateClonedArguments::emit(this, m_argumentsRegister); > } > > // There are some variables that need to be preinitialized to something other than Undefined: >@@ -1165,15 +1146,9 @@ void BytecodeGenerator::initializeVarLexicalEnvironment(int symbolTableConstantI > { > if (hasCapturedVariables) { > RELEASE_ASSERT(m_lexicalEnvironmentRegister); >- emitOpcode(op_create_lexical_environment); >- instructions().append(m_lexicalEnvironmentRegister->index()); >- instructions().append(scopeRegister()->index()); >- instructions().append(symbolTableConstantIndex); >- instructions().append(addConstantValue(jsUndefined())->index()); >+ OpCreateLexicalEnvironment::emit(this, m_lexicalEnvironmentRegister->index(), scopeRegister(), symbolTableConstantIndex, addConstantValue(jsUndefined())); > >- emitOpcode(op_mov); >- instructions().append(scopeRegister()->index()); >- instructions().append(m_lexicalEnvironmentRegister->index()); >+ OpMov::emit(this, scopeRegister(), m_lexicalEnvironmentRegister); > > pushLocalControlFlowScope(); > } >@@ -1267,14 +1242,14 @@ void BytecodeGenerator::emitLabel(Label& l0) > m_lastOpcodeID = op_end; > } > >-void BytecodeGenerator::emitOpcode(OpcodeID opcodeID) >+void BytecodeGenerator::recordOpcode(OpcodeID opcodeID) > { > #ifndef NDEBUG > size_t opcodePosition = instructions().size(); > ASSERT(opcodePosition - m_lastOpcodePosition == opcodeLength(m_lastOpcodeID) || m_lastOpcodeID == op_end); > m_lastOpcodePosition = opcodePosition; > #endif >- instructions().append(opcodeID); >+ m_lastOffset = instructions.size(); > m_lastOpcodeID = opcodeID; > } > >@@ -1293,18 +1268,9 @@ UnlinkedObjectAllocationProfile BytecodeGenerator::newObjectAllocationProfile() > return m_codeBlock->addObjectAllocationProfile(); > } > >-UnlinkedValueProfile BytecodeGenerator::emitProfiledOpcode(OpcodeID opcodeID) >-{ >- emitOpcode(opcodeID); >- if (!m_vm->canUseJIT()) >- return static_cast<UnlinkedValueProfile>(-1); >- UnlinkedValueProfile result = m_codeBlock->addValueProfile(); >- return result; >-} >- > void BytecodeGenerator::emitEnter() > { >- emitOpcode(op_enter); >+ OpEnter::emit(this); > > if (LIKELY(Options::optimizeRecursiveTailCalls())) { > // We must add the end of op_enter as a potential jump target, because the bytecode parser may decide to split its basic block >@@ -1317,22 +1283,24 @@ void BytecodeGenerator::emitEnter() > > void BytecodeGenerator::emitLoopHint() > { >- emitOpcode(op_loop_hint); >+ OpLoopHint::emit(this); > emitCheckTraps(); > } > > void BytecodeGenerator::emitCheckTraps() > { >- emitOpcode(op_check_traps); >+ OpCheckTraps::emit(this); > } > > void BytecodeGenerator::retrieveLastBinaryOp(int& dstIndex, int& src1Index, int& src2Index) > { > ASSERT(instructions().size() >= 4); > size_t size = instructions().size(); >- dstIndex = instructions().at(size - 3).u.operand; >- src1Index = instructions().at(size - 2).u.operand; >- src2Index = instructions().at(size - 1).u.operand; >+ >+ auto instr = reinterpret_cast<Instruction*>(instructions().data() + m_lastOffset)->as<BinaryOp>(); >+ dst = instr->dst(); >+ src1Index = instr->lhs(); >+ src2Index = instr->rhs(); > } > > void BytecodeGenerator::retrieveLastUnaryOp(int& dstIndex, int& srcIndex) >@@ -1359,9 +1327,7 @@ void ALWAYS_INLINE BytecodeGenerator::rewindUnaryOp() > > void BytecodeGenerator::emitJump(Label& target) > { >- size_t begin = instructions().size(); >- emitOpcode(op_jmp); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJmp::emit(this, target.bind(this, 1)); > } > > void BytecodeGenerator::emitJumpIfTrue(RegisterID* cond, Label& target) >@@ -1376,11 +1342,7 @@ void BytecodeGenerator::emitJumpIfTrue(RegisterID* cond, Label& target) > if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) { > rewindBinaryOp(); > >- size_t begin = instructions().size(); >- emitOpcode(jumpID); >- instructions().append(src1Index); >- instructions().append(src2Index); >- instructions().append(target.bind(begin, instructions().size())); >+ BinaryJmp::emit(this, src1Index, src2Index, target.bind(this, 3)); > return true; > } > return false; >@@ -1424,11 +1386,7 @@ void BytecodeGenerator::emitJumpIfTrue(RegisterID* cond, Label& target) > > if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) { > rewindUnaryOp(); >- >- size_t begin = instructions().size(); >- emitOpcode(op_jeq_null); >- instructions().append(srcIndex); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJeqNull::emit(this, srcIndex, target.bind(this, 2)); > return; > } > } else if (m_lastOpcodeID == op_neq_null && target.isForward()) { >@@ -1440,19 +1398,14 @@ void BytecodeGenerator::emitJumpIfTrue(RegisterID* cond, Label& target) > if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) { > rewindUnaryOp(); > >- size_t begin = instructions().size(); >- emitOpcode(op_jneq_null); >- instructions().append(srcIndex); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJeqNull::emit(this, srcIndex, target.bind(this, 2)); > return; > } > } > > size_t begin = instructions().size(); > >- emitOpcode(op_jtrue); >- instructions().append(cond->index()); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJtrue::emit(this, cond, target.bind(this, 2)); > } > > void BytecodeGenerator::emitJumpIfFalse(RegisterID* cond, Label& target) >@@ -1467,14 +1420,10 @@ void BytecodeGenerator::emitJumpIfFalse(RegisterID* cond, Label& target) > if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) { > rewindBinaryOp(); > >- size_t begin = instructions().size(); >- emitOpcode(jumpID); > // Since op_below and op_beloweq only accepts Int32, replacing operands is not observable to users. > if (replaceOperands) > std::swap(src1Index, src2Index); >- instructions().append(src1Index); >- instructions().append(src2Index); >- instructions().append(target.bind(begin, instructions().size())); >+ BinaryJmp::emit(this, jumpID, src1Index, src2Index, target.bind(this, 3)); > return true; > } > return false; >@@ -1518,11 +1467,7 @@ void BytecodeGenerator::emitJumpIfFalse(RegisterID* cond, Label& target) > > if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) { > rewindUnaryOp(); >- >- size_t begin = instructions().size(); >- emitOpcode(op_jtrue); >- instructions().append(srcIndex); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJtrue::emit(this, srcIndex, target.bind(this, 2)); > return; > } > } else if (m_lastOpcodeID == op_eq_null && target.isForward()) { >@@ -1533,11 +1478,7 @@ void BytecodeGenerator::emitJumpIfFalse(RegisterID* cond, Label& target) > > if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) { > rewindUnaryOp(); >- >- size_t begin = instructions().size(); >- emitOpcode(op_jneq_null); >- instructions().append(srcIndex); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJneqNull::emit(this, srcIndex, target.bind(this, 2)); > return; > } > } else if (m_lastOpcodeID == op_neq_null && target.isForward()) { >@@ -1548,41 +1489,22 @@ void BytecodeGenerator::emitJumpIfFalse(RegisterID* cond, Label& target) > > if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) { > rewindUnaryOp(); >- >- size_t begin = instructions().size(); >- emitOpcode(op_jeq_null); >- instructions().append(srcIndex); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJeqNull::emit(this, srcIndex, target.bind(this, 2)); > return; > } > } > >- size_t begin = instructions().size(); >- emitOpcode(op_jfalse); >- instructions().append(cond->index()); >- instructions().append(target.bind(begin, instructions().size())); >+ OpJfalse::emit(this, cond, target.bind(this, 2)); > } > > void BytecodeGenerator::emitJumpIfNotFunctionCall(RegisterID* cond, Label& target) > { >- size_t begin = instructions().size(); >- >- emitOpcode(op_jneq_ptr); >- instructions().append(cond->index()); >- instructions().append(Special::CallFunction); >- instructions().append(target.bind(begin, instructions().size())); >- instructions().append(0); >+ OpJneqPtr::emit(this, cond->index(), Special::CallFunction, target.bind(this, 3)); > } > > void BytecodeGenerator::emitJumpIfNotFunctionApply(RegisterID* cond, Label& target) > { >- size_t begin = instructions().size(); >- >- emitOpcode(op_jneq_ptr); >- instructions().append(cond->index()); >- instructions().append(Special::ApplyFunction); >- instructions().append(target.bind(begin, instructions().size())); >- instructions().append(0); >+ OpJneqPtr::emit(this, cond->index(), Special::ApplyFunction, target.bind(this, 3)); > } > > bool BytecodeGenerator::hasConstant(const Identifier& ident) const >@@ -1644,9 +1566,7 @@ RegisterID* BytecodeGenerator::moveLinkTimeConstant(RegisterID* dst, LinkTimeCon > if (!dst) > return m_linkTimeConstantRegisters[constantIndex]; > >- emitOpcode(op_mov); >- instructions().append(dst->index()); >- instructions().append(m_linkTimeConstantRegisters[constantIndex]->index()); >+ OpMov::emit(this, dst->index(), m_linkTimeConstantRegisters[constantIndex]->index()); > > return dst; > } >@@ -1655,9 +1575,8 @@ RegisterID* BytecodeGenerator::moveEmptyValue(RegisterID* dst) > { > RefPtr<RegisterID> emptyValue = addConstantEmptyValue(); > >- emitOpcode(op_mov); >- instructions().append(dst->index()); >- instructions().append(emptyValue->index()); >+ OpMov::emit(this, dst->index(), emptyValue->index()); >+ > return dst; > } > >@@ -1666,9 +1585,7 @@ RegisterID* BytecodeGenerator::emitMove(RegisterID* dst, RegisterID* src) > ASSERT(src != m_emptyValueRegister); > > m_staticPropertyAnalyzer.mov(dst->index(), src->index()); >- emitOpcode(op_mov); >- instructions().append(dst->index()); >- instructions().append(src->index()); >+ OpMov::emit(this, dst, src); > > return dst; > } >@@ -1677,22 +1594,13 @@ RegisterID* BytecodeGenerator::emitUnaryOp(OpcodeID opcodeID, RegisterID* dst, R > { > ASSERT_WITH_MESSAGE(op_to_number != opcodeID, "op_to_number has a Value Profile."); > ASSERT_WITH_MESSAGE(op_negate != opcodeID, "op_negate has an Arith Profile."); >- emitOpcode(opcodeID); >- instructions().append(dst->index()); >- instructions().append(src->index()); >- >+ UnaryOp::emit(this, opcodeID, dst, src); > return dst; > } > > RegisterID* BytecodeGenerator::emitUnaryOp(OpcodeID opcodeID, RegisterID* dst, RegisterID* src, OperandTypes types) > { >- ASSERT_WITH_MESSAGE(op_to_number != opcodeID, "op_to_number has a Value Profile."); >- emitOpcode(opcodeID); >- instructions().append(dst->index()); >- instructions().append(src->index()); >- >- if (opcodeID == op_negate) >- instructions().append(ArithProfile(types.first()).bits()); >+ UnaryOp::emit(this, opcodeID, dst, src); > return dst; > } > >@@ -1707,39 +1615,33 @@ RegisterID* BytecodeGenerator::emitUnaryOpProfiled(OpcodeID opcodeID, RegisterID > > RegisterID* BytecodeGenerator::emitToObject(RegisterID* dst, RegisterID* src, const Identifier& message) > { >- UnlinkedValueProfile profile = emitProfiledOpcode(op_to_object); >- instructions().append(dst->index()); >- instructions().append(src->index()); >- instructions().append(addConstant(message)); >- instructions().append(profile); >+ OpToObject::emit(this, dst, src, addConstant(message)); > return dst; > } > > RegisterID* BytecodeGenerator::emitInc(RegisterID* srcDst) > { >- emitOpcode(op_inc); >- instructions().append(srcDst->index()); >+ OpInc::emit(this, srcDst); > return srcDst; > } > > RegisterID* BytecodeGenerator::emitDec(RegisterID* srcDst) > { >- emitOpcode(op_dec); >- instructions().append(srcDst->index()); >+ OpDec::emit(this, srcDst); > return srcDst; > } > > RegisterID* BytecodeGenerator::emitBinaryOp(OpcodeID opcodeID, RegisterID* dst, RegisterID* src1, RegisterID* src2, OperandTypes types) > { >- emitOpcode(opcodeID); >- instructions().append(dst->index()); >- instructions().append(src1->index()); >- instructions().append(src2->index()); >+ BinaryOp::emit(this, opcodeID, dst, src1, src2); >+ return dst; >+} > >- if (opcodeID == op_bitor || opcodeID == op_bitand || opcodeID == op_bitxor || >- opcodeID == op_add || opcodeID == op_mul || opcodeID == op_sub || opcodeID == op_div) >- instructions().append(ArithProfile(types.first(), types.second()).bits()); >+RegisterID* BytecodeGenerator::emitProfiledBinaryOp(OpcodeID opcodeID, RegisterID* dst, RegisterID* src1, RegisterID* src2, OperandTypes types) >+{ >+ ProfiledBinaryOp::emit(dst, opcodeID, src1, src2); > >+ instructions().append(ArithProfile(types.first(), types.second()).bits()); > return dst; > } > >@@ -1758,70 +1660,48 @@ RegisterID* BytecodeGenerator::emitEqualityOp(OpcodeID opcodeID, RegisterID* dst > const String& value = asString(m_codeBlock->constantRegister(src2->index()).get())->tryGetValue(); > if (value == "undefined") { > rewindUnaryOp(); >- emitOpcode(op_is_undefined); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >+ OpIsUndefined::emit(this, dst, srcIndex); > return dst; > } > if (value == "boolean") { > rewindUnaryOp(); >- emitOpcode(op_is_boolean); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >+ OpIsBoolean::emit(this, dst, srcIndex); > return dst; > } > if (value == "number") { > rewindUnaryOp(); >- emitOpcode(op_is_number); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >+ OpIsNumber::emit(this, dst, srcIndex); > return dst; > } > if (value == "string") { > rewindUnaryOp(); >- emitOpcode(op_is_cell_with_type); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >- instructions().append(StringType); >+ OpIsCellWithType::emit(this, dst, srcIndex, StringType); > return dst; > } > if (value == "symbol") { > rewindUnaryOp(); >- emitOpcode(op_is_cell_with_type); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >- instructions().append(SymbolType); >+ OpIsCellWithType::emit(this, dst, srcIndex, SymbolType); > return dst; > } > if (Options::useBigInt() && value == "bigint") { > rewindUnaryOp(); >- emitOpcode(op_is_cell_with_type); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >- instructions().append(BigIntType); >+ OpIsCellWithType::emit(this, dst, srcIndex, BigIntType); > return dst; > } > if (value == "object") { > rewindUnaryOp(); >- emitOpcode(op_is_object_or_null); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >+ OpIsObjectOrNull::emit(this, dst, srcIndex); > return dst; > } > if (value == "function") { > rewindUnaryOp(); >- emitOpcode(op_is_function); >- instructions().append(dst->index()); >- instructions().append(srcIndex); >+ OpIsFunction::emit(this, dst, srcIndex); > return dst; > } > } > } > >- emitOpcode(opcodeID); >- instructions().append(dst->index()); >- instructions().append(src1->index()); >- instructions().append(src2->index()); >+ BinaryOp::emit(this, dst, src1, src2); > return dst; > } > >@@ -1843,12 +1723,7 @@ void BytecodeGenerator::emitProfileType(RegisterID* registerToProfile, ProfileTy > if (!registerToProfile) > return; > >- emitOpcode(op_profile_type); >- instructions().append(registerToProfile->index()); >- instructions().append(0); >- instructions().append(flag); >- instructions().append(0); >- instructions().append(resolveType()); >+ OpProfileType::emit(this, registerToProfile, flag, nullopt, resolveType()); > > // Don't emit expression info for this version of profile type. This generally means > // we're profiling information for something that isn't in the actual text of a JavaScript >@@ -1869,13 +1744,7 @@ void BytecodeGenerator::emitProfileType(RegisterID* registerToProfile, ProfileTy > return; > > // The format of this instruction is: op_profile_type regToProfile, TypeLocation*, flag, identifier?, resolveType? >- emitOpcode(op_profile_type); >- instructions().append(registerToProfile->index()); >- instructions().append(0); >- instructions().append(flag); >- instructions().append(0); >- instructions().append(resolveType()); >- >+ OpProfileType::emit(this, registerToProfile, flag, nullopt, resolveType()); > emitTypeProfilerExpressionInfo(startDivot, endDivot); > } > >@@ -1899,12 +1768,7 @@ void BytecodeGenerator::emitProfileType(RegisterID* registerToProfile, const Var > } > > // The format of this instruction is: op_profile_type regToProfile, TypeLocation*, flag, identifier?, resolveType? >- emitOpcode(op_profile_type); >- instructions().append(registerToProfile->index()); >- instructions().append(symbolTableOrScopeDepth); >- instructions().append(flag); >- instructions().append(addConstant(var.ident())); >- instructions().append(resolveType()); >+ OpProfileType::emit(this, registerToProfile, symbolTableOrScopeDepth, flag, addConstant(var.ident()), resolveType()); > > emitTypeProfilerExpressionInfo(startDivot, endDivot); > } >@@ -1916,8 +1780,7 @@ void BytecodeGenerator::emitProfileControlFlow(int textOffset) > size_t bytecodeOffset = instructions().size(); > m_codeBlock->addOpProfileControlFlowBytecodeOffset(bytecodeOffset); > >- emitOpcode(op_profile_control_flow); >- instructions().append(textOffset); >+ OpProfileControlFlow::emit(this, textOffset); > } > } > >@@ -2116,11 +1979,7 @@ void BytecodeGenerator::pushLexicalScopeInternal(VariableEnvironment& environmen > if (constantSymbolTableResult) > *constantSymbolTableResult = constantSymbolTable; > >- emitOpcode(op_create_lexical_environment); >- instructions().append(newScope->index()); >- instructions().append(scopeRegister()->index()); >- instructions().append(constantSymbolTable->index()); >- instructions().append(addConstantValue(tdzRequirement == TDZRequirement::UnderTDZ ? jsTDZValue() : jsUndefined())->index()); >+ OpCreateLexicalEnvironment::emit(this, newScope, scopeRegister(), constantSymbolTable, addConstantValue(tdzRequirement == TDZRequirement::UnderTDZ ? jsTDZValue() : jsUndefined())->index()); > > move(scopeRegister(), newScope); > >@@ -2251,10 +2110,7 @@ RegisterID* BytecodeGenerator::emitResolveScopeForHoistingFuncDeclInEval(Registe > ASSERT(m_codeType == EvalCode); > > dst = finalDestination(dst); >- emitOpcode(op_resolve_scope_for_hoisting_func_decl_in_eval); >- instructions().append(kill(dst)); >- instructions().append(m_topMostScope->index()); >- instructions().append(addConstant(property)); >+ OpResolveScopeForHoistingFuncDeclInEval::emit(this, kill(dst), m_topMostScope, addConstant(property)); > return dst; > } > >@@ -2352,11 +2208,7 @@ void BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration(VariableEnvir > RefPtr<RegisterID> parentScope = emitGetParentScope(newTemporary(), loopScope); > move(scopeRegister(), parentScope.get()); > >- emitOpcode(op_create_lexical_environment); >- instructions().append(loopScope->index()); >- instructions().append(scopeRegister()->index()); >- instructions().append(loopSymbolTable->index()); >- instructions().append(addConstantValue(jsTDZValue())->index()); >+ OpCreateLexicalEnvironment::emit(this, loopScope, scopeRegister(), loopSymbolTable, addConstantValue(jsTDZValue())); > > move(scopeRegister(), loopScope); > >@@ -2481,10 +2333,7 @@ void BytecodeGenerator::createVariable( > > RegisterID* BytecodeGenerator::emitOverridesHasInstance(RegisterID* dst, RegisterID* constructor, RegisterID* hasInstanceValue) > { >- emitOpcode(op_overrides_has_instance); >- instructions().append(dst->index()); >- instructions().append(constructor->index()); >- instructions().append(hasInstanceValue->index()); >+ OpOverridesHasInstance::emit(this, dst, constructor, hasInstanceValue); > return dst; > } > >@@ -2549,13 +2398,7 @@ RegisterID* BytecodeGenerator::emitResolveScope(RegisterID* dst, const Variable& > > // resolve_scope dst, id, ResolveType, depth > dst = tempDestination(dst); >- emitOpcode(op_resolve_scope); >- instructions().append(kill(dst)); >- instructions().append(scopeRegister()->index()); >- instructions().append(addConstant(variable.ident())); >- instructions().append(resolveType()); >- instructions().append(localScopeDepth()); >- instructions().append(0); >+ OpResolveScope::emit(this, kill(dst), scopeRegister(), addConstant(variable.ident()), resolveType(), localScopeDepth()); > return dst; > } > >@@ -2605,10 +2448,7 @@ RegisterID* BytecodeGenerator::emitPutToScope(RegisterID* scope, const Variable& > return value; > > case VarKind::DirectArgument: >- emitOpcode(op_put_to_arguments); >- instructions().append(scope->index()); >- instructions().append(variable.offset().capturedArgumentsOffset().offset()); >- instructions().append(value->index()); >+ OpPutToArguments::emit(this, scope, variable.offset().capturedArgumentsOffset().offset(), value); > return value; > > case VarKind::Scope: >@@ -2616,10 +2456,7 @@ RegisterID* BytecodeGenerator::emitPutToScope(RegisterID* scope, const Variable& > m_codeBlock->addPropertyAccessInstruction(instructions().size()); > > // put_to_scope scope, id, value, GetPutInfo, Structure, Operand >- emitOpcode(op_put_to_scope); >- instructions().append(scope->index()); >- instructions().append(addConstant(variable.ident())); >- instructions().append(value->index()); >+ OpPutToScope::emit(this, scope, addConstant(variable.ident()), value); > ScopeOffset offset; > if (variable.offset().isScope()) { > offset = variable.offset().scopeOffset(); >@@ -2646,40 +2483,25 @@ RegisterID* BytecodeGenerator::initializeVariable(const Variable& variable, Regi > > RegisterID* BytecodeGenerator::emitInstanceOf(RegisterID* dst, RegisterID* value, RegisterID* basePrototype) > { >- emitOpcode(op_instanceof); >- instructions().append(dst->index()); >- instructions().append(value->index()); >- instructions().append(basePrototype->index()); >+ OpInstanceof::emit(this, dst, value, basePrototype); > return dst; > } > > RegisterID* BytecodeGenerator::emitInstanceOfCustom(RegisterID* dst, RegisterID* value, RegisterID* constructor, RegisterID* hasInstanceValue) > { >- emitOpcode(op_instanceof_custom); >- instructions().append(dst->index()); >- instructions().append(value->index()); >- instructions().append(constructor->index()); >- instructions().append(hasInstanceValue->index()); >+ OpInstanceofCustom::emit(this, dst, value, constructor, hasInstanceValue); > return dst; > } > > RegisterID* BytecodeGenerator::emitInByVal(RegisterID* dst, RegisterID* property, RegisterID* base) > { >- UnlinkedArrayProfile arrayProfile = newArrayProfile(); >- emitOpcode(op_in_by_val); >- instructions().append(dst->index()); >- instructions().append(base->index()); >- instructions().append(property->index()); >- instructions().append(arrayProfile); >+ OpInByVal::emit(this, dst, base, property); > return dst; > } > > RegisterID* BytecodeGenerator::emitInById(RegisterID* dst, RegisterID* base, const Identifier& property) > { >- emitOpcode(op_in_by_id); >- instructions().append(dst->index()); >- instructions().append(base->index()); >- instructions().append(addConstant(property)); >+ OpInById::emit(this, dst, base, addConstant(property)); > return dst; > } > >@@ -2687,11 +2509,7 @@ RegisterID* BytecodeGenerator::emitTryGetById(RegisterID* dst, RegisterID* base, > { > ASSERT_WITH_MESSAGE(!parseIndex(property), "Indexed properties are not supported with tryGetById."); > >- UnlinkedValueProfile profile = emitProfiledOpcode(op_try_get_by_id); >- instructions().append(kill(dst)); >- instructions().append(base->index()); >- instructions().append(addConstant(property)); >- instructions().append(profile); >+ OpTryGetById::emit(this, kill(dst), base, addConstant(property)); > return dst; > } > >@@ -2701,15 +2519,8 @@ RegisterID* BytecodeGenerator::emitGetById(RegisterID* dst, RegisterID* base, co > > m_codeBlock->addPropertyAccessInstruction(instructions().size()); > >- UnlinkedValueProfile profile = emitProfiledOpcode(op_get_by_id); >- instructions().append(kill(dst)); >- instructions().append(base->index()); >- instructions().append(addConstant(property)); >- instructions().append(0); >- instructions().append(0); >- instructions().append(0); >- instructions().append(Options::prototypeHitCountForLLIntCaching()); >- instructions().append(profile); >+ OpGetById::emit(this, kill(dst), base, addConstant(property)); >+ // TODO: instructions().append(Options::prototypeHitCountForLLIntCaching()); > return dst; > } > >@@ -2717,12 +2528,7 @@ RegisterID* BytecodeGenerator::emitGetById(RegisterID* dst, RegisterID* base, Re > { > ASSERT_WITH_MESSAGE(!parseIndex(property), "Indexed properties should be handled with get_by_val."); > >- UnlinkedValueProfile profile = emitProfiledOpcode(op_get_by_id_with_this); >- instructions().append(kill(dst)); >- instructions().append(base->index()); >- instructions().append(thisVal->index()); >- instructions().append(addConstant(property)); >- instructions().append(profile); >+ OpGetByIdWithThis::emit(this, kill(dst), base, thisVal, addConstant(property)); > return dst; > } > >@@ -2732,13 +2538,7 @@ RegisterID* BytecodeGenerator::emitDirectGetById(RegisterID* dst, RegisterID* ba > > m_codeBlock->addPropertyAccessInstruction(instructions().size()); > >- UnlinkedValueProfile profile = emitProfiledOpcode(op_get_by_id_direct); >- instructions().append(kill(dst)); >- instructions().append(base->index()); >- instructions().append(addConstant(property)); >- instructions().append(0); >- instructions().append(0); >- instructions().append(profile); >+ OpGetByIdDirect::emit(this, kill(dst), base, addConstant(property)); > return dst; > } > >@@ -2752,15 +2552,8 @@ RegisterID* BytecodeGenerator::emitPutById(RegisterID* base, const Identifier& p > > m_codeBlock->addPropertyAccessInstruction(instructions().size()); > >- emitOpcode(op_put_by_id); >- instructions().append(base->index()); >- instructions().append(propertyIndex); >- instructions().append(value->index()); >- instructions().append(0); // old structure >- instructions().append(0); // offset >- instructions().append(0); // new structure >- instructions().append(0); // structure chain >- instructions().append(static_cast<int>(PutByIdNone)); // is not direct >+ OpPutById::emit(this, base, propertyIndex, value); >+ // TODO: instructions().append(static_cast<int>(PutByIdNone)); // is not direct > > return value; > } >@@ -2771,11 +2564,7 @@ RegisterID* BytecodeGenerator::emitPutById(RegisterID* base, RegisterID* thisVal > > unsigned propertyIndex = addConstant(property); > >- emitOpcode(op_put_by_id_with_this); >- instructions().append(base->index()); >- instructions().append(thisValue->index()); >- instructions().append(propertyIndex); >- instructions().append(value->index()); >+ OpPutByIdWithThis::emit(this, base, thisValue, propertyIndex, value); > > return value; > } >@@ -2790,15 +2579,8 @@ RegisterID* BytecodeGenerator::emitDirectPutById(RegisterID* base, const Identif > > m_codeBlock->addPropertyAccessInstruction(instructions().size()); > >- emitOpcode(op_put_by_id); >- instructions().append(base->index()); >- instructions().append(propertyIndex); >- instructions().append(value->index()); >- instructions().append(0); // old structure >- instructions().append(0); // offset >- instructions().append(0); // new structure >- instructions().append(0); // structure chain (unused if direct) >- instructions().append(static_cast<int>((putType == PropertyNode::KnownDirect || property != m_vm->propertyNames->underscoreProto) ? PutByIdIsDirect : PutByIdNone)); >+ OpPutById::emit(this, base, propertyIndex, value); >+ // TODO: instructions().append(static_cast<int>((putType == PropertyNode::KnownDirect || property != m_vm->propertyNames->underscoreProto) ? PutByIdIsDirect : PutByIdNone)); > return value; > } > >@@ -2807,11 +2589,7 @@ void BytecodeGenerator::emitPutGetterById(RegisterID* base, const Identifier& pr > unsigned propertyIndex = addConstant(property); > m_staticPropertyAnalyzer.putById(base->index(), propertyIndex); > >- emitOpcode(op_put_getter_by_id); >- instructions().append(base->index()); >- instructions().append(propertyIndex); >- instructions().append(attributes); >- instructions().append(getter->index()); >+ OpPutGetterById::emit(this, base, propertyIndex, attributes, getter); > } > > void BytecodeGenerator::emitPutSetterById(RegisterID* base, const Identifier& property, unsigned attributes, RegisterID* setter) >@@ -2819,11 +2597,7 @@ void BytecodeGenerator::emitPutSetterById(RegisterID* base, const Identifier& pr > unsigned propertyIndex = addConstant(property); > m_staticPropertyAnalyzer.putById(base->index(), propertyIndex); > >- emitOpcode(op_put_setter_by_id); >- instructions().append(base->index()); >- instructions().append(propertyIndex); >- instructions().append(attributes); >- instructions().append(setter->index()); >+ OpPutSetterById::emit(this, base, propertyIndex, attributes, setter); > } > > void BytecodeGenerator::emitPutGetterSetter(RegisterID* base, const Identifier& property, unsigned attributes, RegisterID* getter, RegisterID* setter) >@@ -2832,30 +2606,17 @@ void BytecodeGenerator::emitPutGetterSetter(RegisterID* base, const Identifier& > > m_staticPropertyAnalyzer.putById(base->index(), propertyIndex); > >- emitOpcode(op_put_getter_setter_by_id); >- instructions().append(base->index()); >- instructions().append(propertyIndex); >- instructions().append(attributes); >- instructions().append(getter->index()); >- instructions().append(setter->index()); >+ OpPutGetterSetterById::emit(this, base, propertyIndex, attributes, getter, setter); > } > > void BytecodeGenerator::emitPutGetterByVal(RegisterID* base, RegisterID* property, unsigned attributes, RegisterID* getter) > { >- emitOpcode(op_put_getter_by_val); >- instructions().append(base->index()); >- instructions().append(property->index()); >- instructions().append(attributes); >- instructions().append(getter->index()); >+ OpPutGetterByVal::emit(this, base, property, attributes, getter); > } > > void BytecodeGenerator::emitPutSetterByVal(RegisterID* base, RegisterID* property, unsigned attributes, RegisterID* setter) > { >- emitOpcode(op_put_setter_by_val); >- instructions().append(base->index()); >- instructions().append(property->index()); >- instructions().append(attributes); >- instructions().append(setter->index()); >+ OpPutSetterByVal::emit(this, base, property, attributes, setter); > } > > void BytecodeGenerator::emitPutGeneratorFields(RegisterID* nextFunction) >@@ -2896,10 +2657,7 @@ void BytecodeGenerator::emitPutAsyncGeneratorFields(RegisterID* nextFunction) > > RegisterID* BytecodeGenerator::emitDeleteById(RegisterID* dst, RegisterID* base, const Identifier& property) > { >- emitOpcode(op_del_by_id); >- instructions().append(dst->index()); >- instructions().append(base->index()); >- instructions().append(addConstant(property)); >+ OpDelById::emit(this, dst, base, addConstant(property)); > return dst; > } > >@@ -2920,112 +2678,70 @@ RegisterID* BytecodeGenerator::emitGetByVal(RegisterID* dst, RegisterID* base, R > > ASSERT(context.type() == ForInContext::StructureForInContextType); > StructureForInContext& structureContext = static_cast<StructureForInContext&>(context); >- UnlinkedValueProfile profile = emitProfiledOpcode(op_get_direct_pname); >- instructions().append(kill(dst)); >- instructions().append(base->index()); >- instructions().append(property->index()); >- instructions().append(structureContext.index()->index()); >- instructions().append(structureContext.enumerator()->index()); >- instructions().append(profile); >+ OpGetDirectPname::emit(this, kill(dst), base, property, structureContext.index()->index(), structureContext.enumerator()->index()); > > structureContext.addGetInst(instIndex, property->index(), profile); > return dst; > } > >- UnlinkedArrayProfile arrayProfile = newArrayProfile(); >- UnlinkedValueProfile profile = emitProfiledOpcode(op_get_by_val); >- instructions().append(kill(dst)); >- instructions().append(base->index()); >- instructions().append(property->index()); >- instructions().append(arrayProfile); >- instructions().append(profile); >+ OpGetByVal::emit(this, kill(dst), base, property); > return dst; > } > > RegisterID* BytecodeGenerator::emitGetByVal(RegisterID* dst, RegisterID* base, RegisterID* thisValue, RegisterID* property) > { >- UnlinkedValueProfile profile = emitProfiledOpcode(op_get_by_val_with_this); >- instructions().append(kill(dst)); >- instructions().append(base->index()); >- instructions().append(thisValue->index()); >- instructions().append(property->index()); >- instructions().append(profile); >+ OpGetByValWithThis::emit(this, kill(dst), base, thisValue, property); > return dst; > } > > RegisterID* BytecodeGenerator::emitPutByVal(RegisterID* base, RegisterID* property, RegisterID* value) > { >- UnlinkedArrayProfile arrayProfile = newArrayProfile(); >- emitOpcode(op_put_by_val); >- instructions().append(base->index()); >- instructions().append(property->index()); >- instructions().append(value->index()); >- instructions().append(arrayProfile); >- >+ OpPutByVal::emit(this, base, property, value); > return value; > } > > RegisterID* BytecodeGenerator::emitPutByVal(RegisterID* base, RegisterID* thisValue, RegisterID* property, RegisterID* value) > { >- emitOpcode(op_put_by_val_with_this); >- instructions().append(base->index()); >- instructions().append(thisValue->index()); >- instructions().append(property->index()); >- instructions().append(value->index()); >- >+ OpPutByValWithThis::emit(this, base, thisValue, property, value); > return value; > } > > RegisterID* BytecodeGenerator::emitDirectPutByVal(RegisterID* base, RegisterID* property, RegisterID* value) > { >- UnlinkedArrayProfile arrayProfile = newArrayProfile(); >- emitOpcode(op_put_by_val_direct); >- instructions().append(base->index()); >- instructions().append(property->index()); >- instructions().append(value->index()); >- instructions().append(arrayProfile); >+ OpPutByValDirect::emit(this, base, property, value); > return value; > } > > RegisterID* BytecodeGenerator::emitDeleteByVal(RegisterID* dst, RegisterID* base, RegisterID* property) > { >- emitOpcode(op_del_by_val); >- instructions().append(dst->index()); >- instructions().append(base->index()); >- instructions().append(property->index()); >+ OpDelByVal::emit(this, dst, base, property); > return dst; > } > > void BytecodeGenerator::emitSuperSamplerBegin() > { >- emitOpcode(op_super_sampler_begin); >+ OpSuperSamplerBegin::emit(this); > } > > void BytecodeGenerator::emitSuperSamplerEnd() > { >- emitOpcode(op_super_sampler_end); >+ OpSuperSamplerEnd::emit(this); > } > > RegisterID* BytecodeGenerator::emitIdWithProfile(RegisterID* src, SpeculatedType profile) > { >- emitOpcode(op_identity_with_profile); >- instructions().append(src->index()); >- instructions().append(static_cast<uint32_t>(profile >> 32)); >- instructions().append(static_cast<uint32_t>(profile)); >+ OpIdentityWithProfile::emit(this, src, static_cast<uint32_t>(profile >> 32), static_cast<uint32_t>(profile)); > return src; > } > > void BytecodeGenerator::emitUnreachable() > { >- emitOpcode(op_unreachable); >+ OpUnreachable::emit(this); > } > > RegisterID* BytecodeGenerator::emitGetArgument(RegisterID* dst, int32_t index) > { >- UnlinkedValueProfile profile = emitProfiledOpcode(op_get_argument); >- instructions().append(dst->index()); >- instructions().append(index + 1); // Including |this|. >- instructions().append(profile); >+ OpGetArgument::emit(this, dst, index + 1 /* Including |this| */); > return dst; > } > >@@ -3035,18 +2751,13 @@ RegisterID* BytecodeGenerator::emitCreateThis(RegisterID* dst) > m_staticPropertyAnalyzer.createThis(dst->index(), begin + 3); > > m_codeBlock->addPropertyAccessInstruction(instructions().size()); >- emitOpcode(op_create_this); >- instructions().append(dst->index()); >- instructions().append(dst->index()); >- instructions().append(0); >- instructions().append(0); >+ OpCreateThis::emit(this, dst, dst, 0); > return dst; > } > > void BytecodeGenerator::emitTDZCheck(RegisterID* target) > { >- emitOpcode(op_check_tdz); >- instructions().append(target->index()); >+ OpCheckTdz::emit(this, target); > } > > bool BytecodeGenerator::needsTDZCheck(const Variable& variable) >@@ -3149,10 +2860,7 @@ RegisterID* BytecodeGenerator::emitNewObject(RegisterID* dst) > size_t begin = instructions().size(); > m_staticPropertyAnalyzer.newObject(dst->index(), begin + 2); > >- emitOpcode(op_new_object); >- instructions().append(dst->index()); >- instructions().append(0); >- instructions().append(newObjectAllocationProfile()); >+ OpNewObject::emit(this, dst, 0); > return dst; > } > >@@ -3195,10 +2903,7 @@ RegisterID* BytecodeGenerator::addTemplateObjectConstant(Ref<TemplateObjectDescr > > RegisterID* BytecodeGenerator::emitNewArrayBuffer(RegisterID* dst, JSImmutableButterfly* array, IndexingType recommendedIndexingType) > { >- emitOpcode(op_new_array_buffer); >- instructions().append(dst->index()); >- instructions().append(addConstantValue(array)->index()); >- instructions().append(newArrayAllocationProfile(recommendedIndexingType)); >+ OpNewArrayBuffer::emit(this, dst, addConstantValue(array)); > return dst; > } > >@@ -3216,11 +2921,7 @@ RegisterID* BytecodeGenerator::emitNewArray(RegisterID* dst, ElementNode* elemen > emitNode(argv.last().get(), n->value()); > } > ASSERT(!length); >- emitOpcode(op_new_array); >- instructions().append(dst->index()); >- instructions().append(argv.size() ? argv[0]->index() : 0); // argv >- instructions().append(argv.size()); // argc >- instructions().append(newArrayAllocationProfile(recommendedIndexingType)); >+ OpNewArray::emit(this, dst, argv.size() ? argv[0]->index() : nullopt, argv.size()); > return dst; > } > >@@ -3246,9 +2947,7 @@ RegisterID* BytecodeGenerator::emitNewArrayWithSpread(RegisterID* dst, ElementNo > RefPtr<RegisterID> tmp = newTemporary(); > emitNode(tmp.get(), expression); > >- emitOpcode(op_spread); >- instructions().append(argv[i].get()->index()); >- instructions().append(tmp.get()->index()); >+ OpSpread::emit(this, argv[i].get(), tmp.get()); > } else { > ExpressionNode* expression = node->value(); > emitNode(argv[i].get(), expression); >@@ -3258,30 +2957,19 @@ RegisterID* BytecodeGenerator::emitNewArrayWithSpread(RegisterID* dst, ElementNo > } > > unsigned bitVectorIndex = m_codeBlock->addBitVector(WTFMove(bitVector)); >- emitOpcode(op_new_array_with_spread); >- instructions().append(dst->index()); >- instructions().append(argv[0]->index()); // argv >- instructions().append(argv.size()); // argc >- instructions().append(bitVectorIndex); >- >+ OpNewArrayWithSpread::emit(this, dst, argv[0], argv.size(), bitVectorIndex); > return dst; > } > > RegisterID* BytecodeGenerator::emitNewArrayWithSize(RegisterID* dst, RegisterID* length) > { >- emitOpcode(op_new_array_with_size); >- instructions().append(dst->index()); >- instructions().append(length->index()); >- instructions().append(newArrayAllocationProfile(ArrayWithUndecided)); >- >+ OpNewArrayWithSize::emit(This, dst, length); > return dst; > } > > RegisterID* BytecodeGenerator::emitNewRegExp(RegisterID* dst, RegExp* regExp) > { >- emitOpcode(op_new_regexp); >- instructions().append(dst->index()); >- instructions().append(addConstantValue(regExp)->index()); >+ OpNewRegexp::emit(This, dst, addConstantValue(regExpr)); > return dst; > } > >@@ -3309,10 +2997,7 @@ void BytecodeGenerator::emitNewFunctionExpressionCommon(RegisterID* dst, Functio > break; > } > >- emitOpcode(opcodeID); >- instructions().append(dst->index()); >- instructions().append(scopeRegister()->index()); >- instructions().append(index); >+ NewFunction::emit(this, opcodeID, dst, scopeRegister(), index); > } > > RegisterID* BytecodeGenerator::emitNewFunctionExpression(RegisterID* dst, FuncExprNode* func) >@@ -3345,28 +3030,24 @@ RegisterID* BytecodeGenerator::emitNewDefaultConstructor(RegisterID* dst, Constr > > unsigned index = m_codeBlock->addFunctionExpr(executable); > >- emitOpcode(op_new_func_exp); >- instructions().append(dst->index()); >- instructions().append(scopeRegister()->index()); >- instructions().append(index); >+ OpNewFuncExp::emit(this, dst, scopeRegister(), index); > return dst; > } > > RegisterID* BytecodeGenerator::emitNewFunction(RegisterID* dst, FunctionMetadataNode* function) > { > unsigned index = m_codeBlock->addFunctionDecl(makeFunction(function)); >+ OpcodeID opcodeID; > if (isGeneratorWrapperParseMode(function->parseMode())) >- emitOpcode(op_new_generator_func); >+ opcodeID = op_new_generator_func; > else if (function->parseMode() == SourceParseMode::AsyncFunctionMode) >- emitOpcode(op_new_async_func); >+ opcodeID = op_new_async_func; > else if (isAsyncGeneratorWrapperParseMode(function->parseMode())) { > ASSERT(Options::useAsyncIterator()); >- emitOpcode(op_new_async_generator_func); >+ opcodeID = op_new_async_generator_func; > } else >- emitOpcode(op_new_func); >- instructions().append(dst->index()); >- instructions().append(scopeRegister()->index()); >- instructions().append(index); >+ opcodeID = op_new_func; >+ NewFunction::emit(this, opcodeID, dst, scopeRegister(), index); > return dst; > } > >@@ -3387,9 +3068,7 @@ void BytecodeGenerator::emitSetFunctionNameIfNeeded(ExpressionNode* valueNode, R > > // FIXME: We should use an op_call to an internal function here instead. > // https://bugs.webkit.org/show_bug.cgi?id=155547 >- emitOpcode(op_set_function_name); >- instructions().append(value->index()); >- instructions().append(name->index()); >+ OpSetFunctionName::emit(this, value, name); > } > > RegisterID* BytecodeGenerator::emitCall(RegisterID* dst, RegisterID* func, ExpectedFunction expectedFunction, CallArguments& callArguments, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall debuggableCall) >@@ -3430,11 +3109,7 @@ ExpectedFunction BytecodeGenerator::emitExpectedFunctionSnippet(RegisterID* dst, > return NoExpectedFunction; > > size_t begin = instructions().size(); >- emitOpcode(op_jneq_ptr); >- instructions().append(func->index()); >- instructions().append(Special::ObjectConstructor); >- instructions().append(realCall->bind(begin, instructions().size())); >- instructions().append(0); >+ OpJneqPtr::emit(this, func, Special::ObjectConstructor, realCall->bind(begin, instructions().size()); > > if (dst != ignoredResult()) > emitNewObject(dst); >@@ -3451,22 +3126,15 @@ ExpectedFunction BytecodeGenerator::emitExpectedFunctionSnippet(RegisterID* dst, > return NoExpectedFunction; > > size_t begin = instructions().size(); >- emitOpcode(op_jneq_ptr); >- instructions().append(func->index()); >- instructions().append(Special::ArrayConstructor); >- instructions().append(realCall->bind(begin, instructions().size())); >- instructions().append(0); >+ OpJneqPtr::emit(This, func, Special::ArrayConstructor, realCall->bind(begin, instructions().size()); > > if (dst != ignoredResult()) { > if (callArguments.argumentCountIncludingThis() == 2) > emitNewArrayWithSize(dst, callArguments.argumentRegister(0)); > else { > ASSERT(callArguments.argumentCountIncludingThis() == 1); >- emitOpcode(op_new_array); >- instructions().append(dst->index()); >- instructions().append(0); >- instructions().append(0); >- instructions().append(newArrayAllocationProfile(ArrayWithUndecided)); >+ OpNewArray::emit(This, dst, nullopt, 0); >+ // instructions().append(newArrayAllocationProfile(ArrayWithUndecided)); > } > } > break; >@@ -3478,8 +3146,7 @@ ExpectedFunction BytecodeGenerator::emitExpectedFunctionSnippet(RegisterID* dst, > } > > size_t begin = instructions().size(); >- emitOpcode(op_jmp); >- instructions().append(done.bind(begin, instructions().size())); >+ OpJmp::emit(this, done.bind(begin, instructions().size())); > emitLabel(realCall.get()); > > return expectedFunction; >@@ -3502,9 +3169,7 @@ RegisterID* BytecodeGenerator::emitCall(OpcodeID opcodeID, RegisterID* dst, Regi > if (elements && !elements->next() && elements->value()->isSpreadExpression()) { > ExpressionNode* expression = static_cast<SpreadExpressionNode*>(elements->value())->expression(); > RefPtr<RegisterID> argumentRegister = emitNode(callArguments.argumentRegister(0), expression); >- emitOpcode(op_spread); >- instructions().append(argumentRegister.get()->index()); >- instructions().append(argumentRegister.get()->index()); >+ OpSpread::emit(this, argumentRegister, argumentRegister); > > RefPtr<RegisterID> thisRegister = move(newTemporary(), callArguments.thisRegister()); > return emitCallVarargs(opcodeID == op_tail_call ? op_tail_call_varargs : op_call_varargs, dst, func, callArguments.thisRegister(), argumentRegister.get(), newTemporary(), 0, divot, divotStart, divotEnd, debuggableCall); >@@ -3605,17 +3270,14 @@ void BytecodeGenerator::emitLogShadowChickenPrologueIfNecessary() > { > if (!m_shouldEmitDebugHooks && !Options::alwaysUseShadowChicken()) > return; >- emitOpcode(op_log_shadow_chicken_prologue); >- instructions().append(scopeRegister()->index()); >+ OpLogShadowChickenPrologue::emit(this, scopeRegister()); > } > > void BytecodeGenerator::emitLogShadowChickenTailIfNecessary() > { > if (!m_shouldEmitDebugHooks && !Options::alwaysUseShadowChicken()) > return; >- emitOpcode(op_log_shadow_chicken_tail); >- instructions().append(thisRegister()->index()); >- instructions().append(scopeRegister()->index()); >+ OpLogShadowChickenTail::emit(this, thisRegister(), scopeRegister()); > } > > void BytecodeGenerator::emitCallDefineProperty(RegisterID* newObj, RegisterID* propertyNameRegister, >@@ -3661,18 +3323,9 @@ void BytecodeGenerator::emitCallDefineProperty(RegisterID* newObj, RegisterID* p > else > setter = throwTypeErrorFunction; > >- emitOpcode(op_define_accessor_property); >- instructions().append(newObj->index()); >- instructions().append(propertyNameRegister->index()); >- instructions().append(getter->index()); >- instructions().append(setter->index()); >- instructions().append(emitLoad(nullptr, jsNumber(attributes.rawRepresentation()))->index()); >+ OpDefineAccessorProperty::emit(this, newObj, propertyNameRegister, getter, setter, emitLoad(nullptr, jsNumber(attributes.rawRepresentation()))); > } else { >- emitOpcode(op_define_data_property); >- instructions().append(newObj->index()); >- instructions().append(propertyNameRegister->index()); >- instructions().append(valueRegister->index()); >- instructions().append(emitLoad(nullptr, jsNumber(attributes.rawRepresentation()))->index()); >+ OpDefineDataProperty::emit(this, newObj, propertyNameRegister, valueRegister, emitLoad(nullptr, jsNumber(attributes.rawRepresentation()))); > } > } > >@@ -3696,18 +3349,12 @@ RegisterID* BytecodeGenerator::emitReturn(RegisterID* src, ReturnFrom from) > emitLabel(isUndefinedLabel.get()); > emitTDZCheck(&m_thisRegister); > } >- emitUnaryNoDstOp(op_ret, &m_thisRegister); >+ OpRet::emit(this, &m_thisRegister); > emitLabel(isObjectLabel.get()); > } > } > >- return emitUnaryNoDstOp(op_ret, src); >-} >- >-RegisterID* BytecodeGenerator::emitUnaryNoDstOp(OpcodeID opcodeID, RegisterID* src) >-{ >- emitOpcode(opcodeID); >- instructions().append(src->index()); >+ OpRet::emit(this, src); > return src; > } > >@@ -3728,9 +3375,7 @@ RegisterID* BytecodeGenerator::emitConstruct(RegisterID* dst, RegisterID* func, > if (elements && !elements->next() && elements->value()->isSpreadExpression()) { > ExpressionNode* expression = static_cast<SpreadExpressionNode*>(elements->value())->expression(); > RefPtr<RegisterID> argumentRegister = emitNode(callArguments.argumentRegister(0), expression); >- emitOpcode(op_spread); >- instructions().append(argumentRegister.get()->index()); >- instructions().append(argumentRegister.get()->index()); >+ OpSpread::emit(this, argumentRegister.get(), argumentRegister.get()); > > move(callArguments.thisRegister(), lazyThis); > RefPtr<RegisterID> thisRegister = move(newTemporary(), callArguments.thisRegister()); >@@ -3778,25 +3423,18 @@ RegisterID* BytecodeGenerator::emitConstruct(RegisterID* dst, RegisterID* func, > > RegisterID* BytecodeGenerator::emitStrcat(RegisterID* dst, RegisterID* src, int count) > { >- emitOpcode(op_strcat); >- instructions().append(dst->index()); >- instructions().append(src->index()); >- instructions().append(count); >- >+ OpStrcat::emit(this, dst, src, count); > return dst; > } > > void BytecodeGenerator::emitToPrimitive(RegisterID* dst, RegisterID* src) > { >- emitOpcode(op_to_primitive); >- instructions().append(dst->index()); >- instructions().append(src->index()); >+ OpToPrimitive::emit(this, dst, src); > } > > void BytecodeGenerator::emitGetScope() > { >- emitOpcode(op_get_scope); >- instructions().append(scopeRegister()->index()); >+ OpGetScope::emit(this, scopeRegister()); > } > > RegisterID* BytecodeGenerator::emitPushWithScope(RegisterID* objectScope) >@@ -3805,10 +3443,7 @@ RegisterID* BytecodeGenerator::emitPushWithScope(RegisterID* objectScope) > RegisterID* newScope = newBlockScopeVariable(); > newScope->ref(); > >- emitOpcode(op_push_with_scope); >- instructions().append(newScope->index()); >- instructions().append(scopeRegister()->index()); >- instructions().append(objectScope->index()); >+ OpPushWithScope::emit(this, newScope, scopeRegister(), objectScope); > > move(scopeRegister(), newScope); > m_lexicalScopeStack.append({ nullptr, newScope, true, 0 }); >@@ -3818,9 +3453,7 @@ RegisterID* BytecodeGenerator::emitPushWithScope(RegisterID* objectScope) > > RegisterID* BytecodeGenerator::emitGetParentScope(RegisterID* dst, RegisterID* scope) > { >- emitOpcode(op_get_parent_scope); >- instructions().append(dst->index()); >- instructions().append(scope->index()); >+ OpGetParentScope::emit(this, dst, scope); > return dst; > } > >@@ -3845,9 +3478,7 @@ void BytecodeGenerator::emitDebugHook(DebugHookType debugHookType, const JSTextP > return; > > emitExpressionInfo(divot, divot, divot); >- emitOpcode(op_debug); >- instructions().append(debugHookType); >- instructions().append(false); >+ OpDebug::emit(this, debugHookType, false); > } > > void BytecodeGenerator::emitDebugHook(DebugHookType debugHookType, unsigned line, unsigned charOffset, unsigned lineStart) >@@ -4062,16 +3693,12 @@ void BytecodeGenerator::emitThrowStaticError(ErrorType errorType, RegisterID* ra > { > RefPtr<RegisterID> message = newTemporary(); > emitToString(message.get(), raw); >- emitOpcode(op_throw_static_error); >- instructions().append(message->index()); >- instructions().append(static_cast<unsigned>(errorType)); >+ OpThrowStaticError::emit(this, message, errorType); > } > > void BytecodeGenerator::emitThrowStaticError(ErrorType errorType, const Identifier& message) > { >- emitOpcode(op_throw_static_error); >- instructions().append(addConstantValue(addStringConstant(message))->index()); >- instructions().append(static_cast<unsigned>(errorType)); >+ OpThrowStaticError::emit(this, addConstantValue(addStringConstant(message)), errorType); > } > > void BytecodeGenerator::emitThrowReferenceError(const String& message) >@@ -4151,23 +3778,22 @@ void BytecodeGenerator::emitPopCatchScope(VariableEnvironment& environment) > void BytecodeGenerator::beginSwitch(RegisterID* scrutineeRegister, SwitchInfo::SwitchType type) > { > SwitchInfo info = { static_cast<uint32_t>(instructions().size()), type }; >+ OpcodeID opcode; > switch (type) { > case SwitchInfo::SwitchImmediate: >- emitOpcode(op_switch_imm); >+ opcode = op_switch_imm; > break; > case SwitchInfo::SwitchCharacter: >- emitOpcode(op_switch_char); >+ opcode = op_switch_char; > break; > case SwitchInfo::SwitchString: >- emitOpcode(op_switch_string); >+ opcode = op_switch_string; > break; > default: > RELEASE_ASSERT_NOT_REACHED(); > } > >- instructions().append(0); // place holder for table index >- instructions().append(0); // place holder for default target >- instructions().append(scrutineeRegister->index()); >+ SwitchValue::emit(this, opcode, 0, 0, scrutineeRegister); > m_switchContextStack.append(info); > } > >@@ -4459,114 +4085,79 @@ RegisterID* BytecodeGenerator::emitGetGlobalPrivate(RegisterID* dst, const Ident > > RegisterID* BytecodeGenerator::emitGetEnumerableLength(RegisterID* dst, RegisterID* base) > { >- emitOpcode(op_get_enumerable_length); >- instructions().append(dst->index()); >- instructions().append(base->index()); >+ OpGetEnumerableLength::emit(this, dst, base); > return dst; > } > > RegisterID* BytecodeGenerator::emitHasGenericProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName) > { >- emitOpcode(op_has_generic_property); >- instructions().append(dst->index()); >- instructions().append(base->index()); >- instructions().append(propertyName->index()); >+ OpHasGenericProperty::emit(this, dst, base, property); > return dst; > } > > RegisterID* BytecodeGenerator::emitHasIndexedProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName) > { >- UnlinkedArrayProfile arrayProfile = newArrayProfile(); >- emitOpcode(op_has_indexed_property); >- instructions().append(dst->index()); >- instructions().append(base->index()); >- instructions().append(propertyName->index()); >- instructions().append(arrayProfile); >+ OpHasIndexedProperty::emit(this, dst, base, propertyName); > return dst; > } > > RegisterID* BytecodeGenerator::emitHasStructureProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName, RegisterID* enumerator) > { >- emitOpcode(op_has_structure_property); >- instructions().append(dst->index()); >- instructions().append(base->index()); >- instructions().append(propertyName->index()); >- instructions().append(enumerator->index()); >+ OpHasStructureProperty::emit(this, dst, base, propertyName, enumerator); > return dst; > } > > RegisterID* BytecodeGenerator::emitGetPropertyEnumerator(RegisterID* dst, RegisterID* base) > { >- emitOpcode(op_get_property_enumerator); >- instructions().append(dst->index()); >- instructions().append(base->index()); >+ OpGetPropertyEnumerator::emit(this, dst, base); > return dst; > } > > RegisterID* BytecodeGenerator::emitEnumeratorStructurePropertyName(RegisterID* dst, RegisterID* enumerator, RegisterID* index) > { >- emitOpcode(op_enumerator_structure_pname); >- instructions().append(dst->index()); >- instructions().append(enumerator->index()); >- instructions().append(index->index()); >+ OpEnumeratorStructurePname::emit(this, dst, enumerator, index); > return dst; > } > > RegisterID* BytecodeGenerator::emitEnumeratorGenericPropertyName(RegisterID* dst, RegisterID* enumerator, RegisterID* index) > { >- emitOpcode(op_enumerator_generic_pname); >- instructions().append(dst->index()); >- instructions().append(enumerator->index()); >- instructions().append(index->index()); >+ OpEnumeratorGenericPname::emit(this, dst, enumerator, index); > return dst; > } > > RegisterID* BytecodeGenerator::emitToIndexString(RegisterID* dst, RegisterID* index) > { >- emitOpcode(op_to_index_string); >- instructions().append(dst->index()); >- instructions().append(index->index()); >+ OpToIndexString::emit(this, dst, index); > return dst; > } > > RegisterID* BytecodeGenerator::emitIsCellWithType(RegisterID* dst, RegisterID* src, JSType type) > { >- emitOpcode(op_is_cell_with_type); >- instructions().append(dst->index()); >- instructions().append(src->index()); >- instructions().append(type); >+ OpIsCellWithType::emit(this, dst, src, type); > return dst; > } > > RegisterID* BytecodeGenerator::emitIsObject(RegisterID* dst, RegisterID* src) > { >- emitOpcode(op_is_object); >- instructions().append(dst->index()); >- instructions().append(src->index()); >+ OpIsObject::emit(this, dst, src); > return dst; > } > > RegisterID* BytecodeGenerator::emitIsNumber(RegisterID* dst, RegisterID* src) > { >- emitOpcode(op_is_number); >- instructions().append(dst->index()); >- instructions().append(src->index()); >+ OpIsNumber::emit(this, dst, src); > return dst; > } > > RegisterID* BytecodeGenerator::emitIsUndefined(RegisterID* dst, RegisterID* src) > { >- emitOpcode(op_is_undefined); >- instructions().append(dst->index()); >- instructions().append(src->index()); >+ OpIsUndefined::emit(this, dst, src); > return dst; > } > > RegisterID* BytecodeGenerator::emitIsEmpty(RegisterID* dst, RegisterID* src) > { >- emitOpcode(op_is_empty); >- instructions().append(dst->index()); >- instructions().append(src->index()); >+ OpIsEmpty::emit(this, dst, src); > return dst; > } > >@@ -4771,14 +4362,9 @@ void BytecodeGenerator::invalidateForInContextForLocal(RegisterID* localRegister > RegisterID* BytecodeGenerator::emitRestParameter(RegisterID* result, unsigned numParametersToSkip) > { > RefPtr<RegisterID> restArrayLength = newTemporary(); >- emitOpcode(op_get_rest_length); >- instructions().append(restArrayLength->index()); >- instructions().append(numParametersToSkip); >+ OpGetRestLength::emit(this, restArrayLength, numParametersToSkip); > >- emitOpcode(op_create_rest); >- instructions().append(result->index()); >- instructions().append(restArrayLength->index()); >- instructions().append(numParametersToSkip); >+ OpCreateRest::emit(this, result, restArrayLength, numParametersToSkip); > > return result; > } >@@ -4789,9 +4375,7 @@ void BytecodeGenerator::emitRequireObjectCoercible(RegisterID* value, const Stri > // thus incorrectly throws a TypeError for interfaces like HTMLAllCollection. > Ref<Label> target = newLabel(); > size_t begin = instructions().size(); >- emitOpcode(op_jneq_null); >- instructions().append(value->index()); >- instructions().append(target->bind(begin, instructions().size())); >+ OpJneqNull::emit(this, value, target->bind(begin, instruction().size())); > emitThrowTypeError(error); > emitLabel(target.get()); > } >@@ -4822,10 +4406,7 @@ void BytecodeGenerator::emitYieldPoint(RegisterID* argument, JSAsyncGeneratorFun > Vector<TryContext> savedTryContextStack; > m_tryContextStack.swap(savedTryContextStack); > >- emitOpcode(op_yield); >- instructions().append(generatorFrameRegister()->index()); >- instructions().append(yieldPointIndex); >- instructions().append(argument->index()); >+ OpYield::emit(this, generatorFrameRegister(), yieldPointIndex, argument); > > // Restore the try contexts, which start offset is updated to the merge point. > m_tryContextStack.swap(savedTryContextStack); >@@ -5241,11 +4822,8 @@ void IndexedForInContext::finalize(BytecodeGenerator& generator) > void BytecodeGenerator::emitToThis() > { > m_codeBlock->addPropertyAccessInstruction(instructions().size()); >- UnlinkedValueProfile profile = emitProfiledOpcode(op_to_this); >- instructions().append(kill(&m_thisRegister)); >- instructions().append(0); >- instructions().append(0); >- instructions().append(profile); >+ >+ OpToThis::emit(this, kill(&m_thisRegister)); > } > > } // namespace JSC >diff --git a/Source/JavaScriptCore/bytecompiler/Label.h b/Source/JavaScriptCore/bytecompiler/Label.h >index 3e2d297f23d105c15984011a0f55a33574df053a..732955deb80ee710faa65cf402ff64846b6f13bf 100644 >--- a/Source/JavaScriptCore/bytecompiler/Label.h >+++ b/Source/JavaScriptCore/bytecompiler/Label.h >@@ -44,6 +44,29 @@ namespace JSC { > > void setLocation(BytecodeGenerator&, unsigned); > >+ Label& bind(BytecodeGenerator* generator, offset) >+ { >+ m_opcode = generator->instructions().size(); >+ m_offset = offset; >+ } >+ >+ int compute(size_t width) >+ { >+ return m_location - m_opcode; >+ } >+ >+ int compute(size_t width) >+ { >+ ASSERT(!m_bound); >+ m_bound = true; >+ if (m_location == invalidLocation) { >+ m_unresolvedJumps.append(std::make_pair(m_opcode, m_opcode + m_offset * width + Fits::padding(width))); >+ return 0; >+ } >+ return m_location - m_opcode; >+ >+ } >+ > int bind(int opcode, int offset) const > { > m_bound = true; >diff --git a/Source/JavaScriptCore/interpreter/Interpreter.h b/Source/JavaScriptCore/interpreter/Interpreter.h >index 49227ebe515663ffde03c9e0a3fcb64967a0f568..d672b4a84725c22c0b733cc24aa1ff92bfe5de80 100644 >--- a/Source/JavaScriptCore/interpreter/Interpreter.h >+++ b/Source/JavaScriptCore/interpreter/Interpreter.h >@@ -104,6 +104,7 @@ namespace JSC { > static inline OpcodeID getOpcodeID(Opcode); > static inline OpcodeID getOpcodeID(const Instruction&); > static inline OpcodeID getOpcodeID(const UnlinkedInstruction&); >+ static inline OpcodeID getOpcodeID(OpcodeID); > > #if !ASSERT_DISABLED > static bool isOpcode(Opcode); >diff --git a/Source/JavaScriptCore/interpreter/InterpreterInlines.h b/Source/JavaScriptCore/interpreter/InterpreterInlines.h >index fc89a189d6057d8e4e0ab10a8791f856b49f9071..5e58ffffa40543d8c9fbbddf74bfd03e11d124c2 100644 >--- a/Source/JavaScriptCore/interpreter/InterpreterInlines.h >+++ b/Source/JavaScriptCore/interpreter/InterpreterInlines.h >@@ -65,7 +65,7 @@ inline OpcodeID Interpreter::getOpcodeID(Opcode opcode) > > inline OpcodeID Interpreter::getOpcodeID(const Instruction& instruction) > { >- return getOpcodeID(instruction.u.opcode); >+ return static_cast<OpcodeID>(instruction.u.unsignedValue); > } > > inline OpcodeID Interpreter::getOpcodeID(const UnlinkedInstruction& instruction) >@@ -73,6 +73,11 @@ inline OpcodeID Interpreter::getOpcodeID(const UnlinkedInstruction& instruction) > return instruction.u.opcode; > } > >+inline OpcodeID Interpreter::getOpcodeID(OpcodeID opcode) >+{ >+ return opcode; >+} >+ > ALWAYS_INLINE JSValue Interpreter::execute(CallFrameClosure& closure) > { > VM& vm = *closure.vm; >diff --git a/Source/JavaScriptCore/llint/LLIntData.h b/Source/JavaScriptCore/llint/LLIntData.h >index be58c00ae5c66ac30581ae3d4849428e5bb301d0..3937f33a15fc8fffbab69e8469ca2f5d05ad1b60 100644 >--- a/Source/JavaScriptCore/llint/LLIntData.h >+++ b/Source/JavaScriptCore/llint/LLIntData.h >@@ -83,9 +83,7 @@ inline Opcode getOpcode(OpcodeID id) > template<PtrTag tag> > ALWAYS_INLINE MacroAssemblerCodePtr<tag> getCodePtr(OpcodeID opcodeID) > { >- void* address = reinterpret_cast<void*>(getOpcode(opcodeID)); >- address = retagCodePtr<BytecodePtrTag, tag>(address); >- return MacroAssemblerCodePtr<tag>::createFromExecutableAddress(address); >+ return MacroAssemblerCodePtr<tag>::createFromExecutableAddress((void*)opcodeID); > } > > template<PtrTag tag> >@@ -109,7 +107,7 @@ ALWAYS_INLINE LLIntCode getCodeFunctionPtr(OpcodeID opcodeID) > #else > ALWAYS_INLINE void* getCodePtr(OpcodeID id) > { >- return reinterpret_cast<void*>(getOpcode(id)); >+ return reinterpret_cast<void*>(id); > } > #endif > >diff --git a/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp b/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp >index f2e411f8da89cfa10a3832e41cc1c5a650f456d1..653124ba25aabbedf0c4a133fecb295ad2d19182 100644 >--- a/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp >+++ b/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp >@@ -237,7 +237,7 @@ extern "C" SlowPathReturnType llint_trace_operand(ExecState* exec, Instruction* > exec->codeBlock(), > exec, > static_cast<intptr_t>(exec->codeBlock()->bytecodeOffset(pc)), >- Interpreter::getOpcodeID(pc[0].u.opcode), >+ pc[0].u.opcode, > fromWhere, > operand, > pc[operand].u.operand); >@@ -264,7 +264,7 @@ extern "C" SlowPathReturnType llint_trace_value(ExecState* exec, Instruction* pc > exec->codeBlock(), > exec, > static_cast<intptr_t>(exec->codeBlock()->bytecodeOffset(pc)), >- Interpreter::getOpcodeID(pc[0].u.opcode), >+ pc[0].u.opcode, > fromWhere, > operand, > pc[operand].u.operand, >@@ -327,7 +327,7 @@ LLINT_SLOW_PATH_DECL(trace) > if (!Options::traceLLIntExecution()) > LLINT_END_IMPL(); > >- OpcodeID opcodeID = Interpreter::getOpcodeID(pc[0].u.opcode); >+ OpcodeID opcodeID = pc[0].u.opcode; > dataLogF("<%p> %p / %p: executing bc#%zu, %s, pc = %p\n", > &Thread::current(), > exec->codeBlock(), >@@ -726,13 +726,13 @@ static void setupGetByIdPrototypeCache(ExecState* exec, VM& vm, Instruction* pc, > ConcurrentJSLocker locker(codeBlock->m_lock); > > if (slot.isUnset()) { >- pc[0].u.opcode = LLInt::getOpcode(op_get_by_id_unset); >+ pc[0].u.unsignedValue = op_get_by_id_unset; > pc[4].u.structureID = structure->id(); > return; > } > ASSERT(slot.isValue()); > >- pc[0].u.opcode = LLInt::getOpcode(op_get_by_id_proto_load); >+ pc[0].u.unsignedValue = op_get_by_id_proto_load; > pc[4].u.structureID = structure->id(); > pc[5].u.operand = offset; > // We know that this pointer will remain valid because it will be cleared by either a watchpoint fire or >@@ -760,7 +760,7 @@ LLINT_SLOW_PATH_DECL(slow_path_get_by_id) > { > StructureID oldStructureID = pc[4].u.structureID; > if (oldStructureID) { >- auto opcode = Interpreter::getOpcodeID(pc[0]); >+ auto opcode = pc[0].u.opcode; > if (opcode == op_get_by_id > || opcode == op_get_by_id_unset > || opcode == op_get_by_id_proto_load) { >@@ -779,7 +779,7 @@ LLINT_SLOW_PATH_DECL(slow_path_get_by_id) > Structure* structure = baseCell->structure(vm); > if (slot.isValue() && slot.slotBase() == baseValue) { > // Start out by clearing out the old cache. >- pc[0].u.opcode = LLInt::getOpcode(op_get_by_id); >+ pc[0].u.unsignedValue = op_get_by_id; > pc[4].u.pointer = nullptr; // old structure > pc[5].u.pointer = nullptr; // offset > >@@ -804,7 +804,7 @@ LLINT_SLOW_PATH_DECL(slow_path_get_by_id) > } else if (!LLINT_ALWAYS_ACCESS_SLOW > && isJSArray(baseValue) > && ident == vm.propertyNames->length) { >- pc[0].u.opcode = LLInt::getOpcode(op_get_array_length); >+ pc[0].u.unsignedValue = op_get_array_length; > ArrayProfile* arrayProfile = codeBlock->getOrAddArrayProfile(codeBlock->bytecodeOffset(pc)); > arrayProfile->observeStructure(baseValue.asCell()->structure(vm)); > pc[4].u.arrayProfile = arrayProfile; >diff --git a/Source/JavaScriptCore/llint/LowLevelInterpreter.cpp b/Source/JavaScriptCore/llint/LowLevelInterpreter.cpp >index 78bff0884c4802939a4de860f76b582eaa9a4265..828fc4f85ac7495a75f5cf9b4ae8fb6d68669ebd 100644 >--- a/Source/JavaScriptCore/llint/LowLevelInterpreter.cpp >+++ b/Source/JavaScriptCore/llint/LowLevelInterpreter.cpp >@@ -108,13 +108,20 @@ using namespace JSC::LLInt; > > #define OFFLINE_ASM_GLOBAL_LABEL(label) label: USE_LABEL(label); > >+#if ENABLE(LABEL_TRACING) >+#define TRACE_LABEL(prefix, label) dataLog(#prefix, ": ", #label, "\n") >+#else >+#define TRACE_LABEL(prefix, label) do { } while (false); >+#endif >+ >+ > #if ENABLE(COMPUTED_GOTO_OPCODES) >-#define OFFLINE_ASM_GLUE_LABEL(label) label: USE_LABEL(label); >+#define OFFLINE_ASM_GLUE_LABEL(label) label: TRACE_LABEL("OFFLINE_ASM_GLUE_LABEL", label); USE_LABEL(label); > #else > #define OFFLINE_ASM_GLUE_LABEL(label) case label: label: USE_LABEL(label); > #endif > >-#define OFFLINE_ASM_LOCAL_LABEL(label) label: USE_LABEL(label); >+#define OFFLINE_ASM_LOCAL_LABEL(label) label: TRACE_LABEL("OFFLINE_ASM_LOCAL_LABEL", #label); USE_LABEL(label); > > > //============================================================================ >@@ -238,7 +245,7 @@ struct CLoopRegister { > EncodedJSValue encodedJSValue; > double castToDouble; > #endif >- Opcode opcode; >+ OpcodeID opcode; > }; > > operator ExecState*() { return execState; } >@@ -288,8 +295,8 @@ JSValue CLoop::execute(OpcodeID entryOpcodeID, void* executableAddress, VM* vm, > // can depend on the opcodeMap. > Instruction* exceptionInstructions = LLInt::exceptionInstructions(); > for (int i = 0; i < maxOpcodeLength + 1; ++i) >- exceptionInstructions[i].u.pointer = >- LLInt::getCodePtr(llint_throw_from_slow_path_trampoline); >+ exceptionInstructions[i].u.unsignedValue = >+ llint_throw_from_slow_path_trampoline; > > return JSValue(); > } >@@ -353,7 +360,7 @@ JSValue CLoop::execute(OpcodeID entryOpcodeID, void* executableAddress, VM* vm, > CLoopStack& cloopStack = vm->interpreter->cloopStack(); > StackPointerScope stackPointerScope(cloopStack); > >- lr.opcode = getOpcode(llint_return_to_host); >+ lr.opcode = llint_return_to_host; > sp.vp = cloopStack.currentStackPointer(); > cfr.callFrame = vm->topCallFrame; > #ifndef NDEBUG >@@ -376,7 +383,7 @@ JSValue CLoop::execute(OpcodeID entryOpcodeID, void* executableAddress, VM* vm, > // Interpreter variables for value passing between opcodes and/or helpers: > NativeFunction nativeFunc = nullptr; > JSValue functionReturnValue; >- Opcode opcode = getOpcode(entryOpcodeID); >+ OpcodeID opcode = entryOpcodeID; > > #define PUSH(cloopReg) \ > do { \ >@@ -399,7 +406,7 @@ JSValue CLoop::execute(OpcodeID entryOpcodeID, void* executableAddress, VM* vm, > #if USE(JSVALUE32_64) > #define FETCH_OPCODE() pc.opcode > #else // USE(JSVALUE64) >-#define FETCH_OPCODE() *bitwise_cast<Opcode*>(pcBase.i8p + pc.i * 8) >+#define FETCH_OPCODE() *bitwise_cast<OpcodeID*>(pcBase.i8p + pc.i * 8) > #endif // USE(JSVALUE64) > > #define NEXT_INSTRUCTION() \ >@@ -413,7 +420,7 @@ JSValue CLoop::execute(OpcodeID entryOpcodeID, void* executableAddress, VM* vm, > //======================================================================== > // Loop dispatch mechanism using computed goto statements: > >- #define DISPATCH_OPCODE() goto *opcode >+ #define DISPATCH_OPCODE() goto *getOpcode(opcode); > > #define DEFINE_OPCODE(__opcode) \ > __opcode: \ >diff --git a/Source/JavaScriptCore/offlineasm/cloop.rb b/Source/JavaScriptCore/offlineasm/cloop.rb >index 870525922f02a4447e8732f99a0d8bfe5d186cc4..9dd818dc623d7e7f02e2384e5649a0fa04525324 100644 >--- a/Source/JavaScriptCore/offlineasm/cloop.rb >+++ b/Source/JavaScriptCore/offlineasm/cloop.rb >@@ -222,7 +222,7 @@ class Address > "*CAST<NativeFunction*>(#{pointerExpr})" > end > def opcodeMemRef >- "*CAST<Opcode*>(#{pointerExpr})" >+ "*CAST<OpcodeID*>(#{pointerExpr})" > end > def dblMemRef > "*CAST<double*>(#{pointerExpr})" >@@ -286,7 +286,7 @@ class BaseIndex > "*CAST<uintptr_t*>(#{pointerExpr})" > end > def opcodeMemRef >- "*CAST<Opcode*>(#{pointerExpr})" >+ "*CAST<OpcodeID*>(#{pointerExpr})" > end > def dblMemRef > "*CAST<double*>(#{pointerExpr})" >@@ -1077,7 +1077,7 @@ class Instruction > # as an opcode dispatch. > when "cloopCallJSFunction" > uid = $asm.newUID >- $asm.putc "lr.opcode = getOpcode(llint_cloop_did_return_from_js_#{uid});" >+ $asm.putc "lr.opcode = llint_cloop_did_return_from_js_#{uid};" > $asm.putc "opcode = #{operands[0].clValue(:opcode)};" > $asm.putc "DISPATCH_OPCODE();" > $asm.putsLabel("llint_cloop_did_return_from_js_#{uid}", false) >diff --git a/Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.cpp b/Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.cpp >index 6e93ce810011618e8d4c8b80e670d83e8e18a129..f5054f8aa8fe08f49b8848ee5503900991620ae9 100644 >--- a/Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.cpp >+++ b/Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.cpp >@@ -55,7 +55,7 @@ BytecodeSequence::BytecodeSequence(CodeBlock* codeBlock) > for (unsigned bytecodeIndex = 0; bytecodeIndex < codeBlock->instructions().size();) { > out.reset(); > codeBlock->dumpBytecode(out, bytecodeIndex, statusMap); >- OpcodeID opcodeID = Interpreter::getOpcodeID(codeBlock->instructions()[bytecodeIndex].u.opcode); >+ OpcodeID opcodeID = codeBlock->instructions()[bytecodeIndex].u.opcode; > m_sequence.append(Bytecode(bytecodeIndex, opcodeID, out.toCString())); > bytecodeIndex += opcodeLength(opcodeID); > } >diff --git a/Source/JavaScriptCore/wip_bytecode/BytecodeList.rb b/Source/JavaScriptCore/wip_bytecode/BytecodeList.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..25911921466b3e9af97aebefcd7a8849acee408e >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/BytecodeList.rb >@@ -0,0 +1,1084 @@ >+types [ >+ :Register, >+ :Constant, >+ >+ :BasicBlockLocation, >+ :DebugHookType, >+ :ErrorType, >+ :GetPutInfo, >+ :JSCell, >+ :JSGlobalLexicalEnvironment, >+ :JSGlobalObject, >+ :JSObject, >+ :JSType, >+ :LLIntCallLinkInfo, >+ :ProfileTypeBytecodeFlag, >+ :PutByIdFlags, >+ :ResolveType, >+ :ScopeOffset, >+ :Structure, >+ :StructureID, >+ :StructureChain, >+ :ToThisStatus, >+ :TypeLocation, >+ >+ :ValueProfile, >+ :ValueProfileAndOperandBuffer, >+ :ArithProfile, >+ :ArrayProfile, >+ :ArrayAllocationProfile, >+ :ObjectAllocationProfile, >+] >+ >+namespace :Special do >+ types [ :Pointer ] >+end >+ >+templates [ >+ :WriteBarrierBase, >+] >+ >+begin_section :Bytecodes, >+ emitInHFile: true, >+ emitInStructsFile: true, >+ emitInASMFile: true, >+ emitOpcodeIDStringValuesInHFile: true, >+ macroNameComponent: :BYTECODE, >+ asmPrefix: :llint_, >+ op_prefix: :op_ >+ >+op :enter >+ >+op :get_scope, >+ args: { >+ dst: Register >+ } >+ >+op :create_direct_arguments, >+ args: { >+ dst: Register, >+ } >+ >+op :create_scoped_arguments, >+ args: { >+ dst: Register, >+ scope: Register, >+ } >+ >+op :create_cloned_arguments, >+ args: { >+ dst: Register, >+ } >+ >+op :create_this, >+ args: { >+ dst: Register, >+ callee: Register, >+ inlineCapacity: unsigned, >+ }, >+ metadata: { >+ cachedCallee: WriteBarrierBase[JSCell] >+ } >+ >+op :get_argument, >+ args: { >+ dst: Register, >+ index: unsigned, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :argument_count, >+ args: { >+ dst: Register, >+ } >+ >+op :to_this, >+ args: { >+ this: Register, >+ }, >+ metadata: { >+ cachedStructure: WriteBarrierBase[Structure], >+ toThisStatus: ToThisStatus, >+ profile: ValueProfile, >+ } >+ >+op :check_tdz, >+ args: { >+ target: Register, >+ } >+ >+op :new_object, >+ args: { >+ dst: Register, >+ inlineCapacity: unsigned, >+ }, >+ metadata: { >+ allocationProfile: ObjectAllocationProfile, >+ } >+ >+op :new_array, >+ args: { >+ dst: Register, >+ argv?: Register, >+ argc: unsigned, >+ }, >+ metadata: { >+ allocationProfile: ArrayAllocationProfile, >+ } >+ >+op :new_array_with_size, >+ args: { >+ dst: Register, >+ length: unsigned, >+ }, >+ metadata: { >+ allocationProfile: ArrayAllocationProfile, >+ } >+ >+op :new_array_buffer, >+ args: { >+ dst: Register, >+ immutableButterfly: Constant, >+ }, >+ metadata: { >+ allocationProfile: ArrayAllocationProfile, >+ } >+ >+op :new_array_with_spread, >+ args: { >+ dst: Register, >+ argv?: Register, >+ argc: unsigned, >+ bitVector: unsigned, # this could have type BitVector& if the instruction has a reference to the codeblock >+ } >+ >+op :spread, >+ args: { >+ dst: Register, >+ argument: Register, >+ } >+ >+op :new_regexp, >+ args: { >+ dst: Register, >+ regexp: unsigned, # this could have type RegExp the instruction has a reference to the codeblock >+ } >+ >+op :mov, # damnit this is in reverse order to llint >+ args: { >+ dst: Register, >+ src: Register, >+ } >+ >+op :not, >+ args: { >+ dst: Register, >+ operand: Register, >+ } >+ >+op_group :BinaryOp, >+ [ >+ :eq, >+ :neq, >+ :stricteq, >+ :nstricteq, >+ :less, >+ :lesseq, >+ :greater, >+ :greatereq, >+ :below, >+ :beloweq, >+ :mod, >+ :pow, >+ :lshift, >+ :rshift, >+ :urshift, >+ ], >+ args: { >+ dst: Register, >+ lhs: Register, >+ rhs: Register, >+ } >+ >+op_group :ProfiledBinaryOp, >+ [ >+ :add, >+ :mul, >+ :div, >+ :sub, >+ :bitand, >+ :bitxor, >+ :bitor, >+ ], >+ args: { >+ dst: Register, >+ lhs: Register, >+ rhs: Register, >+ }, >+ metadata: { >+ arithProfile: :ArithProfile >+ } >+ >+op_group :UnaryOp, >+ [ >+ :eq_null, >+ :neq_null, >+ :to_string, >+ :unsigned, >+ :is_empty, >+ :is_undefined, >+ :is_boolean, >+ :is_number, >+ :is_object, >+ :is_object_or_null, >+ :is_function, >+ ], >+ args: { >+ dst: Register, >+ operand: Register, >+ } >+ >+op :to_number, >+ args: { >+ dst: Register, >+ operand: Register, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :inc, >+ args: { >+ srcDst: Register, >+ } >+ >+op :dec, >+ args: { >+ srcDst: Register, >+ } >+ >+op :to_object, >+ args: { >+ dst: Register, >+ operand: Register, >+ message: Constant, # Constants could possibly also have their final type >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :negate, >+ args: { >+ dst: Register, >+ operand: Register, >+ }, >+ metadata: { >+ arithProfile: ArithProfile, >+ } >+ >+op :identity_with_profile, >+ args: { >+ src: Register, >+ topProfile: unsigned, >+ bottomProfile: unsigned, >+ } >+ >+op :overrides_has_instance, >+ args: { >+ dst: Register, >+ constructor: Register, >+ hasInstanceValue: Register, >+ } >+ >+op :instanceof, >+ args: { >+ dst: Register, >+ value: Register, >+ prototype: Register, >+ } >+ >+op :instanceof_custom, >+ args: { >+ dst: Register, >+ value: Register, >+ constructor: Register, >+ hasInstanceValue: Register, >+ } >+ >+op :typeof, >+ args: { >+ dst: Register, >+ value: Register, >+} >+ >+op :is_cell_with_type, >+ args: { >+ dst: Register, >+ value: Register, >+ type: JSType, >+ } >+ >+op :in_by_val, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ } >+ >+op :in_by_id, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ } >+ >+# NOTE: get_by_id variants >+# they all used to have to share the same size, in order to store all the metadata >+# for all the variants - this should no longer be necessary, since the metadata is >+# stored out-of-line, but has to be confirmed later on >+# we should also consider whether we want to keep modifying the bytecode stream >+# throughout execution, because otherwise we'll need an alternative way of specializing >+# get_by_id >+op :get_array_length, # special - never emitted >+ args: { >+ dst: Register, >+ base: Register, # must be a JSArray >+ property: Constant, # always "length" >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ } >+ >+op :get_by_id, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Constant, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ hitCountForLLIntCaching: unsigned, >+ } >+ >+op :get_by_id_proto_load, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Constant, >+ structure: StructureID, >+ slot: JSObject, >+ } >+ >+op :get_by_id_unset, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Constant, >+ structure: StructureID, >+ } >+ >+op :get_by_id_with_this, >+ args: { >+ dst: Register, >+ base: Register, >+ this: Register, >+ property: Constant, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :get_by_val_with_this, >+ args: { >+ dst: Register, >+ base: Register, >+ this: Register, >+ property: Constant, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :get_by_id_direct, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Constant, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ structure: StructureID, >+ offset: unsigned, >+ } >+ >+op :try_get_by_id, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Constant, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :put_by_id, >+ args: { >+ base: Register, >+ property: Constant, >+ value: Register, >+ }, >+ metadata: { >+ oldStructure: StructureID, >+ offset: unsigned, >+ newStructure: StructureID, >+ structureChain: WriteBarrierBase[StructureChain], >+ flags: PutByIdFlags, >+ } >+ >+op :put_by_id_with_this, >+ args: { >+ base: Register, >+ this: Register, >+ property: Constant, >+ value: Register, >+ } >+ >+op :del_by_id, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Constant, >+ } >+ >+op :get_by_val, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Constant, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ arrayProfile: ArrayProfile, >+ } >+ >+op :put_by_val, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ } >+ >+op :put_by_val_with_this, >+ args: { >+ base: Register, >+ this: Register, >+ property: Register, >+ value: Register, >+ } >+ >+op :put_by_val_direct, >+ args: { >+ base: Register, >+ property: Register, >+ value: Register, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ } >+ >+op :del_by_val, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ } >+ >+op :put_getter_by_id, >+ args: { >+ base: Register, >+ property: Constant, >+ attributes: unsigned, >+ getter: Register, >+ } >+ >+op :put_setter_by_id, >+ args: { >+ base: Register, >+ property: Constant, >+ attributes: unsigned, >+ setter: Register, >+ } >+ >+op :put_getter_setter_by_id, >+ args: { >+ base: Register, >+ property: Constant, >+ attributes: unsigned, >+ getter: Register, >+ setter: Register, >+ } >+ >+op :put_getter_by_val, >+ args: { >+ base: Register, >+ property: Register, >+ attributes: unsigned, >+ getter: Register, >+ } >+ >+op :put_setter_by_val, >+ args: { >+ base: Register, >+ property: Register, >+ attributes: unsigned, >+ setter: Register, >+ } >+ >+op :define_data_property, >+ args: { >+ base: Register, >+ property: Register, >+ value: Register, >+ attributes: Register, >+ } >+ >+op :define_accessor_property, >+ args: { >+ base: Register, >+ property: Register, >+ getter: Register, >+ setter: Register, >+ attributes: Register, >+ } >+ >+op :jmp, >+ args: { >+ target: int, >+ } >+ >+op :jtrue, >+ args: { >+ condition: Register, >+ target: int, >+ } >+ >+op :jfalse, >+ args: { >+ condition: Register, >+ target: int, >+ } >+ >+op :jeq_null, >+ args: { >+ condition: Register, >+ target: int, >+ } >+ >+op :jneq_null, >+ args: { >+ condition: Register, >+ target: int, >+ } >+ >+op :jneq_ptr, >+ args: { >+ condition: Register, >+ specialPointer: Special::Pointer, >+ target: int, >+ }, >+ metadata: { >+ hasJumped: bool, >+ } >+ >+op_group :BinaryJmp, >+ [ >+ :jeq, >+ :jstricteq, >+ :jneq, >+ :jnstricteq, >+ :jless, >+ :jlesseq, >+ :jgreater, >+ :jgreatereq, >+ :jnless, >+ :jnlesseq, >+ :jngreater, >+ :jngreatereq, >+ :jbelow, >+ :jbeloweq, >+ ], >+ args: { >+ lhs: Register, >+ rhs: Register, >+ target: int, >+ } >+ >+op :loop_hint >+ >+op_group :SwitchValue, >+ [ >+ :switch_imm, >+ :switch_char, >+ :switch_string, >+ ], >+ args: { >+ tableIndex: int, >+ defaultOffset: int, >+ scrutinee: Register, >+ } >+ >+op_group :NewFunction, >+ [ >+ :new_func, >+ :new_func_exp, >+ :new_generator_func, >+ :new_generator_func_exp, >+ :new_async_func, >+ :new_async_func_exp, >+ :new_async_generator_func, >+ :new_async_generator_func_exp, >+ ], >+ args: { >+ dst: Register, >+ scope: Register, >+ functionDecl: int, >+ } >+ >+op :set_function_name, >+ args: { >+ function: Register, >+ name: Register, >+ } >+ >+# op_call variations >+op :call, >+ args: { >+ dst: Register, >+ callee: Register, >+ argc: unsigned, >+ argv: unsigned, >+ }, >+ metadata: { >+ callLinkInfo: LLIntCallLinkInfo, >+ # ? there was an extra slot here >+ arrayProfile: ArrayProfile, >+ profile: ValueProfile, >+ } >+ >+op :tail_call, >+ args: { >+ dst: Register, >+ callee: Register, >+ argc: unsigned, >+ argv: unsigned, >+ }, >+ metadata: { >+ callLinkInfo: LLIntCallLinkInfo, >+ # ? there was an extra slot here >+ arrayProfile: ArrayProfile, >+ profile: ValueProfile, >+ } >+ >+op :call_eval, >+ args: { >+ dst: Register, >+ callee: Register, >+ argc: unsigned, >+ argv: unsigned, >+ }, >+ metadata: { >+ callLinkInfo: LLIntCallLinkInfo, >+ # ? there was an extra slot here >+ arrayProfile: ArrayProfile, >+ profile: ValueProfile, >+ } >+ >+op :call_varargs, >+ args: { >+ dst: Register, >+ callee: Register, >+ this?: Register, >+ arguments?: Register, >+ firstFree: Register, >+ firstVarArg: int, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ profile: ValueProfile, >+ } >+ >+op :tail_call_varargs, >+ args: { >+ dst: Register, >+ callee: Register, >+ this?: Register, >+ arguments?: Register, >+ firstFree: Register, >+ firstVarArg: int, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ profile: ValueProfile, >+ } >+ >+op :tail_call_forward_arguments, >+ args: { >+ dst: Register, >+ callee: Register, >+ this?: Register, >+ arguments?: Register, >+ firstFree: Register, >+ firstVarArg: int, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ profile: ValueProfile, >+ } >+ >+op :construct, >+ args: { >+ dst: Register, >+ function: Register, >+ argc: unsigned, >+ argv: unsigned, >+ }, >+ metadata: { >+ callLinkInfo: LLIntCallLinkInfo, >+ # ? there was an extra slot here >+ # ? empty slot here >+ profile: ValueProfile, >+ } >+ >+op :construct_varargs, >+ args: { >+ dst: Register, >+ callee: Register, >+ this?: Register, >+ arguments?: Register, >+ firstFree: Register, >+ firstVarArg: int, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ profile: ValueProfile, >+ } >+ >+op :ret, >+ args: { >+ value: Register, >+ } >+ >+op :strcat, >+ args: { >+ dst: Register, >+ src: Register, >+ count: int, >+ } >+ >+op :to_primitive, >+ args: { >+ dst: Register, >+ src: Register, >+ } >+ >+op :resolve_scope, >+ args: { >+ dst: Register, >+ scope: Register, >+ var: Constant, >+ type: ResolveType, >+ localScopeDepth: int, >+ }, >+ metadata: { >+ globalObject: JSGlobalObject.*, >+ globalLexicalEnvironment: JSGlobalLexicalEnvironment.*, >+ } >+ >+op :get_from_scope, >+ args: { >+ dst: Register, >+ scope: Register, >+ var: Constant, >+ getPutInfo: GetPutInfo, >+ localScopeDepth: int, >+ variableOffset?: unsigned, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :put_to_scope, >+ args: { >+ scope: Register, >+ var: Constant, >+ value: Register, >+ getPutInfo: GetPutInfo, >+ depthOrSymbolTableIndex: unsigned, >+ scopeOffset?: ScopeOffset, >+ } >+ >+op :get_from_arguments, >+ args: { >+ dst: Register, >+ scope: Register, >+ offset: unsigned, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :put_to_arguments, >+ args: { >+ scope: Register, >+ offset: unsigned, >+ value: Register, >+ } >+ >+op :push_with_scope, >+ args: { >+ dst: Register, >+ currentScope: Register, >+ newScope: Register, >+ } >+ >+op :create_lexical_environment, >+ args: { >+ dst: Register, >+ scope: Register, >+ symbolTable: Register, >+ initialValue: Register, >+ } >+ >+op :get_parent_scope, >+ args: { >+ dst: Register, >+ scope: Register, >+ } >+ >+op :catch, >+ args: { >+ exception: Register, >+ thrownValue: Register, >+ }, >+ metadata: { >+ buffer: ValueProfileAndOperandBuffer, >+ } >+ >+op :throw, >+ args: { >+ value: Register, >+ } >+ >+op :throw_static_error, >+ args: { >+ message: Register, >+ errorType: ErrorType, >+ } >+ >+op :debug, >+ args: { >+ debugHookType: DebugHookType, >+ hasBreakpoint: bool, >+ } >+ >+op :end, >+ args: { >+ value: Register, >+ } >+ >+op :profile_type, >+ args: { >+ target: Register, >+ flag: ProfileTypeBytecodeFlag, >+ identifier?: Constant, >+ resolveType: ResolveType, >+ }, >+ metadata: { >+ typeLocation: TypeLocation.*, >+ } >+ >+op :profile_control_flow, >+ args: { >+ textOffset: BasicBlockLocation.*, >+ } >+ >+op :get_enumerable_length, >+ args: { >+ dst: Register, >+ base: Register, >+ } >+ >+op :has_indexed_property, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ }, >+ metadata: { >+ arrayProfile: ArrayProfile, >+ } >+ >+op :has_structure_property, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ enumerator: Register, >+ } >+ >+op :has_generic_property, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ } >+ >+op :get_direct_pname, >+ args: { >+ dst: Register, >+ base: Register, >+ property: Register, >+ index: Register, >+ enumerator: Register, >+ }, >+ metadata: { >+ profile: ValueProfile, >+ } >+ >+op :get_property_enumerator, >+ args: { >+ dst: Register, >+ base: Register, >+ } >+ >+op :enumerator_structure_pname, >+ args: { >+ dst: Register, >+ enumerator: Register, >+ index: Register, >+ } >+ >+op :enumerator_generic_pname, >+ args: { >+ dst: Register, >+ enumerator: Register, >+ index: Register, >+ } >+ >+op :to_index_string, >+ args: { >+ dst: Register, >+ index: Register, >+ } >+ >+op :unreachable >+ >+op :create_rest, >+ args: { >+ dst: Register, >+ arraySize: unsigned, >+ numParametersToSkip: unsigned, >+ } >+ >+op :get_rest_length, >+ args: { >+ dst: Register, >+ numParametersToSkip: unsigned, >+ } >+ >+op :yield, >+ args: { >+ generator: Register, >+ yieldPoint: unsigned, >+ argument: Register, >+ } >+ >+op :check_traps >+ >+op :log_shadow_chicken_prologue, >+ args: { >+ scope: Register, >+ } >+ >+op :log_shadow_chicken_tail, >+ args: { >+ this: Register, >+ scope: Register, >+ } >+ >+op :resolve_scope_for_hoisting_func_decl_in_eval, >+ args: { >+ dst: Register, >+ scope: Register, >+ property: Constant, >+ } >+ >+op :nop >+ >+op :super_sampler_begin >+ >+op :super_sampler_end >+ >+end_section :Bytecodes >+ >+begin_section :CLoopHelpers, >+ emitInHFile: true, >+ emitInStructsFile: false, >+ emitInASMFile: false, >+ emitOpcodeIDStringValuesInHFile: false, >+ defaultLength: 1, >+ macroNameComponent: :CLOOP_BYTECODE_HELPER >+ >+op :llint_entry >+op :getHostCallReturnValue >+op :llint_return_to_host >+op :llint_vm_entry_to_javascript >+op :llint_vm_entry_to_native >+op :llint_cloop_did_return_from_js_1 >+op :llint_cloop_did_return_from_js_2 >+op :llint_cloop_did_return_from_js_3 >+op :llint_cloop_did_return_from_js_4 >+op :llint_cloop_did_return_from_js_5 >+op :llint_cloop_did_return_from_js_6 >+op :llint_cloop_did_return_from_js_7 >+op :llint_cloop_did_return_from_js_8 >+op :llint_cloop_did_return_from_js_9 >+op :llint_cloop_did_return_from_js_10 >+op :llint_cloop_did_return_from_js_11 >+op :llint_cloop_did_return_from_js_12 >+ >+end_section :CLoopHelpers >+ >+begin_section :NativeHelpers, >+ emitInHFile: true, >+ emitInStructsFile: false, >+ emitInASMFile: true, >+ emitOpcodeIDStringValuesInHFile: false, >+ defaultLength: 1, >+ macroNameComponent: :BYTECODE_HELPER >+ >+op :llint_program_prologue >+op :llint_eval_prologue >+op :llint_module_program_prologue >+op :llint_function_for_call_prologue >+op :llint_function_for_construct_prologue >+op :llint_function_for_call_arity_check >+op :llint_function_for_construct_arity_check >+op :llint_generic_return_point >+op :llint_throw_from_slow_path_trampoline >+op :llint_throw_during_call_trampoline >+op :llint_native_call_trampoline >+op :llint_native_construct_trampoline >+op :llint_internal_function_call_trampoline >+op :llint_internal_function_construct_trampoline >+op :handleUncaughtException >+ >+end_section :NativeHelpers >diff --git a/Source/JavaScriptCore/wip_bytecode/README.md b/Source/JavaScriptCore/wip_bytecode/README.md >new file mode 100644 >index 0000000000000000000000000000000000000000..dfd11654f7b196b89392d674711c5a383a4b74ab >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/README.md >@@ -0,0 +1,151 @@ >+# Bytecode format >+ >++--------------+ >+| header | >++==============+ >+| instruction0 | >++--------------+ >+| instruction1 | >++--------------+ >+| ... | >++--------------+ >+| instructionN | >++--------------+ >+ >+## Header >+ >++--------------+ >+|num_parameters| >++--------------+ >+| has_metadata | >++--------------+ >+| count_op1 | >++--------------+ >+| ... | >++--------------+ >+| count_opN | >++--------------+ >+| liveness | >++--------------+ >+| global_info | >++--------------+ >+| constants | >++--------------+ >+ >+* `has_metada` is a BitMap that indicates which opcodes need side table entries >+* `count_opI` is a varible length unsigned number that indicates how many entries are necessary for opcode I. >+ >+Given that we currently have < 256 opcodes, the BitMap should fit in 4 bytes. >+Of all opcodes, ~40 will currently ever need metadata, so that if the bytecode for any CodeBlock uses all of this opcodes, it would an extra 40~160b, depending on how many instances of each opcode appear in the bytecode. >+ >+## Instruction >+ >+Instructions have variable length, and have the form >+ >++-----------+------+-----+------+------------+ >+| opcode_id | arg0 | ... | argN | metadataID | >++-----------+------+-----+------+------------+ >+ >+where N <= 0 and metadataID is optional >+ >+### Narrow Instructions >+ >+By the default, we try to encode every instruction in a narrow setting, where every segment has 1-byte. However, we will fall back to a "Wide Instruction" whenever any of the arguments overflows, i.e.: >+ >+* opcode_id: we currently have 167 opcodes, so this won't be a problem for now but, hypothetically, any opcodes beyond id 256 will have to be encoded as a wide instruction. >+* arg: the type of the operand should never be ambiguous, therefore we support: >+ + up to 256 of each of the following: local registers, constants and arguments >+ + up to 8-byte types: we'll attempt to fit integers and unsigned integers in 8 bytes, otherwise fallback to a wide instruction. >+* up to 256 metadata entries per opcode, i.e. if an opcode has metadata, only 256 instances of the same opcode will fit into the same CodeBlock. >+ >+### Wide Instructions >+ >+Wide instructions have 4-byte segments, but otherwise indistinguishable from narrow instructions. >+ >+We reserve the first opcode to a trampoline that will evaluate the next instruction as a "Wide Instruction", where each segment of the instruction has 4 bytes. This opcode will also be responsible to guaranteeing 4-byte alignment on ARM. >+ >+## API >+ >+A class/struct will be generated for each opcode. The struct wil be responsible for: >+* Encoding, e.g. dumping the instruction into a binary format, and choosing between narrow or wide encoding >+* Providing access to each of the instruction's arguments and metadata >+* Potentially allow dumping the instruction, simplifying the work done by the BytecodeDumper >+ >+Here's what the API may look like for each of this operations, for e.g. the `op_get_argument` (this opcode should be a good example, since it has multiple argument types and metadata). Here is its current declaration (syntax may still change) >+ >+```ruby >+op :get_argument, >+ args: { >+ dst: :Register, >+ index: :unsigned, >+ }, >+ metadata: { >+ profile: :ValueProfile, >+ } >+``` >+ >+### Encoding >+ >+```cpp >+static void OpGetArgument::create(BytecodeGenerator& generator RegisterID* register, unsigned index); >+``` >+ >+ >+### Field Access >+ >+```cpp >+RegisterID OpGetArgument::dst(); >+unsigned OpGetArgument::index(); >+``` >+ >+### Metadata Acess >+```cpp >+ValueProfile* OpGetArgument::profile(ExecState&); >+``` >+ >+### BytecodeDumper >+ >+```cpp >+void OpGetArguments::dump(BytecodeDumper&); >+``` >+ >+### Decoding >+ >+Decoding should be done by the base instruction/reader class. >+ >+```cpp >+Instruction::Unknown* Instruction::read(UnlinkedInstructionStream::Reader&); >+``` >+ >+## "Linking" >+ >+Linking, in its current form, should no longer be necessary. Instead, it will consist of creating the side table for the bytecode metadata and ensuring that the jump table with the offset for each opcode has been initialized. >+ >+### Side table >+ >+A callee-saved register pointing to the current CodeBlock's can be kept at all times to speed up metadata accesses that are necessary specially for profiling. >+ >+### Jump table >+ >+A mapping from opcode IDs to opcode addresses is already generated in InitBytecodes.asm and loaded by LLIntData. >+ >+## Portability >+ >+Due to different alignment requirements, the bytecode should not portable across different platforms. >+Does enabling the JIT affect the bytecode? Possibly not, since it may only affect the metadata and not the bytecode itself, but TBC. >+ >+## Performance >+ >+Removing the linking step means that the interpreter will no longer be direct-threaded. Disabling COMPUTED_GOTO in CLoop (in order to disable direct threading) shows a 1% regression on PLT. >+ >+However, CLoop's fallback implementation is a switch statement, which affects branch prediction. >+ >+Alternatively, hacking JSC to skip replacing opcodes with their addresses during linking and modifying the dispatch macro in CLoop to fetch opcodes addresses shows a ~1% progression over CLoop with COMPUTED_GOTO enabled. >+ >+### get_by_id >+ >+`get_by_id` is the instruction that will require the most change, since we currently rewrite the bytecode stream to select from multiple implementations that share the same size. We can default to trying the most performance critical version of `get_by_id` first and fallback to loading the metadata field that specifies which version of the opcode should we execute. >+ >+# Current issues >+ >+Forward jumps will always generate wide opcodes: UINT_MAX is used as invalidLocation, which means that the address won't fit into a 1-byte operand. We might need to compact it later. >diff --git a/Source/JavaScriptCore/wip_bytecode/bytecode_generator.rb b/Source/JavaScriptCore/wip_bytecode/bytecode_generator.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 >diff --git a/Source/JavaScriptCore/wip_bytecode/bytecode_structs.cpp b/Source/JavaScriptCore/wip_bytecode/bytecode_structs.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..caa31f47980b31def4ed9799bcc333f751eeef4d >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/bytecode_structs.cpp >@@ -0,0 +1,414 @@ >+#include <cassert> >+#include <cstdint> >+#include <iostream> >+#include <type_traits> >+#include <unordered_map> >+#include <vector> >+ >+typedef unsigned Opcode; >+ >+enum OpcodeSize : size_t { >+ Narrow = 1, >+ Wide = 4, >+}; >+ >+size_t opcode_count = 2; >+size_t metadata_count[] = { >+ 0, >+ 3 >+}; >+size_t opcode_length[] = { >+ 0, >+ 4 >+}; >+ >+ >+class BytecodeGenerator { >+public: >+ BytecodeGenerator() >+ : m_metadata(opcode_count) >+ { } >+ >+ void write(uint8_t op) >+ { >+ m_opcodes.push_back(op); >+ } >+ >+ void write(unsigned op) >+ { >+ uint8_t* b = (uint8_t*)&op; >+ m_opcodes.push_back(b[0]); >+ m_opcodes.push_back(b[1]); >+ m_opcodes.push_back(b[2]); >+ m_opcodes.push_back(b[3]); >+ } >+ >+ unsigned metadataFor(Opcode opcode) >+ { >+ auto& it = m_metadata.at(opcode); >+ return it++; >+ } >+ >+ std::vector<uint8_t> m_opcodes; >+private: >+ std::vector<unsigned> m_metadata; >+}; >+ >+class RegisterID { >+public: >+ RegisterID(unsigned offset) >+ : m_offset(offset) >+ { } >+ >+ unsigned m_offset; >+}; >+ >+template <typename T, size_t Width, typename = std::true_type> >+struct Fits { }; >+ >+template <typename T, size_t Width> >+struct Fits<T, Width, std::enable_if_t<sizeof(T) == Width, std::true_type>> { >+ using type = T; >+ static bool check(T) { return true; } >+ static T convert(T t) { return t; } >+}; >+ >+template<> >+struct Fits<unsigned, 1> { >+ using type = uint8_t; >+ >+ static bool check(unsigned u) >+ { >+ std::cout << "HERE: " << u << " <= " << UINT8_MAX << std::endl; >+ return u <= UINT8_MAX; >+ } >+ >+ static type convert(unsigned u) >+ { >+ assert(check(u)); >+ return static_cast<uint8_t>(u); >+ } >+}; >+ >+template<> >+struct Fits<RegisterID*, 1> { >+ using type = uint8_t; >+ >+ static bool check(RegisterID* r) >+ { >+ return Fits<unsigned, 1>::check(r->m_offset); >+ } >+ >+ static type convert(RegisterID* r) >+ { >+ return Fits<unsigned, 1>::convert(r->m_offset); >+ } >+}; >+ >+template<> >+struct Fits<RegisterID*, 4> { >+ using type = unsigned; >+ >+ static bool check(RegisterID* r) >+ { >+ return true; >+ } >+ >+ static type convert(RegisterID* r) >+ { >+ return r->m_offset; >+ } >+}; >+ >+class BytecodeReader { >+public: >+ BytecodeReader(std::vector<uint8_t>& stream) >+ : m_stream(stream) >+ { } >+ >+ uint8_t& get() >+ { >+ assert(m_index < m_stream.size()); >+ std::cout << "BytecodeReader::read [" << m_index << "]" << std::endl; >+ return m_stream[m_index]; >+ }; >+ >+ void advance(size_t offset) >+ { >+ m_index += offset; >+ assert(m_index <= m_stream.size()); >+ } >+ >+private: >+ unsigned m_index; >+ std::vector<uint8_t>& m_stream; >+}; >+ >+class OpWide { >+public: >+ static Opcode opcode() { return 0; } >+}; >+ >+template<template<OpcodeSize> class Impl> >+class BaseInstruction { }; >+ >+class Instruction { >+public: >+ template<template<OpcodeSize> class Impl> >+ class Intf { >+ public: >+ Opcode opcode() >+ { >+ if (isWide()) >+ return wide()->opcode(); >+ return narrow()->opcode(); >+ } >+ >+ bool isWide() >+ { >+ return narrow()->opcode() == OpWide::opcode(); >+ }; >+ >+ size_t length() >+ { >+ return opcode_length[opcode()]; >+ } >+ >+ size_t size() >+ { >+ auto isWide = this->isWide(); >+ return length() * (isWide ? OpcodeSize::Wide : OpcodeSize::Narrow) + isWide; >+ } >+ >+ >+ template<class T> >+ bool is() >+ { >+ return opcode() == T::opcode(); >+ } >+ >+ template<class T> >+ typename T::Unknown* as() >+ { >+ assert(is<T>()); >+ return (typename T::Unknown*)this; >+ } >+ >+ Impl<OpcodeSize::Narrow>* narrow() >+ { >+ return (Impl<OpcodeSize::Narrow>*)this; >+ } >+ >+ Impl<OpcodeSize::Wide>* wide() >+ { >+ >+ assert(isWide()); >+ return (Impl<OpcodeSize::Wide>*)((uintptr_t)this + 1); >+ } >+ >+ }; >+ >+ template<OpcodeSize Width> >+ class Impl : public Intf<Impl> { >+ public: >+ Opcode opcode() >+ { >+ return *reinterpret_cast<typename Fits<unsigned, Width>::type*>(&m_opcode); >+ } >+ >+ private: >+ std::aligned_storage_t<Width, Width> m_opcode; >+ }; >+ >+public: >+ using Unknown = Intf<Impl>; >+ static Instruction::Unknown* read(BytecodeReader& reader) >+ { >+ >+ Instruction::Unknown* instr = (Instruction::Unknown*)&reader.get(); >+ reader.advance(instr->size()); >+ return instr; >+ } >+}; >+ >+class ValueProfile { >+public: >+ ValueProfile() >+ { >+ static unsigned id = 0; >+ m_id = id++; >+ } >+ >+ unsigned id() { return m_id; } >+ >+private: >+ unsigned m_id; >+}; >+ >+template <typename Key, typename Value> >+using HashMap = std::unordered_map<Key, Value>; >+ >+typedef struct _OpaqueMetadata* OpaqueMetadata; >+ >+class CodeBlock { >+public: >+ CodeBlock() >+ : m_metadata(opcode_count) >+ { >+ for (unsigned i = 0; i < opcode_count; i++) { >+ auto count = metadata_count[i]; >+ if (count) { >+ std::cout << "opcode: " << i << ", metadata_count: " << count << std::endl; >+ m_metadata[i] = HashMap<unsigned, OpaqueMetadata>(count); >+ } >+ >+ } >+ } >+ >+ template <typename Value> >+ HashMap <unsigned, Value>& metadata(Opcode opcode) >+ { >+ auto& meta = m_metadata.at(opcode); >+ return *reinterpret_cast<HashMap<unsigned, Value>*>(&meta); >+ } >+ >+private: >+ HashMap <Opcode, HashMap<unsigned, OpaqueMetadata>> m_metadata; >+}; >+ >+class ExecState { >+public: >+ ExecState(CodeBlock* codeBlock) >+ : m_codeBlock(codeBlock) >+ { } >+ >+ CodeBlock* codeBlock() { return m_codeBlock; } >+ >+private: >+ CodeBlock* m_codeBlock; >+}; >+ >+ >+class OpGetArgument final { >+public: >+ static constexpr Opcode opcode() { return 1; } >+ >+ static void create(BytecodeGenerator& generator, RegisterID* dst, unsigned index) >+ { >+ if (Fits<Opcode, 1>::check(opcode()) && Fits<decltype(dst), 1>::check(dst) && Fits<decltype(index), 1>::check(index)) { >+ generator.write(Fits<Opcode, 1>::convert(opcode())); >+ generator.write(Fits<decltype(dst), 1>::convert(dst)); >+ generator.write(Fits<decltype(index), 1>::convert(index)); >+ generator.write(Fits<unsigned, 1>::convert(generator.metadataFor(opcode()))); >+ } else { >+ assert((Fits<decltype(opcode()), 4>::check(opcode()))); >+ assert((Fits<decltype(dst), 4>::check(dst))); >+ assert((Fits<decltype(index), 4>::check(index))); >+ >+ generator.write(Fits<Opcode, 1>::convert(OpWide::opcode())); >+ generator.write(OpGetArgument::opcode()); >+ generator.write(Fits<decltype(dst), 4>::convert(dst)); >+ generator.write(Fits<decltype(index), 4>::convert(index)); >+ generator.write(Fits<unsigned, 4>::convert(generator.metadataFor(opcode()))); >+ } >+ } >+ >+private: >+ template<OpcodeSize> class Impl; >+ >+public: >+ struct Metadata { >+ ValueProfile profile; >+ }; >+ >+ class Intf : public Instruction::Intf<Impl> { >+ public: >+ RegisterID dst() { return isWide() ? wide()->dst() : narrow()->dst(); } >+ unsigned index() { return isWide() ? wide()->index() : narrow()->index(); } >+ unsigned metadata() { return isWide() ? wide()->metadata() : narrow()->metadata(); } >+ Metadata& metadata(ExecState& exec) { return isWide() ? wide()->metadata(exec) : narrow()->metadata(exec); } >+ }; >+ >+ using Unknown = Intf; >+ >+private: >+ template<OpcodeSize Width> >+ class Impl : public Instruction::Impl<Width> { >+ public: >+ >+ RegisterID dst() { return *reinterpret_cast<typename Fits<RegisterID*, Width>::type*>(&m_dst); } >+ unsigned index() { return *reinterpret_cast<typename Fits<unsigned, Width>::type*>(&m_index); } >+ unsigned metadata() { return *reinterpret_cast<typename Fits<unsigned, Width>::type*>(&m_metadata); } >+ Metadata& metadata(ExecState& exec) >+ { >+ auto id = metadata(); >+ auto meta = exec.codeBlock()->metadata<OpGetArgument::Metadata>(opcode()); >+ const auto& it = meta.find(id); >+ if (it != meta.end()) >+ return it->second; >+ return meta.emplace(std::make_pair(id, Metadata { })).first->second; >+ } >+ >+ private: >+ std::aligned_storage_t<Width, Width> m_dst; >+ std::aligned_storage_t<Width, Width> m_index; >+ std::aligned_storage_t<Width, Width> m_metadata; >+ }; >+ >+}; >+ >+ >+int main() >+{ >+ BytecodeGenerator generator; >+ RegisterID dst(3); >+ CodeBlock codeBlock; >+ ExecState exec(&codeBlock); >+ >+ OpGetArgument::create(generator, &dst, 1); >+ OpGetArgument::create(generator, &dst, 1256); >+ OpGetArgument::create(generator, &dst, 42); >+ >+ std::cout << "writing " << generator.m_opcodes.size() << " bytes" << std::endl; >+ for (auto op : generator.m_opcodes) >+ std::cout << std::to_string(op) << std::endl; >+ >+ BytecodeReader reader(generator.m_opcodes); >+ { >+ auto instr = Instruction::read(reader); >+ std::cout << "opcode: " << instr->opcode() << std::endl; >+ std::cout << "isWide: " << instr->isWide() << std::endl; >+ std::cout << "size: " << instr->size() << std::endl; >+ } >+ >+ { >+ auto instr = Instruction::read(reader); >+ std::cout << "opcode: " << instr->opcode() << std::endl; >+ std::cout << "isWide: " << instr->isWide() << std::endl; >+ std::cout << "size: " << instr->size() << std::endl; >+ >+ auto wide = instr->as<OpGetArgument>()->wide(); >+ std::cout << "as<OpGetArgument>->wide(): " << wide << std::endl; >+ std::cout << "as<OpGetArgument>->wide()->dst(): " << wide->dst().m_offset << std::endl; >+ std::cout << "as<OpGetArgument>->wide()->metadata(): " << wide->metadata() << std::endl; >+ std::cout << "as<OpGetArgument>->wide()->metadata(exec).profile.id(): " << wide->metadata(exec).profile.id() << std::endl; >+ } >+ >+ { >+ auto instr = Instruction::read(reader); >+ std::cout << "opcode: " << instr->opcode() << std::endl; >+ std::cout << "isWide: " << instr->isWide() << std::endl; >+ std::cout << "size: " << instr->size() << std::endl; >+ >+ std::cout << "is<OpGetArgument>: " << instr->is<OpGetArgument>() << std::endl; >+ std::cout << "is<OpWide>: " << instr->is<OpWide>() << std::endl; >+ >+ std::cout << "as<OpGetArgument>->index: " << instr->as<OpGetArgument>()->index() << std::endl; >+ >+ auto narrow = instr->as<OpGetArgument>()->narrow(); >+ std::cout << "as<OpGetArgument>->narrow(): " << narrow << std::endl; >+ std::cout << "as<OpGetArgument>->narrow()->dst(): " << narrow->dst().m_offset << std::endl; >+ std::cout << "as<OpGetArgument>->narrow()->metadata(exec).profile.id(): " << narrow->metadata(exec).profile.id() << std::endl; >+ } >+ return 0; >+}; >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Argument.rb b/Source/JavaScriptCore/wip_bytecode/generator/Argument.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..d97cb53f97235434e8f98654dc77abc4a175e91a >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Argument.rb >@@ -0,0 +1,36 @@ >+require_relative 'Fits' >+ >+class Argument >+ def initialize(name, type) >+ @name = name >+ @type = type >+ end >+ >+ def intf_accessor >+ "#{@type.to_s} #{@name}() { return #{Fits::choose_width @name}; }" >+ end >+ >+ def impl_accessor >+ "#{@type.to_s} #{@name}() { return #{Fits::cast member_name, @type}; }" >+ end >+ >+ def impl_field >+ "std::aligned_storage_t<Width, Width> #{member_name};" >+ end >+ >+ def member_name >+ "m_#{@name}" >+ end >+ >+ def create_param >+ "#{@type.to_s} #{@name}" >+ end >+ >+ def fits_check(size) >+ Fits::check size, @name, @type >+ end >+ >+ def fits_write(size) >+ Fits::write size, @name, @type >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Assertion.rb b/Source/JavaScriptCore/wip_bytecode/generator/Assertion.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..a93dd4d9feff9750471fb66d94fd73b2da5faee0 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Assertion.rb >@@ -0,0 +1,9 @@ >+class AssertionError < RuntimeError >+ def initialize(msg) >+ super >+ end >+end >+ >+def assert(msg, &block) >+ raise AssertionError, msg unless yield >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/DSL.rb b/Source/JavaScriptCore/wip_bytecode/generator/DSL.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..26e88d80e2c549722da4968ae86d28917918062c >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/DSL.rb >@@ -0,0 +1,66 @@ >+require_relative 'Assertion' >+require_relative 'Opcode' >+require_relative 'Section' >+require_relative 'Template' >+require_relative 'Type' >+ >+module DSL >+ @sections = [] >+ @current_section = nil >+ @context = binding() >+ >+ def begin_section(name, config={}) >+ assert("must call `end_section` before beginning a new section") { @current_section.nil? } >+ @current_section = Section.new name, config >+ end >+ >+ def end_section(name) >+ assert("current section's name is `#{@current_section.name}`, but end_section was called with `#{name}`") { @current_section.name == name } >+ @sections << @current_section >+ @current_section = nil >+ end >+ >+ def op(name, config = {}) >+ assert("`op` can only be called in between `begin_section` and `end_section`") { not @current_section.nil? } >+ @current_section.add_opcode Opcode.new(name, config[:args], config[:metadata]) >+ end >+ >+ def op_group(desc, ops, config) >+ ops.map do |op_name| >+ op op_name, config >+ end >+ end >+ >+ def types(types) >+ types.map do |type| >+ puts("#{type} = Type.new :#{type}") >+ @context.eval("#{type} = Type.new :#{type}") >+ end >+ end >+ >+ def templates(types) >+ types.map do |type| >+ @context.eval("#{type} = Template.new :#{type}") >+ end >+ end >+ >+ def namespace(name) >+ ctx = @context >+ @context = @context.eval(" >+ module #{name} >+ def self.get_binding >+ binding() >+ end >+ end >+ #{name}.get_binding >+ ") >+ yield >+ @context = ctx >+ end >+ >+ def run(file) >+ @context.eval(File.read(file), file) >+ assert("must end last section") { @current_section.nil? } >+ @sections[0].print 10 >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Fits.rb b/Source/JavaScriptCore/wip_bytecode/generator/Fits.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..b8f95da4b20ba37a2ff870fb94fb343d1a3c1719 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Fits.rb >@@ -0,0 +1,18 @@ >+module Fits >+ def cast(name, type) >+ "(*reinterpret_cast<typename Fits<#{type.to_s}, Width>::type*>(&#{name}))" >+ end >+ >+ def check(size, name, type) >+ "Fits<#{type.to_s}, #{size}>::check(#{name})" >+ end >+ >+ def write(size, name, type) >+ "generator.write(Fits<#{type.to_s}, #{size}>::convert(#{name}));" >+ end >+ >+ def choose_width(name, *args) >+ args = args.map(&:to_s).join ", " >+ "(isWide() ? wide()->#{name}(#{args}) : narrow()->#{name}(#{args}))" >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Implementation.rb b/Source/JavaScriptCore/wip_bytecode/generator/Implementation.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..01a321dcfaf81d30c53ba1e92a23ad8e49cf27db >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Implementation.rb >@@ -0,0 +1,16 @@ >+module Implementation >+ def for(opcode) >+ <<-EOF >+ template<OpcodeSize Width> >+ class Impl : Instruction::Impl<Impl> >+ { >+ public: >+ #{opcode.print_args(&:impl_accessor)} >+ #{opcode.metadata.impl_accessor} >+ private: >+ #{opcode.print_args(&:impl_field)} >+ #{opcode.metadata.impl_accessor} >+ } >+ EOF >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Interface.rb b/Source/JavaScriptCore/wip_bytecode/generator/Interface.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..d3f108b5f96314139559bc5bf8d682c009ff6a9d >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Interface.rb >@@ -0,0 +1,12 @@ >+module Interface >+ def for(opcode) >+ <<-EOF >+ class Intf : Instruction::Intf<Impl> >+ { >+ public: >+ #{opcode.print_args(&:intf_accessor)} >+ #{opcode.metadata.intf_accessor} >+ } >+ EOF >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Metadata.rb b/Source/JavaScriptCore/wip_bytecode/generator/Metadata.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..6f01d114197f23bd85b5e849c44f6db640ccfc94 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Metadata.rb >@@ -0,0 +1,41 @@ >+require_relative 'Fits' >+ >+class Metadata >+ def initialize(fields) >+ @fields = fields >+ end >+ >+ def cpp_class >+ return if @fields.nil? >+ >+ fields = @fields.map { |field, type| "#{type.to_s} #{field.to_s};" }.join "\n" >+ <<-EOF >+ struct Metadata >+ { >+ #{fields} >+ } >+ EOF >+ end >+ >+ def intf_accessor >+ return if @fields.nil? >+ >+ <<-EOF >+ Metadata& metadata() { return #{Fits::choose_width "metadata"}; } >+ Metadata& metadata(ExecState& exec) { return #{Fits::choose_width "metadata", "exec"}; } >+ EOF >+ end >+ >+ def impl_accessor >+ return if @fields.nil? >+ >+ <<-EOF >+ Metadata& metadata() { return #{Fits::cast "m_metadata", :unsigned}; } >+ Metadata& metadata(ExecState& exec) { return #{Fits::cast "m_metadata", :unsigned}; } >+ EOF >+ end >+ >+ def impl_field >+ "std::aligned_storage_t<Width, Width> m_metadata;" >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Opcode.rb b/Source/JavaScriptCore/wip_bytecode/generator/Opcode.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..df9d81a9d234c4a88bd13f1468f6959610887bcd >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Opcode.rb >@@ -0,0 +1,100 @@ >+require_relative 'Argument' >+require_relative 'Fits' >+require_relative 'Interface' >+require_relative 'Implementation' >+require_relative 'Metadata' >+ >+include Fits >+include Interface >+include Implementation >+ >+class Opcode >+ attr_reader :metadata >+ >+ module Size >+ Narrow = "OpcodeSize::Narrow" >+ Wide = "OpcodeSize::Wide" >+ end >+ >+ @@id = 0 >+ @@sizes = [Size::Narrow, Size::Wide] >+ >+ def self.id >+ tid = @@id >+ @@id = @@id + 1 >+ tid >+ end >+ >+ def initialize(name, args, metadata) >+ @id = self.class.id >+ @name = name >+ @metadata = Metadata.new metadata >+ @args = args.map { |arg_name, type| Argument.new arg_name, type } unless args.nil? >+ end >+ >+ def print_args(&block) >+ return if @args.nil? >+ >+ @args.map(&block).join "\n" >+ end >+ >+ def capitalized_name(prefix) >+ "#{prefix}#{@name}".split('_').collect(&:capitalize).join >+ end >+ >+ def typed_args >+ return if @args.nil? >+ >+ @args.map(&:create_param).unshift("").join(", ") >+ end >+ >+ def try_fit(size) >+ def field_checks(size) >+ return if @args.nil? >+ >+ @args.map { |arg| arg.fits_check size }.unshift("").join(" && ") >+ end >+ >+ def field_writes(size) >+ return if @args.nil? >+ >+ @args.map { |arg| arg.fits_write size }.unshift("").join("\n") >+ end >+ >+ <<-EOF >+ if (#{Fits::check size, "opcode()", :Opcode}#{field_checks size}) { >+ #{Fits::write size, "opcode()", :Opcode} >+ #{field_writes size} >+ } >+ EOF >+ end >+ >+ def cpp_class(prefix) >+ puts <<-EOF >+ class #{capitalized_name prefix} { >+ public: >+ static constexpr Opcode opcode() { return #{@id}; } >+ >+ static void emit(BytecodeGenerator* generator#{typed_args}) >+ { >+ generator->recordOpcode(opcode()); >+ #{@@sizes.map { |size| try_fit size }.join " else " } >+ ASSERT_NOT_REACHED(); >+ } >+ >+ private: >+ template<OpcodeSize> class Impl; >+ >+ public: >+ #{@metadata.cpp_class} >+ >+ #{Interface.for self} >+ >+ using Unknown = Intf; >+ >+ private: >+ #{Implementation.for self} >+ }; >+ EOF >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Section.rb b/Source/JavaScriptCore/wip_bytecode/generator/Section.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..d987363266a824f25a3de8cd135252a291de5447 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Section.rb >@@ -0,0 +1,23 @@ >+class Section >+ attr_reader :name >+ >+ def initialize(name, config) >+ @name = name >+ @config = config >+ @opcodes = [] >+ end >+ >+ def add_opcode(opcode) >+ @opcodes << opcode >+ end >+ >+ def print(max=nil) >+ opcodes = if max.nil? >+ then @opcodes >+ else @opcodes.take(max) >+ end >+ puts "--- BEGIN OF SECTION #{@name} ---" >+ opcodes.map { |opcode| opcode.cpp_class(@config[:op_prefix]) } >+ puts "--- END OF SECTION #{@name} ---" >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Template.rb b/Source/JavaScriptCore/wip_bytecode/generator/Template.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..a4e429ecbc1fc2956df4142c70fadf8c21fb89a7 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Template.rb >@@ -0,0 +1,7 @@ >+require_relative 'Type' >+ >+class Template < Type >+ def [](*types) >+ Type.new "#{@name}<#{types.map(&:to_s).join ","}>" >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/Type.rb b/Source/JavaScriptCore/wip_bytecode/generator/Type.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..28841bfc55ea962bd303e934d510bd8d74be1933 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/Type.rb >@@ -0,0 +1,13 @@ >+class Type >+ def initialize(name) >+ @name = name >+ end >+ >+ def * >+ Type.new "#{@name}*" >+ end >+ >+ def to_s >+ @name.to_s >+ end >+end >diff --git a/Source/JavaScriptCore/wip_bytecode/generator/main.rb b/Source/JavaScriptCore/wip_bytecode/generator/main.rb >new file mode 100644 >index 0000000000000000000000000000000000000000..d0fd097921a27c2e199f5d9ac7704a052583471d >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/generator/main.rb >@@ -0,0 +1,13 @@ >+require_relative 'DSL' >+ >+include DSL >+ >+# for some reason, lower case variables are not accessible until the next invocation of eval >+# so we bind them here, before eval'ing the file >+DSL::types [ >+ :bool, >+ :int, >+ :unsigned, >+] >+ >+DSL::run(File.expand_path("../BytecodeList.rb", __dir__)) >diff --git a/Source/JavaScriptCore/wip_bytecode/runtime/Fits.h b/Source/JavaScriptCore/wip_bytecode/runtime/Fits.h >new file mode 100644 >index 0000000000000000000000000000000000000000..181d7837ffda69b0df6590265394d19fdfeb4eec >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/runtime/Fits.h >@@ -0,0 +1,72 @@ >+#pragma once >+ >+template <typename T, size_t Width, typename = std::true_type> >+struct Fits { }; >+ >+template <typename T, size_t Width> >+struct Fits<T, Width, std::enable_if_t<sizeof(T) == Width, std::true_type>> { >+ using type = T; >+ static bool check(T) { return true; } >+ static T convert(T t) { return t; } >+}; >+ >+template<> >+struct Fits<unsigned, 1> { >+ using type = uint8_t; >+ >+ static bool check(unsigned u) >+ { >+ return u <= UINT8_MAX; >+ } >+ >+ static type convert(unsigned u) >+ { >+ ASSERT(check(u)); >+ return static_cast<uint8_t>(u); >+ } >+}; >+ >+template<> >+struct Fits<int, 1> { >+ using type = int8_t; >+ >+ static bool check(int i) >+ { >+ return i >= INT8_MIN && i <= INT8_MAX; >+ } >+ >+ static type convert(int i) >+ { >+ return static_cast<int8_t>(i); >+ } >+}; >+ >+template<size_t Width> >+struct Fits<Label&, Width> : public Fits<int, Width> { >+ using Base = Fits<int, Width>; >+ >+ static bool check(Label& target) >+ { >+ return Base::check(target.compute()); >+ } >+ >+ static Base::type convert(Label& target) >+ { >+ return Base::convert(target.compute(Width)); >+ } >+}; >+ >+template<size_t Width> >+struct Fits<RegisterID*, Width> : public Fits<unsigned, Width> { >+ using Base = Fits<int, Width>; >+ >+ static bool check(RegisterID* r) >+ { >+ return Base::check(r->index()); >+ } >+ >+ static Base::type convert(RegisterID* r) >+ { >+ return Base::convert(r->index()); >+ } >+}; >diff --git a/Source/JavaScriptCore/wip_bytecode/runtime/Instruction.h b/Source/JavaScriptCore/wip_bytecode/runtime/Instruction.h >new file mode 100644 >index 0000000000000000000000000000000000000000..1a02554a3421f22faa94503876033ba3ade60651 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/runtime/Instruction.h >@@ -0,0 +1,84 @@ >+#pragma once >+ >+#include "OpcodeSize.h" >+ >+class OpWide; >+ >+class Instruction { >+public: >+ template<template<OpcodeSize> class Impl> >+ class Intf { >+ public: >+ Opcode opcode() >+ { >+ if (isWide()) >+ return wide()->opcode(); >+ return narrow()->opcode(); >+ } >+ >+ bool isWide() >+ { >+ return narrow()->opcode() == OpWide::opcode(); >+ }; >+ >+ size_t length() >+ { >+ return opcode_length[opcode()]; >+ } >+ >+ size_t size() >+ { >+ auto isWide = this->isWide(); >+ return length() * (isWide ? OpcodeSize::Wide : OpcodeSize::Narrow) + isWide; >+ } >+ >+ >+ template<class T> >+ bool is() >+ { >+ return opcode() == T::opcode(); >+ } >+ >+ template<class T> >+ typename T::Unknown* as() >+ { >+ assert(is<T>()); >+ return (typename T::Unknown*)this; >+ } >+ >+ Impl<OpcodeSize::Narrow>* narrow() >+ { >+ return (Impl<OpcodeSize::Narrow>*)this; >+ } >+ >+ Impl<OpcodeSize::Wide>* wide() >+ { >+ >+ assert(isWide()); >+ return (Impl<OpcodeSize::Wide>*)((uintptr_t)this + 1); >+ } >+ >+ }; >+ >+ template<OpcodeSize Width> >+ class Impl : public Intf<Impl> { >+ public: >+ Opcode opcode() >+ { >+ return *reinterpret_cast<typename Fits<unsigned, Width>::type*>(&m_opcode); >+ } >+ >+ private: >+ std::aligned_storage_t<Width, Width> m_opcode; >+ }; >+ >+public: >+ using Unknown = Intf<Impl>; >+ static Instruction::Unknown* read(BytecodeReader& reader) >+ { >+ >+ Instruction::Unknown* instr = (Instruction::Unknown*)&reader.get(); >+ reader.advance(instr->size()); >+ return instr; >+ } >+}; >diff --git a/Source/JavaScriptCore/wip_bytecode/runtime/OpcodeSize.h b/Source/JavaScriptCore/wip_bytecode/runtime/OpcodeSize.h >new file mode 100644 >index 0000000000000000000000000000000000000000..11672ba2c020eaa81cfc56b2d65523263924e689 >--- /dev/null >+++ b/Source/JavaScriptCore/wip_bytecode/runtime/OpcodeSize.h >@@ -0,0 +1,6 @@ >+#pragma once >+ >+enum OpcodeSize : size_t { >+ Narrow = 1, >+ Wide = 4, >+};
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 187373
:
344389
|
344531
|
344635
|
344935
|
345812
|
346138
|
346673
|
346756
|
346862
|
347641
|
347766
|
348149
|
348294
|
348572
|
348792
|
348847
|
348971
|
349051
|
349080
|
349211
|
349307
|
349396
|
349473
|
349594
|
349700
|
349991
|
350040
|
350625
|
350716
|
350743
|
350835
|
350888
|
350987
|
351708
|
351743
|
351841
|
351955
|
351964
|
351995
|
352037
|
352050
|
352126
|
352232
|
352267
|
352268
|
352284
|
352287
|
352288
|
352312
|
352319
|
352322
|
352565
|
352580
|
352600
|
352639
|
352651
|
352664
|
352677
|
352680
|
352689
|
352692
|
352707
|
352719
|
352750
|
352806
|
352809
|
352811
|
352823
|
352843
|
352852
|
352853
|
352861
|
352863
|
352865
|
352866
|
352868
|
352913
|
352926
|
352936
|
352948
|
352981
|
352988
|
352993
|
352999
|
353008
|
353009
|
353033
|
353166
|
353170
|
353199
|
353213
|
353227
|
353235