diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-06-12 14:56:03 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-06-19 13:34:55 +0000 |
commit | 2c0db96b0ea1b8d4daa5d0fda8b9b22270b5ab4b (patch) | |
tree | 46cdcb6f5026716a2c9fdf8c7c7047879f0c33eb /src/qml/compiler/qv4bytecodegenerator.cpp | |
parent | 74149e479ce4252c2a22638bed002985b09b8269 (diff) |
Add a BytecodeGenerator class
Use the generator to store the list of instructions, labels
and patches. The finalize() method can then create the
final bytecode out of that list.
Change-Id: If2ea3118ed6e8744545bb918ecc4bbc87d6a3ff1
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator.cpp')
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp new file mode 100644 index 0000000000..f00a793a0b --- /dev/null +++ b/src/qml/compiler/qv4bytecodegenerator.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <private/qv4bytecodegenerator_p.h> +#include <private/qv4jsir_p.h> + +QT_USE_NAMESPACE +using namespace QV4; +using namespace Moth; + +unsigned BytecodeGenerator::newTemp() +{ + int t = function->currentTemp++; + if (function->tempCount < function->currentTemp) + function->tempCount = function->currentTemp; + return t; +} + +QByteArray BytecodeGenerator::finalize() +{ + // ### prologue + // ## push(tempcount) + // content + QByteArray code; + for (const auto &i : qAsConst(instructions)) { + code.append(reinterpret_cast<const char *>(&i.instr), i.size); + } + + return code; +} |