aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-08-16 15:57:50 +0200
committerLars Knoll <lars.knoll@digia.com>2013-08-16 19:13:02 +0200
commit0d4657cc172d8b3dbd491da10ff88912603b0024 (patch)
tree4cdaa5e7252555a06e45f7d4f73ac6d256659f3a /src
parent75cc05fcf472453fc33b262c70af46344adff666 (diff)
Initial port of moth to the new compile data structures
Change-Id: I2ead40c5c8c9b12b29c48c387ea424838d1f7d9e Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qv4compileddata_p.h11
-rw-r--r--src/qml/compiler/qv4compiler.cpp6
-rw-r--r--src/qml/compiler/qv4isel_masm_p.h1
-rw-r--r--src/qml/compiler/qv4isel_moth.cpp50
-rw-r--r--src/qml/compiler/qv4isel_moth_p.h16
-rw-r--r--src/qml/compiler/qv4isel_p.h2
-rw-r--r--src/qml/jsruntime/qv4function.cpp1
7 files changed, 66 insertions, 21 deletions
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index b2bc25bdbe..611d916ea8 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -328,6 +328,7 @@ struct CompilationUnit
QV4::Lookup *runtimeLookups;
QV4::Value *runtimeRegularExpressions;
QV4::InternalClass **runtimeClasses;
+ QList<QV4::Function *> runtimeFunctions;
QV4::Function *linkToEngine(QV4::ExecutionEngine *engine);
@@ -342,16 +343,6 @@ protected:
virtual QV4::Function *linkBackendToEngine(QV4::ExecutionEngine *engine) = 0;
};
-struct MothCompilationUnit : public CompilationUnit
-{
- virtual ~MothCompilationUnit() {
- // free all bytecode
- }
-
- // vector of bytecode
-
-};
-
}
}
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp
index 8e09e57525..11c0873c76 100644
--- a/src/qml/compiler/qv4compiler.cpp
+++ b/src/qml/compiler/qv4compiler.cpp
@@ -297,8 +297,10 @@ int QV4::Compiler::JSUnitGenerator::writeFunction(char *f, int index, QQmlJS::V4
locals[i] = getStringId(*irFunction->locals.at(i));
// write line number mappings
- quint32 *mappingsToWrite = (quint32*)(f + function->lineNumberMappingOffset);
- memcpy(mappingsToWrite, lineNumberMapping->constData(), 2 * function->nLineNumberMappingEntries * sizeof(quint32));
+ if (function->nLineNumberMappingEntries) {
+ quint32 *mappingsToWrite = (quint32*)(f + function->lineNumberMappingOffset);
+ memcpy(mappingsToWrite, lineNumberMapping->constData(), 2 * function->nLineNumberMappingEntries * sizeof(quint32));
+ }
// write inner functions
quint32 *innerFunctions = (quint32 *)(f + function->innerFunctionsOffset);
diff --git a/src/qml/compiler/qv4isel_masm_p.h b/src/qml/compiler/qv4isel_masm_p.h
index 35b2345109..f05aa016ef 100644
--- a/src/qml/compiler/qv4isel_masm_p.h
+++ b/src/qml/compiler/qv4isel_masm_p.h
@@ -69,7 +69,6 @@ struct CompilationUnit : public QV4::CompiledData::CompilationUnit
// Coderef + execution engine
- QList<QV4::Function *> runtimeFunctions;
QVector<JSC::MacroAssemblerCodeRef> codeRefs;
};
diff --git a/src/qml/compiler/qv4isel_moth.cpp b/src/qml/compiler/qv4isel_moth.cpp
index f7dd4d2e47..b950a987c4 100644
--- a/src/qml/compiler/qv4isel_moth.cpp
+++ b/src/qml/compiler/qv4isel_moth.cpp
@@ -46,6 +46,7 @@
#include <private/qv4debugging_p.h>
#include <private/qv4function_p.h>
#include <private/qv4regexpobject_p.h>
+#include <private/qv4compileddata_p.h>
#undef USE_TYPE_INFO
@@ -198,6 +199,7 @@ InstructionSelection::InstructionSelection(QV4::ExecutionEngine *engine, V4IR::M
, _stackSlotAllocator(0)
, _currentStatement(0)
{
+ compilationUnit = new CompilationUnit;
}
InstructionSelection::~InstructionSelection()
@@ -275,8 +277,7 @@ void InstructionSelection::run(QV4::Function *vmFunction, V4IR::Function *functi
// TODO: patch stack size (the push instruction)
patchJumpAddresses();
- _vmFunction->code = VME::exec;
- _vmFunction->codeData = squeezeCode();
+ codeRefs.insert(_function, squeezeCode());
if (QV4::Debugging::Debugger *debugger = engine()->debugger)
debugger->setPendingBreakpoints(_vmFunction);
@@ -297,6 +298,19 @@ void InstructionSelection::run(QV4::Function *vmFunction, V4IR::Function *functi
delete[] codeStart;
}
+QV4::CompiledData::CompilationUnit *InstructionSelection::backendCompileStep()
+{
+ compilationUnit->data = jsUnitGenerator.generateUnit();
+ compilationUnit->runtimeFunctions.reserve(jsUnitGenerator.irModule->functions.size());
+ compilationUnit->codeRefs.resize(jsUnitGenerator.irModule->functions.size());
+ int i = 0;
+ foreach (V4IR::Function *irFunction, jsUnitGenerator.irModule->functions) {
+ compilationUnit->runtimeFunctions << _irToVM[irFunction];
+ compilationUnit->codeRefs[i++] = codeRefs[irFunction];
+ }
+ return compilationUnit;
+}
+
void InstructionSelection::callValue(V4IR::Temp *value, V4IR::ExprList *args, V4IR::Temp *result)
{
Instruction::CallValue call;
@@ -1046,11 +1060,12 @@ void InstructionSelection::patchJumpAddresses()
_addrs.clear();
}
-uchar *InstructionSelection::squeezeCode() const
+QByteArray InstructionSelection::squeezeCode() const
{
int codeSize = _codeNext - _codeStart;
- uchar *squeezed = new uchar[codeSize];
- ::memcpy(squeezed, _codeStart, codeSize);
+ QByteArray squeezed;
+ squeezed.resize(codeSize);
+ ::memcpy(squeezed.data(), _codeStart, codeSize);
return squeezed;
}
@@ -1085,3 +1100,28 @@ Instr::Param InstructionSelection::getParam(V4IR::Expr *e) {
return Param();
}
}
+
+
+QV4::Function *CompilationUnit::linkBackendToEngine(QV4::ExecutionEngine *engine)
+{
+ QV4::Function *rootRuntimeFunction = 0;
+
+ const QV4::CompiledData::Function *compiledRootFunction = data->functionAt(data->indexOfRootFunction);
+
+ for (int i = 0 ;i < runtimeFunctions.size(); ++i) {
+ QV4::Function *runtimeFunction = runtimeFunctions.at(i);
+ const QV4::CompiledData::Function *compiledFunction = data->functionAt(i);
+
+ runtimeFunction->init(this, compiledFunction,
+ &VME::exec, /*size - doesn't matter for moth*/0);
+
+ runtimeFunction->codeData = reinterpret_cast<const uchar *>(codeRefs.at(i).constData());
+
+ if (compiledFunction == compiledRootFunction) {
+ assert(!rootRuntimeFunction);
+ rootRuntimeFunction = runtimeFunction;
+ }
+ }
+
+ return rootRuntimeFunction;
+}
diff --git a/src/qml/compiler/qv4isel_moth_p.h b/src/qml/compiler/qv4isel_moth_p.h
index 57fc9644ad..b32fba43f5 100644
--- a/src/qml/compiler/qv4isel_moth_p.h
+++ b/src/qml/compiler/qv4isel_moth_p.h
@@ -56,6 +56,15 @@ namespace Moth {
class StackSlotAllocator;
+struct CompilationUnit : public QV4::CompiledData::CompilationUnit
+{
+ virtual QV4::Function *linkBackendToEngine(QV4::ExecutionEngine *engine);
+
+ QVector<QByteArray> codeRefs;
+
+};
+
+
class Q_QML_EXPORT InstructionSelection:
public V4IR::IRDecoder,
public EvalInstructionSelection
@@ -67,6 +76,8 @@ public:
virtual void run(QV4::Function *vmFunction, V4IR::Function *function);
protected:
+ virtual QV4::CompiledData::CompilationUnit *backendCompileStep();
+
virtual void visitJump(V4IR::Jump *);
virtual void visitCJump(V4IR::CJump *);
virtual void visitRet(V4IR::Ret *);
@@ -157,7 +168,7 @@ private:
inline ptrdiff_t addInstruction(const InstrData<Instr> &data);
ptrdiff_t addInstructionHelper(Instr::Type type, Instr &instr);
void patchJumpAddresses();
- uchar *squeezeCode() const;
+ QByteArray squeezeCode() const;
QV4::String *identifier(const QString &s);
@@ -175,6 +186,9 @@ private:
StackSlotAllocator *_stackSlotAllocator;
V4IR::Stmt *_currentStatement;
+
+ CompilationUnit *compilationUnit;
+ QHash<V4IR::Function *, QByteArray> codeRefs;
};
class Q_QML_EXPORT ISelFactory: public EvalISelFactory
diff --git a/src/qml/compiler/qv4isel_p.h b/src/qml/compiler/qv4isel_p.h
index 314af517f9..e265a1e39d 100644
--- a/src/qml/compiler/qv4isel_p.h
+++ b/src/qml/compiler/qv4isel_p.h
@@ -80,7 +80,7 @@ protected:
QV4::Function *createFunctionMapping(QV4::Function *outer, V4IR::Function *irFunction);
QV4::ExecutionEngine *engine() const { return _engine; }
virtual void run(QV4::Function *vmFunction, V4IR::Function *function) = 0;
- virtual QV4::CompiledData::CompilationUnit *backendCompileStep() { return 0; }
+ virtual QV4::CompiledData::CompilationUnit *backendCompileStep() = 0;
private:
QV4::ExecutionEngine *_engine;
diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp
index 3891bb7000..8c95452f3c 100644
--- a/src/qml/jsruntime/qv4function.cpp
+++ b/src/qml/jsruntime/qv4function.cpp
@@ -57,7 +57,6 @@ Function::~Function()
UnwindHelper::deregisterFunction(this); // ### move to masm compilation unit
Q_ASSERT(!refCount);
- delete[] codeData;
foreach (Function *f, nestedFunctions)
f->deref();
if (compilationUnit)