4#ifndef QV4BYTECODEGENERATOR_P_H
5#define QV4BYTECODEGENERATOR_P_H
17#include <private/qv4instr_moth_p.h>
18#include <private/qv4compileddata_p.h>
19#include <private/qv4compilercontext_p.h>
20#include <private/qqmljssourcelocation_p.h>
41 : startLine(line), debugMode(debug)
43 if (storeSourceLocation)
44 m_sourceLocationTable.reset(
new QV4::Compiler::Context::SourceLocationTable {});
55 index(generator->labels.size()) {
56 generator->labels.append(-1);
77 { Q_ASSERT(generator &&
index != -1); }
140 InstrMeta<InstrT>::setData(genericInstr, data);
141 addInstructionHelper(Moth::Instr::Type(InstrT), genericInstr);
239 return currentExceptionHandler;
253 InstrMeta<InstrT>::setData(genericInstr, data);
254 return Jump(
this, addInstructionHelper(Moth::Instr::Type(InstrT), genericInstr, offsetof(InstrData<InstrT>, offset)));
260 addJumpInstruction(Instruction::JumpFalse()).link(*falseLabel);
262 addJumpInstruction(Instruction::JumpTrue()).link(*trueLabel);
272 _labelInfos.push_back({ start.index });
280 int addInstructionHelper(Moth::Instr::Type type,
const Instr &i,
int offsetOfOffset = -1);
283 Moth::Instr::Type type;
290 unsigned char packed[
sizeof(Instr) + 2];
293 void compressInstructions();
294 void packInstruction(I &i);
295 void adjustJumpOffsets();
297 QVector<I> instructions;
306 int currentStatement = 0;
308 std::unique_ptr<QV4::Compiler::Context::SourceLocationTable> m_sourceLocationTable;
309 bool debugMode =
false;
311 int lastInstrType = -1;
312 Moth::Instr lastInstr;
317 std::vector<LabelInfo> _labelInfos;
void insert(quint32 key, quint32 value)
void clearLastInstruction()
Jump addJumpInstruction(const InstrData< InstrT > &data)
BytecodeGenerator(int line, bool debug, bool storeSourceLocation=false)
int currentRegister() const
ExceptionHandler newExceptionHandler()
ExceptionHandler * exceptionHandler() const
void addInstruction(const InstrData< InstrT > &data)
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
QVector< Method > staticMethods
QVector< Method > methods
KeyValuePair(quint32 key, quint32 value)
bool isLexicallyScoped() const
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
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
QSet< QString > usedVariables
bool canHaveTailCalls() const
QVector< Context * > nestedContexts
bool innerFunctionAccessesNewTarget
int firstTemporalDeadZoneRegister
std::unique_ptr< SourceLocationTable > sourceLocationTable
QVector< ImportEntry > importEntries
UsesArgumentsObject usesArgumentsObject
QVector< ExportEntry > exportEntries
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
QVector< CompiledData::CodeOffsetToLineAndStatement > lineAndStatementNumberMapping
void addUsedVariable(const QString &name)
ControlFlow * controlFlow
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
QVector< ImportEntry > importEntries
Context * newContext(QQmlJS::AST::Node *node, Context *parent, ContextType compilationMode)
QVector< ExportEntry > localExportEntries
QHash< QQmlJS::AST::Node *, Context * > contextMap
QList< Context * > functions
QVector< TemplateObject > templateObjects
QDateTime sourceTimeStamp
Module(const QString &fileName, const QString &finalUrl, bool debugMode)
QStringList moduleRequests
QVector< ExportEntry > starExportEntries
QVector< ExportEntry > indirectExportEntries
QList< Context * > blocks
QVector< uint > rawStrings
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