5#ifndef QV4BYTECODEGENERATOR_P_H
6#define QV4BYTECODEGENERATOR_P_H
18#include <private/qv4instr_moth_p.h>
19#include <private/qv4compileddata_p.h>
20#include <private/qv4compilercontext_p.h>
21#include <private/qqmljssourcelocation_p.h>
42 bool storeSourceLocation =
false)
46 if (storeSourceLocation)
47 m_sourceLocationTable.reset(
new QV4::Compiler::Context::SourceLocationTable {});
63 index(generator->labels.size()) {
65 generator->labelReachable.append(
false);
97 { Q_ASSERT(generator); }
168 template<
typename Data>
171 addInstructionHelper(Data::type, Moth::Instr::Factory<Data>::create(data));
265 return currentExceptionHandler;
275 template<
typename Data>
278 return Jump(
this, addInstructionHelper(Data::type, Moth::Instr::Factory<Data>::create(data),
279 offsetof(Data, offset)));
285 addJumpInstruction(Instruction::JumpFalse()).link(*falseLabel);
287 addJumpInstruction(Instruction::JumpTrue()).link(*trueLabel);
297 _labelInfos.push_back({ start.index });
308 int addInstructionHelper(Moth::Instr::Type type,
const Instr &i,
int offsetOfOffset = -1);
311 Moth::Instr::Type type;
319 bool locationSetAfterLabel;
320 unsigned char packed[
sizeof(Instr) + 2];
323 static bool endsFlow(Moth::Instr::Type type)
326 case Instr::Type::Ret:
327 case Instr::Type::Jump:
328 case Instr::Type::UnwindToLabel:
329 case Instr::Type::ThrowException:
336 static I makeInstruction(Moth::Instr::Type type,
const Instr &i,
int offsetOfOffset,
int line,
339 const int argCount = Moth::InstrInfo::argumentCount[
static_cast<
int>(type)];
340 int s = argCount *
sizeof(
int);
341 if (offsetOfOffset != -1)
342 offsetOfOffset += Instr::encodedLength(type);
343 I instr{ type,
static_cast<
short>(s + Instr::encodedLength(type)),
345 statement, offsetOfOffset,
348 uchar *code = instr.packed;
349 code = Instr::pack(code, Instr::wideInstructionType(type));
351 for (
int j = 0; j < argCount; ++j) {
352 qToLittleEndian<qint32>(i[j], code);
358 void compressInstructions();
359 void packInstruction(I &i);
360 void adjustJumpOffsets();
361 bool isLabelValid(
int position)
const {
return labels.at(position) >= 0; }
363 QList<I> instructions;
367 QList<
bool> labelReachable;
369 DebugInstructionPass debugInstructionPass =
nullptr;
377 bool locationSetAfterLabel =
true;
378 std::unique_ptr<QV4::Compiler::Context::SourceLocationTable> m_sourceLocationTable;
379 int currentStatement = 0;
380 bool hasError =
false;
383 bool reachable =
true;
385 int lastInstrType = -1;
386 Moth::Instr lastInstr;
391 std::vector<LabelInfo> _labelInfos;
void insert(quint32 key, quint32 value)
void clearLastInstruction()
int currentRegister() const
void addInstruction(const Data &data)
BytecodeGenerator(int line, DebugInstructionPass debugInstructionPass, bool storeSourceLocation=false)
ExceptionHandler newExceptionHandler()
ExceptionHandler * exceptionHandler() const
void incrementStatement()
void addLoopStart(const Label &start)
void addCJumpInstruction(bool jumpOnFalse, const Label *trueLabel, const Label *falseLabel)
void finalize(Compiler::Context *context)
int newRegisterArray(int n)
int registerCount() const
Jump addJumpInstruction(const Data &data)
Combined button and popup list for selecting options.
QList< Method > staticMethods
KeyValuePair(quint32 key, quint32 value)
bool isLexicallyScoped() const
bool isFormalParameterTDZPromotion
QQmlJS::AST::FunctionExpression * function
bool requiresTDZCheck(const QQmlJS::SourceLocation &accessLocation, bool accessAcrossContextBoundaries) const
QQmlJS::SourceLocation declarationLocation
QQmlJS::AST::VariableScope scope
QQmlJS::SourceLocation declarationLocation
Context::MemberType memberType
QQmlJS::SourceLocation location
QList< Context * > nestedContexts
bool memberInfo(const QString &name, const Member **m) const
void emitBlockFooter(Compiler::Codegen *codegen)
QQmlJS::AST::FormalParameterList * formals
bool innerFunctionAccessesThis
bool hasArgument(const QString &name) const
void emitBlockHeader(Compiler::Codegen *codegen)
QQmlJS::AST::BoundNames arguments
bool escapingVariablesCalculated
QSet< QString > usedVariables
bool canHaveTailCalls() const
bool innerFunctionAccessesNewTarget
int firstTemporalDeadZoneRegister
std::unique_ptr< SourceLocationTable > sourceLocationTable
UsesArgumentsObject usesArgumentsObject
QList< CompiledData::CodeOffsetToLineAndStatement > lineAndStatementNumberMapping
QList< ImportEntry > importEntries
bool requiresExecutionContext
QMap< QString, Member > MemberMap
QQmlJS::AST::Type * returnType
Context(Context *parent, ContextType type)
int sizeOfRegisterTemporalDeadZone
ResolvedName resolveName(const QString &name, const QQmlJS::SourceLocation &accessLocation)
QString localNameForDefaultExport
bool requiresImplicitReturnValue() const
void setupFunctionIndices(Moth::BytecodeGenerator *bytecodeGenerator)
int registerCountInFunction
QQmlJS::SourceLocation lastBlockInitializerLocation
void addUsedVariable(const QString &name)
ControlFlow * controlFlow
void promoteFormalParameterForTDZ(const QString &name, const QQmlJS::SourceLocation &loc)
QList< ExportEntry > exportEntries
int sizeOfLocalTemporalDeadZone
std::vector< unsigned > labelInfo
Member findMember(const QString &name) const
QStringList moduleRequests
bool addLocalVar(const QString &name, MemberType contextType, QQmlJS::AST::VariableScope scope, QQmlJS::AST::FunctionExpression *function=nullptr, const QQmlJS::SourceLocation &declarationLocation=QQmlJS::SourceLocation(), bool isInjected=false)
int findArgument(const QString &name, bool *isInjected) const
CompiledData::Location location
static bool lessThan(const ExportEntry &lhs, const ExportEntry &rhs)
CompiledData::Location location
Context * newContext(QQmlJS::AST::Node *node, Context *parent, ContextType compilationMode)
QHash< QQmlJS::AST::Node *, Context * > contextMap
QList< ExportEntry > indirectExportEntries
QList< Context * > functions
QDateTime sourceTimeStamp
QStringList moduleRequests
Module(const QString &fileName, const QString &finalUrl, Moth::DebugInstructionPass debugInstructionPass)
QList< ExportEntry > starExportEntries
QList< TemplateObject > templateObjects
Moth::DebugInstructionPass debugInstructionPass
QList< ImportEntry > importEntries
QList< ExportEntry > localExportEntries
QList< Context * > blocks
bool operator==(const TemplateObject &other)
ExceptionHandler(BytecodeGenerator *generator)
ExceptionHandler & operator=(ExceptionHandler &&)=default
ExceptionHandler & operator=(const ExceptionHandler &)=default
ExceptionHandler()=default
ExceptionHandler(ExceptionHandler &&)=default
ExceptionHandler(const ExceptionHandler &)=default
BytecodeGenerator * generator
Jump(BytecodeGenerator *generator, int instruction)
Label(BytecodeGenerator *generator, LinkMode mode=LinkNow)
BytecodeGenerator * generator