Skip to content

Commit

Permalink
Support variable length instructions in QML bytecode
Browse files Browse the repository at this point in the history
Reviewed-by: Martin Jones
Change-Id: Ib04b8d46a78723d3a734e14d22a2f2256c1627c2
  • Loading branch information
Aaron Kennedy committed May 5, 2011
1 parent 5f46c8e commit cb661b8
Show file tree
Hide file tree
Showing 14 changed files with 1,374 additions and 1,384 deletions.
33 changes: 31 additions & 2 deletions src/declarative/qml/qdeclarativecompileddata.cpp
Expand Up @@ -248,11 +248,40 @@ void QDeclarativeCompiledData::dumpInstructions()
qWarning() << name;
qWarning().nospace() << "Index\tOperation\t\tData1\tData2\tData3\tComments";
qWarning().nospace() << "-------------------------------------------------------------------------------";
for (int ii = 0; ii < bytecode.count(); ++ii) {
dump(&bytecode[ii], ii);

const char *instructionStream = bytecode.constData();
const char *endInstructionStream = bytecode.constData() + bytecode.size();

int instructionCount = 0;
while (instructionStream < endInstructionStream) {
QDeclarativeInstruction *instr = (QDeclarativeInstruction *)instructionStream;
dump(instr, instructionCount);
instructionStream += instr->size();
instructionCount++;
}

qWarning().nospace() << "-------------------------------------------------------------------------------";
}

int QDeclarativeCompiledData::addInstruction(const QDeclarativeInstruction &instr)
{
int ptrOffset = bytecode.size();
int size = instr.size();
bytecode.resize(bytecode.size() + size);
char *data = bytecode.data() + ptrOffset;
qMemCopy(data, &instr, size);

return ptrOffset;
}

int QDeclarativeCompiledData::nextInstructionIndex()
{
return bytecode.size();
}

QDeclarativeInstruction *QDeclarativeCompiledData::instruction(int index)
{
return (QDeclarativeInstruction *)(bytecode.constData() + index);
}

QT_END_NAMESPACE
219 changes: 115 additions & 104 deletions src/declarative/qml/qdeclarativecompiler.cpp

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/declarative/qml/qdeclarativecompiler_p.h
Expand Up @@ -117,7 +117,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeCompiledData : public QDeclarativeRefCount,
QList<CustomTypeData> customTypeData;
QList<QByteArray> datas;
QList<QDeclarativeParser::Location> locations;
QList<QDeclarativeInstruction> bytecode;
QByteArray bytecode;
QList<QScriptProgram *> cachedPrograms;
QList<QScriptValue *> cachedClosures;
QList<QDeclarativePropertyCache *> propertyCaches;
Expand All @@ -127,6 +127,10 @@ class Q_AUTOTEST_EXPORT QDeclarativeCompiledData : public QDeclarativeRefCount,

void dumpInstructions();

int addInstruction(const QDeclarativeInstruction &instr);
int nextInstructionIndex();
QDeclarativeInstruction *instruction(int index);

protected:
virtual void clear(); // From QDeclarativeCleanup

Expand Down
9 changes: 4 additions & 5 deletions src/declarative/qml/qdeclarativecomponent.cpp
Expand Up @@ -455,15 +455,14 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeEngine *engine, const Q
/*!
\internal
*/
QDeclarativeComponent::QDeclarativeComponent(QDeclarativeEngine *engine, QDeclarativeCompiledData *cc, int start, int count, QObject *parent)
QDeclarativeComponent::QDeclarativeComponent(QDeclarativeEngine *engine, QDeclarativeCompiledData *cc, int start, QObject *parent)
: QObject(*(new QDeclarativeComponentPrivate), parent)
{
Q_D(QDeclarativeComponent);
d->engine = engine;
d->cc = cc;
cc->addref();
d->start = start;
d->count = count;
d->url = cc->url;
d->progress = 1.0;
}
Expand Down Expand Up @@ -833,7 +832,7 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons
return 0;
}

return begin(context, creationContext, cc, start, count, &state, 0, bindings);
return begin(context, creationContext, cc, start, &state, 0, bindings);
}

/*
Expand Down Expand Up @@ -866,7 +865,7 @@ static inline QString buildTypeNameForDebug(const QMetaObject *metaObject)

QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *parentContext,
QDeclarativeContextData *componentCreationContext,
QDeclarativeCompiledData *component, int start, int count,
QDeclarativeCompiledData *component, int start,
ConstructionState *state, QList<QDeclarativeError> *errors,
const QBitField &bindings)
{
Expand Down Expand Up @@ -895,7 +894,7 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *parentCon

QDeclarativeVME vme;
enginePriv->referenceScarceResources(); // "hold" scarce resources in memory during evaluation.
QObject *rv = vme.run(ctxt, component, start, count, bindings);
QObject *rv = vme.run(ctxt, component, start, bindings);
enginePriv->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.

if (vme.isError()) {
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativecomponent.h
Expand Up @@ -113,7 +113,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeComponent : public QObject
Q_INVOKABLE Q_REVISION(1) QScriptValue createObject(QObject* parent, const QScriptValue& valuemap); //XXX Versioning

private:
QDeclarativeComponent(QDeclarativeEngine *, QDeclarativeCompiledData *, int, int, QObject *parent);
QDeclarativeComponent(QDeclarativeEngine *, QDeclarativeCompiledData *, int, QObject *parent);

Q_DISABLE_COPY(QDeclarativeComponent)
friend class QDeclarativeVME;
Expand Down
5 changes: 2 additions & 3 deletions src/declarative/qml/qdeclarativecomponent_p.h
Expand Up @@ -79,7 +79,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeComponentPrivate : public QObjectPrivate, pu
Q_DECLARE_PUBLIC(QDeclarativeComponent)

public:
QDeclarativeComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), engine(0), creationContext(0) {}
QDeclarativeComponentPrivate() : typeData(0), progress(0.), start(-1), cc(0), engine(0), creationContext(0) {}

QObject *beginCreate(QDeclarativeContextData *, const QBitField &);
void completeCreate();
Expand All @@ -94,7 +94,6 @@ class Q_AUTOTEST_EXPORT QDeclarativeComponentPrivate : public QObjectPrivate, pu
qreal progress;

int start;
int count;
QDeclarativeCompiledData *cc;

struct ConstructionState {
Expand All @@ -109,7 +108,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeComponentPrivate : public QObjectPrivate, pu
ConstructionState state;

static QObject *begin(QDeclarativeContextData *parentContext, QDeclarativeContextData *componentCreationContext,
QDeclarativeCompiledData *component, int start, int count,
QDeclarativeCompiledData *component, int start,
ConstructionState *state, QList<QDeclarativeError> *errors,
const QBitField &bindings = QBitField());
static void beginDeferred(QDeclarativeEnginePrivate *enginePriv, QObject *object,
Expand Down
17 changes: 15 additions & 2 deletions src/declarative/qml/qdeclarativeinstruction.cpp
Expand Up @@ -53,10 +53,13 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx)
Q_UNUSED(instr)
Q_UNUSED(idx)
#else
switch(instr->type) {
switch(instr->type()) {
case QDeclarativeInstruction::Init:
qWarning().nospace() << idx << "\t\t" << "INIT\t\t\t" << instr->init.bindingsSize << "\t" << instr->init.parserStatusSize << "\t" << instr->init.contextCache << "\t" << instr->init.compiledBinding;
break;
case QDeclarativeInstruction::Done:
qWarning().nospace() << idx << "\t\t" << "DONE";
break;
case QDeclarativeInstruction::CreateObject:
qWarning().nospace() << idx << "\t\t" << "CREATE\t\t\t" << instr->create.type << "\t" << instr->create.bindingBits << "\t\t" << types.at(instr->create.type).className;
break;
Expand Down Expand Up @@ -214,10 +217,20 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx)
qWarning().nospace() << idx << "\t\t" << "DEFER" << "\t\t\t" << instr->defer.deferCount;
break;
default:
qWarning().nospace() << idx << "\t\t" << "XXX UNKNOWN INSTRUCTION" << "\t" << instr->type;
qWarning().nospace() << idx << "\t\t" << "XXX UNKNOWN INSTRUCTION" << "\t" << instr->type();
break;
}
#endif // QT_NO_DEBUG_STREAM
}

int QDeclarativeInstruction::size() const
{
#define QML_RETURN_INSTR_SIZE(I, FMT) case I: return QDeclarativeInstructionMeta<(int)I>::Size;
switch (common.instructionType) {
FOR_EACH_QML_INSTR(QML_RETURN_INSTR_SIZE)
default: return 0;
}
#undef QML_RETURN_INSTR_SIZE
}

QT_END_NAMESPACE

0 comments on commit cb661b8

Please sign in to comment.