diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2017-11-21 12:29:40 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-11-21 12:29:40 +0100 |
commit | d373d5e7d70e968cfba8957596ed6fe4f46990c8 (patch) | |
tree | c52bf2b0fbbfdb13d644b4050aa7a931ef4b7109 /tools | |
parent | 9880acb424fd814501ba5fc4ae1caa989e23fafa (diff) | |
parent | 9af8a47746b69b6040fc149c1d24602a1e25b08f (diff) |
Merge remote-tracking branch 'origin/wip/new-backend' into dev
Conflicts:
src/qml/compiler/qv4isel_moth.cpp
src/qml/compiler/qv4jsir_p.h
src/qml/jsruntime/qv4engine_p.h
src/qml/jsruntime/qv4vme_moth.cpp
tests/auto/qml/qml.pro
Change-Id: Ia7b6ec24c7fcbcbb1786d9e798d2df294020ae37
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.cpp | 73 | ||||
-rw-r--r-- | tools/qmljs/qmljs.cpp | 148 |
2 files changed, 76 insertions, 145 deletions
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index a62adc82f4..d8af157b8e 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -35,17 +35,7 @@ #include <QHashFunctions> #include <private/qqmlirbuilder_p.h> -#include <private/qv4isel_moth_p.h> #include <private/qqmljsparser_p.h> -#include <private/qv4jssimplifier_p.h> - -QT_BEGIN_NAMESPACE - -namespace QV4 { namespace JIT { -Q_QML_EXPORT QV4::EvalISelFactory *createISelForArchitecture(const QString &architecture); -} } - -QT_END_NAMESPACE struct Error { @@ -128,7 +118,7 @@ static bool checkArgumentsObjectUseInSignalHandlers(const QmlIR::Document &doc, auto compiledFunction = doc.jsModule.functions.value(object->runtimeFunctionIndices.at(binding->value.compiledScriptIndex)); if (!compiledFunction) continue; - if (compiledFunction->usesArgumentsObject) { + if (compiledFunction->usesArgumentsObject == QV4::Compiler::Context::ArgumentsObjectUsed) { error->message = QLatin1Char(':') + QString::number(compiledFunction->line) + QLatin1Char(':'); if (compiledFunction->column > 0) error->message += QString::number(compiledFunction->column) + QLatin1Char(':'); @@ -145,7 +135,7 @@ static bool checkArgumentsObjectUseInSignalHandlers(const QmlIR::Document &doc, return true; } -static bool compileQmlFile(const QString &inputFileName, const QString &outputFileName, QV4::EvalISelFactory *iselFactory, const QString &targetABI, Error *error) +static bool compileQmlFile(const QString &inputFileName, const QString &outputFileName, const QString &targetABI, Error *error) { QmlIR::Document irDocument(/*debugMode*/false); irDocument.jsModule.targetABI = targetABI; @@ -180,7 +170,11 @@ static bool compileQmlFile(const QString &inputFileName, const QString &outputFi annotateListElements(&irDocument); { - QmlIR::JSCodeGen v4CodeGen(/*empty input file name*/QString(), irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable); + QmlIR::JSCodeGen v4CodeGen(irDocument.code, + &irDocument.jsGenerator, &irDocument.jsModule, + &irDocument.jsParserEngine, irDocument.program, + /*import cache*/0, &irDocument.jsGenerator.stringTable); + v4CodeGen.setUseFastLookups(false); // Disable lookups in non-standalone (aka QML) mode for (QmlIR::Object *object: qAsConst(irDocument.objects)) { if (object->functionsAndExpressions->count == 0) continue; @@ -210,17 +204,7 @@ static bool compileQmlFile(const QString &inputFileName, const QString &outputFi } QmlIR::QmlUnitGenerator generator; - - { - QQmlJavaScriptBindingExpressionSimplificationPass pass(irDocument.objects, &irDocument.jsModule, &irDocument.jsGenerator); - pass.reduceTranslationBindings(); - } - - QV4::ExecutableAllocator allocator; - QScopedPointer<QV4::EvalInstructionSelection> isel(iselFactory->create(/*engine*/nullptr, &allocator, &irDocument.jsModule, &irDocument.jsGenerator)); - // Disable lookups in non-standalone (aka QML) mode - isel->setUseFastLookups(false); - irDocument.javaScriptCompilationUnit = isel->compile(/*generate unit*/false); + irDocument.javaScriptCompilationUnit = v4CodeGen.generateCompilationUnit(/*generate unit*/false); QV4::CompiledData::Unit *unit = generator.generate(irDocument); unit->flags |= QV4::CompiledData::Unit::StaticData; unit->flags |= QV4::CompiledData::Unit::PendingTypeCompilation; @@ -234,7 +218,7 @@ static bool compileQmlFile(const QString &inputFileName, const QString &outputFi return true; } -static bool compileJSFile(const QString &inputFileName, const QString &outputFileName, QV4::EvalISelFactory *iselFactory, const QString &targetABI, Error *error) +static bool compileJSFile(const QString &inputFileName, const QString &outputFileName, const QString &targetABI, Error *error) { QmlIR::Document irDocument(/*debugMode*/false); irDocument.jsModule.targetABI = targetABI; @@ -289,8 +273,13 @@ static bool compileJSFile(const QString &inputFileName, const QString &outputFil } { - QmlIR::JSCodeGen v4CodeGen(inputFileName, irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable); - v4CodeGen.generateFromProgram(/*empty input file name*/QString(), sourceCode, program, &irDocument.jsModule, QQmlJS::Codegen::GlobalCode); + irDocument.jsModule.fileName = inputFileName; + QmlIR::JSCodeGen v4CodeGen(irDocument.code, &irDocument.jsGenerator, + &irDocument.jsModule, &irDocument.jsParserEngine, + irDocument.program, /*import cache*/0, + &irDocument.jsGenerator.stringTable); + v4CodeGen.setUseFastLookups(false); // Disable lookups in non-standalone (aka QML) mode + v4CodeGen.generateFromProgram(inputFileName, sourceCode, program, &irDocument.jsModule, QV4::Compiler::GlobalCode); QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors(); if (!jsErrors.isEmpty()) { for (const QQmlJS::DiagnosticMessage &e: qAsConst(jsErrors)) { @@ -304,11 +293,7 @@ static bool compileJSFile(const QString &inputFileName, const QString &outputFil QmlIR::QmlUnitGenerator generator; - QV4::ExecutableAllocator allocator; - QScopedPointer<QV4::EvalInstructionSelection> isel(iselFactory->create(/*engine*/nullptr, &allocator, &irDocument.jsModule, &irDocument.jsGenerator)); - // Disable lookups in non-standalone (aka QML) mode - isel->setUseFastLookups(false); - irDocument.javaScriptCompilationUnit = isel->compile(/*generate unit*/false); + irDocument.javaScriptCompilationUnit = v4CodeGen.generateCompilationUnit(/*generate unit*/false); QV4::CompiledData::Unit *unit = generator.generate(irDocument); unit->flags |= QV4::CompiledData::Unit::StaticData; irDocument.javaScriptCompilationUnit->data = unit; @@ -360,17 +345,12 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - QScopedPointer<QV4::EvalISelFactory> isel; - const QString targetArchitecture = parser.value(targetArchitectureOption); - - isel.reset(QV4::JIT::createISelForArchitecture(targetArchitecture)); - - if (parser.isSet(checkIfSupportedOption)) { - if (isel.isNull()) - return EXIT_FAILURE; - else - return EXIT_SUCCESS; - } +// if (parser.isSet(checkIfSupportedOption)) { +// if (isel.isNull()) +// return EXIT_FAILURE; +// else +// return EXIT_SUCCESS; +// } const QStringList sources = parser.positionalArguments(); if (sources.isEmpty()){ @@ -381,9 +361,6 @@ int main(int argc, char **argv) } const QString inputFile = sources.first(); - if (!isel) - isel.reset(new QV4::Moth::ISelFactory); - Error error; QString outputFileName = inputFile + QLatin1Char('c'); @@ -393,12 +370,12 @@ int main(int argc, char **argv) const QString targetABI = parser.value(targetABIOption); if (inputFile.endsWith(QLatin1String(".qml"))) { - if (!compileQmlFile(inputFile, outputFileName, isel.data(), targetABI, &error)) { + if (!compileQmlFile(inputFile, outputFileName, targetABI, &error)) { error.augment(QLatin1String("Error compiling qml file: ")).print(); return EXIT_FAILURE; } } else if (inputFile.endsWith(QLatin1String(".js"))) { - if (!compileJSFile(inputFile, outputFileName, isel.data(), targetABI, &error)) { + if (!compileJSFile(inputFile, outputFileName, targetABI, &error)) { error.augment(QLatin1String("Error compiling qml file: ")).print(); return EXIT_FAILURE; } diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp index 182547490d..a8dd19228e 100644 --- a/tools/qmljs/qmljs.cpp +++ b/tools/qmljs/qmljs.cpp @@ -32,24 +32,13 @@ #include "private/qv4errorobject_p.h" #include "private/qv4globalobject_p.h" #include "private/qv4codegen_p.h" -#if QT_CONFIG(qml_interpreter) -#include "private/qv4isel_moth_p.h" -#include "private/qv4vme_moth_p.h" -#endif #include "private/qv4objectproto_p.h" -#include "private/qv4isel_p.h" #include "private/qv4mm_p.h" #include "private/qv4context_p.h" #include "private/qv4script_p.h" #include "private/qv4string_p.h" #include "private/qqmlbuiltinfunctions_p.h" -#ifdef V4_ENABLE_JIT -# include "private/qv4isel_masm_p.h" -#else -QT_REQUIRE_CONFIG(qml_interpreter); -#endif // V4_ENABLE_JIT - #include <QtCore/QCoreApplication> #include <QtCore/QFile> #include <QtCore/QFileInfo> @@ -87,32 +76,10 @@ int main(int argc, char *argv[]) QStringList args = app.arguments(); args.removeFirst(); - enum { - use_masm, - use_moth - } mode; -#ifdef V4_ENABLE_JIT - mode = use_masm; -#else - mode = use_moth; -#endif - bool runAsQml = false; bool cache = false; if (!args.isEmpty()) { - if (args.constFirst() == QLatin1String("--jit")) { - mode = use_masm; - args.removeFirst(); - } - -#if QT_CONFIG(qml_interpreter) - if (args.constFirst() == QLatin1String("--interpret")) { - mode = use_moth; - args.removeFirst(); - } -#endif - if (args.constFirst() == QLatin1String("--qml")) { runAsQml = true; args.removeFirst(); @@ -129,79 +96,66 @@ int main(int argc, char *argv[]) } } - switch (mode) { - case use_masm: - case use_moth: { - QV4::EvalISelFactory* iSelFactory = 0; - if (mode == use_moth) { -#if QT_CONFIG(qml_interpreter) - iSelFactory = new QV4::Moth::ISelFactory; -#endif -#ifdef V4_ENABLE_JIT - } else { - iSelFactory = new QV4::JIT::ISelFactory<>; -#endif // V4_ENABLE_JIT - } - - QV4::ExecutionEngine vm(iSelFactory); + QV4::ExecutionEngine vm; - QV4::Scope scope(&vm); - QV4::ScopedContext ctx(scope, vm.rootContext()); + QV4::Scope scope(&vm); + QV4::ScopedContext ctx(scope, vm.rootContext()); - QV4::GlobalExtensions::init(vm.globalObject, QJSEngine::ConsoleExtension | QJSEngine::GarbageCollectionExtension); + QV4::GlobalExtensions::init(vm.globalObject, QJSEngine::ConsoleExtension | QJSEngine::GarbageCollectionExtension); - for (const QString &fn : qAsConst(args)) { - QFile file(fn); - if (file.open(QFile::ReadOnly)) { - QScopedPointer<QV4::Script> script; - if (cache && QFile::exists(fn + QLatin1Char('c'))) { - QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = iSelFactory->createUnitForLoading(); - QString error; - if (unit->loadFromDisk(QUrl::fromLocalFile(fn), QFileInfo(fn).lastModified(), iSelFactory, &error)) { - script.reset(new QV4::Script(&vm, nullptr, unit)); - } else { - std::cout << "Error loading" << qPrintable(fn) << "from disk cache:" << qPrintable(error) << std::endl; - } + for (const QString &fn : qAsConst(args)) { + QFile file(fn); + if (file.open(QFile::ReadOnly)) { + QScopedPointer<QV4::Script> script; + if (cache && QFile::exists(fn + QLatin1Char('c'))) { + QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Compiler::Codegen::createUnitForLoading(); + QString error; + if (unit->loadFromDisk(QUrl::fromLocalFile(fn), QFileInfo(fn).lastModified(), &error)) { + script.reset(new QV4::Script(&vm, nullptr, unit)); + } else { + std::cout << "Error loading" << qPrintable(fn) << "from disk cache:" << qPrintable(error) << std::endl; } - if (!script) { - const QString code = QString::fromUtf8(file.readAll()); - file.close(); + } + if (!script) { + const QString code = QString::fromUtf8(file.readAll()); + file.close(); - script.reset(new QV4::Script(ctx, code, fn)); - script->parseAsBinding = runAsQml; - script->parse(); - } - QV4::ScopedValue result(scope); - if (!scope.engine->hasException) { - const auto unit = script->compilationUnit; - if (cache && unit && !(unit->data->flags & QV4::CompiledData::Unit::StaticData)) { - if (unit->data->sourceTimeStamp == 0) { - const_cast<QV4::CompiledData::Unit*>(unit->data)->sourceTimeStamp = QFileInfo(fn).lastModified().toMSecsSinceEpoch(); - } - QString saveError; - if (!unit->saveToDisk(QUrl::fromLocalFile(fn), &saveError)) { - std::cout << "Error saving JS cache file: " << qPrintable(saveError) << std::endl; - } + script.reset(new QV4::Script(ctx, QV4::Compiler::GlobalCode, code, fn)); + script->parseAsBinding = runAsQml; + script->parse(); + } + QV4::ScopedValue result(scope); + if (!scope.engine->hasException) { + const auto unit = script->compilationUnit; + if (cache && unit && !(unit->data->flags & QV4::CompiledData::Unit::StaticData)) { + if (unit->data->sourceTimeStamp == 0) { + const_cast<QV4::CompiledData::Unit*>(unit->data)->sourceTimeStamp = QFileInfo(fn).lastModified().toMSecsSinceEpoch(); + } + QString saveError; + if (!unit->saveToDisk(QUrl::fromLocalFile(fn), &saveError)) { + std::cout << "Error saving JS cache file: " << qPrintable(saveError) << std::endl; } - result = script->run(); - } - if (scope.engine->hasException) { - QV4::StackTrace trace; - QV4::ScopedValue ex(scope, scope.engine->catchException(&trace)); - showException(ctx, ex, trace); - return EXIT_FAILURE; - } - if (!result->isUndefined()) { - if (! qgetenv("SHOW_EXIT_VALUE").isEmpty()) - std::cout << "exit value: " << qPrintable(result->toQString()) << std::endl; } - } else { - std::cerr << "Error: cannot open file " << fn.toUtf8().constData() << std::endl; +// QElapsedTimer t; t.start(); + result = script->run(); +// std::cout << t.elapsed() << " ms. elapsed" << std::endl; + } + if (scope.engine->hasException) { + QV4::StackTrace trace; + QV4::ScopedValue ex(scope, scope.engine->catchException(&trace)); + showException(ctx, ex, trace); return EXIT_FAILURE; } + if (!result->isUndefined()) { + if (! qgetenv("SHOW_EXIT_VALUE").isEmpty()) + std::cout << "exit value: " << qPrintable(result->toQString()) << std::endl; + } + } else { + std::cerr << "Error: cannot open file " << fn.toUtf8().constData() << std::endl; + return EXIT_FAILURE; } + } - vm.memoryManager->dumpStats(); - } return EXIT_SUCCESS; - } // switch (mode) + vm.memoryManager->dumpStats(); + return EXIT_SUCCESS; } |