aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4bytecodegenerator_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Build fixes for GCC 11Ville Voutilainen2021-01-181-2/+2
| | | | | | Task-number: QTBUG-89977 Change-Id: I975a859d5252e2721475f86ced6c8dab06ae8c9c Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Restore offset/length in QQmlJS::DiagnosticMessageSimon Hausmann2020-03-021-3/+1
| | | | | | | | | | | | This is needed in a few places outside of declarative, so this change restores the loc member in DiagnosticMessage and moves QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory. QQmlError is unaffected and retains only line/column. Amends d4d197d06279f9257647628f7e1ccc9ec763a6bb Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Split compiler and runtime more clearlyUlf Hermann2019-07-111-0/+5
| | | | | | | | Provide different export macros and different top level headers for each, don't include runtime headers from compiler sources. Change-Id: I7dc3f8c95839a00a871ba045ec65af87123154be Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Make JavaScript execution interruptibleUlf Hermann2019-04-301-0/+6
| | | | | | | | | | | Add an atomic isInterrupted flag to BaseEngine and check that in addition to the hasException flag on checkException(). Add some more exception checks to cover all possible infinite loops. Also, remove the writeBarrierActive member from QV4::EngineBase. It isn't used. Fixes: QTBUG-49080 Change-Id: I86b3114e3e61aff3e5eb9b020749a908ed801c2b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove tracing JIT infrastructureUlf Hermann2019-04-291-47/+6
| | | | | | | | The tracing JIT won't be finished. Therefore, remove the parts that have already been integrated. Change-Id: If72036be904bd7fc17ba9bcba0a317f8ed6cb30d Reviewed-by: Erik Verbruggen <erik.verbruggen@me.com>
* V4: Generate labels for backward jumpsErik Verbruggen2019-01-311-0/+10
| | | | | | | | | | | | | | | | | | | | | | | When analyzing the bytecode from top-to-bottom in a single pass, we don't know when a jump back to previously seen code occurs. For example, in the baseline JIT we would already have generated code for some bytecode when we see a jump back (like at the end of a loop body), and we can't go back and insert a label to jump to. As JavaScript has no goto's, the only backward jumps are at the end of loops, so there are very few cases where we need to actually generate labels. This was previously handled by analyzing the bytecode twice: once to collect all jump targets, and then second pass over the bytecode to do the actual JITting (which would use the jump targets to insert labels). We can now do that with one single pass. So the trade-off is to store 4 bytes more per function plus 4 bytes for each loop, instead of having to analyze all functions only to find where all jumps are each time that function is JITted. Change-Id: I3abfcb69f65851a397dbd4a9762ea5e9e57495f6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* V4: Collect trace information in the interpreterErik Verbruggen2019-01-251-10/+50
| | | | | | | | | | | | | | | Collect type information about values used in a function. These include all parameters, and the results of many bytecode instructions. For array loads/stores, it also tracks if the access is in-bounds of a SimpleArrayData. Collection is only enabled when the qml-tracing feature is turned on while configuring. In subsequent patches this is used to generated optimized JITted code. Change-Id: I63985c334c3fdc55fca7fb4addfe3e535989aac5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add initial basic support for ES6 modulesSimon Hausmann2018-08-091-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The entry point from the parsing perspective into modules is not QV4::Script but QV4::ExecutionEngine::compileModule. For convenience, the ESModule AST node gets a body, which is the statement list connected between the ModuleItemList items that are not import/export declarations. The QV4::Module allocates a call context where the exported variables are stored as named locals. This will also become the module namespace object. The imports in turn is an array of value pointers that point into the locals array of the context of the imported modules. The default module loading in ExecutionEngine assumes the accessibility of module urls via QFile (so local file system or resource). This is what qmljs also uses and QJSEngine as well via public API in the future. The test runner compiles the modules manually and injects them, because they need to be compiled together with the test harness code. The QML type loader will the mechanism for injection in the future for module imports from .qml files. Change-Id: I93be9cfe54c651fdbd08c5e1d22d58f47284e54f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Change the instruction encoding for the bytecodeLars Knoll2018-07-031-1/+1
| | | | | | | | | | | | Change the encoding, so that even instructions are short ones, odd instructions long. This implies that the lowest bit encodes whether an instruction is short or long (1 vs 4 byte encoded). This prepares for allowing us to extend the totoal number of instructions beyond 128. Change-Id: I4732e7241d3593b24ad25cd69555edc25f38d2f6 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Rework unwind handlingLars Knoll2018-06-211-24/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | The old code was rather convoluted and expanded to quite a bit of bytecode. It was also very hard to fix some of the remaining issues with unwinding in there. The new code handles unwinding a bit differently. Basically, we now have three instructions to do what the spec requires. SetUnwindHandler is the same as the old SetExceptionHandler instruction. It basically tells the runtime where to jump to to handle any abrupt completion (ie. throw/break/continue/return) that requires unwinding. UnwindToLabel is a new instruction that is used for unwinding break/continue/return statements. It takes two arguments, one telling the runtime how many levels to unwind and the second a target label to jump to when unwinding is done. UnwindDispatch is the third instruction and is invoked at the end of each unwind block to dispatch the the parent unwind handler if required and thus implement the support for the levelled unwinding. Change-Id: I079a39d0d897b3ecc2f0dc631ca29b25eae05250 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Rename SetExceptionHandler to SetUnwindHandlerLars Knoll2018-06-041-2/+2
| | | | | | | | | It's being used for more than just exception handling, unwinding for return or break/continue statements also goes through those handlers. Change-Id: I145c7909540a1adca431de6a98d9c115ddf23612 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* V4: Peephole optimize LoadReg/MoveRegErik Verbruggen2018-05-251-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | The following sequence: StoreReg rX LoadReg rX Can be optimized by dropping the LoadReg, as the value is still in the accumulator. Also, the sequence: StoreReg rX MoveReg rY, rX Can be optimized to: StoreReg rX StoreReg rY This last optimization prevents one load from the JS stack (reading rX). Both cases are only valid if there is no label on the second instruction. Change-Id: Ibd4543459e1eab4da55e92248eba544c707c5456 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Improve for-in and for-of supportLars Knoll2018-05-111-0/+1
| | | | | | | | | | | | Create a Block scope per iteration as defined in the ES spec. So closures created inside the loop will remember the iteration variable at that loop iteration. Add support for destructuring of the left hand side expression or declaration. Change-Id: Id06ef94e2a4b93646827da4f6ce922eb436e5a31 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for proper lexical scopingLars Knoll2018-05-021-2/+4
| | | | | | | | | | | | | This is still to some extend work in progress as lexically scoped for loops won't yet do the right thing. let and const variables are still accessible before they are declared, and the global scope doesn't yet have a proper context for lexically declared variables. Change-Id: Ie39f74a8fccdaead437fbf07f9fc228a444c26ed Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* ES6: add support for default arguments for function parametersLars Knoll2018-04-251-0/+6
| | | | | | | | | The parser can also handle rest parameters correctly, this will however require some additional work in the runtime to support it correctly. Change-Id: Ib6f4d27683774966b2d2aac075494d2f5066d2a2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix failing assertion when loading QML/JS on IntegrityErik Verbruggen2018-03-091-4/+15
| | | | | | | | | | | | | | | | | | | | | | With the QV4::Moth::BytecodeGenerator::Jump type we are relying on the compiler doing a return value optimization. That however is not required by the C++11 standard and the GHS compiler does indeed not do that here, resulting in a ~Jump destructor call in the following sequence _before_ link() is called: Jump generateJump() { ...; return Jump(...); } ... generateJump().link(); The destructor however verifies that link() was called, which fails. Fix this by making Jump a move-only type, which the compiler will issue if it doesn't perform a return value optimization. Task-number: QTBUG-66917 Change-Id: I97cc9a5d7f97d61e573ad8bc309cf48ab18eb25d Reviewed-by: Kimmo Ollila <kimmo.ollila@qt.io> Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* use nullptr consistently (clang-tidy)Shawn Rutledge2018-02-261-1/+1
| | | | | | | | | | | | | From now on we prefer nullptr instead of 0 to clarify cases where we are assigning or testing a pointer rather than a numeric zero. Also, replaced cases where 0 was passed as Qt::KeyboardModifiers with Qt::NoModifier (clang-tidy replaced them with nullptr, which waas wrong, so it was just as well to make the tests more readable rather than to revert those lines). Change-Id: I4735d35e4d9f42db5216862ce091429eadc6e65d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Re-enable Debug instructions and locations for QML functionsUlf Hermann2017-11-061-2/+3
| | | | | | | | | | | | | | | | | | | | | | Debug instructions are used to trigger break points and are added for every source line. We also need to insert Debug instructions before Ret, so that we can step out. We also need to assign line numbers to the entry and return points of "abbreviated" QML functions (by simulating lbrace and rbrace) so that we can set break points on them. The line numbers on Ret need to be negative, so that you cannot (accidentally) set break points on them. A typical signal handler or binding in QML consists of only one line and if you set a break point on that line, you want it to hit only once, when entering the function. If the line numbers on Ret were positive, it would be hit again on exit. Some of the tests in tst_qqmldebugjs implicitly check for that. Also the new interpreter does something on the left brace, so a function actually starts there, not on the first statement. Change-Id: Id9dfb20e35696b420d0950deab988f7cc5197bfc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix invalid condition inversion for conditional jumpsErik Verbruggen2017-09-011-12/+22
| | | | | | | | | We now have separate instructions for comparissons, which put the result in the accumulator. Then a JumpTrue/JumpFalse is generated to do the actual jump. Change-Id: I50a9d5899a6e071f4997931de6e8eb62596723cd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Compress jump instructions as wellLars Knoll2017-08-281-10/+4
| | | | | Change-Id: If95a5733594a1beaa41063249a364988190844c5 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Compress all non jump instructionsLars Knoll2017-08-281-5/+7
| | | | | Change-Id: I90daee5388f5aba5a5c1cd643379adc9a8e05039 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Start compressing the byte codeLars Knoll2017-08-281-9/+13
| | | | | | | As a first step, use only one byte for the instruction type. Change-Id: I762a05233c277a7144472793bc71e41d9e8e82cb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Get rid of the separate vector of JumpsLars Knoll2017-08-281-17/+11
| | | | | | | Instead add it to the unencoded instruction vector Change-Id: I7e88d808bb94f75aecdf9d3ed9bace2055c1da5d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Rename the Common instruction to NopLars Knoll2017-08-281-2/+2
| | | | | | | | And add Wide and XWide instructions that will get used as prefixes later on. Change-Id: I993865395ee2ac7d30eba2e41e7b437bfdb54391 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Decode instructions into registersLars Knoll2017-08-281-2/+2
| | | | | | | | Don't use the old instruction structures in the VME anymore, instead directly decode into scoped registers. Change-Id: Ie03ebad98050ebfd9eb9cc7e9273e5db92884a89 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify instruction namingLars Knoll2017-08-281-2/+2
| | | | | | | | Simplify the naming conventions, so that both the instruction struct and enum start with upper case letters. Change-Id: I60c5a95d729e0b68b5a40f7db0e8f90be5938032 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Move line number information into a side tableLars Knoll2017-08-251-3/+7
| | | | | | | | | Don't emit any Line instructions anymore, and instead store the info in a side table in the compiled data, where it can be looked up on demand. Change-Id: Idcaf3bf4ee4129fd62f9e717bf1277dc6a34fe19 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Don't use a return value register for regular functionsErik Verbruggen2017-08-181-0/+24
| | | | | | | | | | | | | | | | | | don't use the return value register for normal functions anymore. It's still needed for eval code and qml bindings that have an implicit return value, as the accumulator gets clobbered too easily in those cases. Also get rid of the exit block we used to generate. Adjust the control flow handlers to correctly unwind. This required adding some jump instructions that left the accumulator untouched (as it now holds the return value) and using those in handlers. Change-Id: I2ca1afaf7234cb632e5d26ba5b10ec3f11f50c93 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Store arguments in the stack frame before the locals/tempsErik Verbruggen2017-08-031-0/+1
| | | | | | | | | | All escaping arguments will still be loaded/stored from/to the CallData, but this is not the common case. In a subsequent patch we can make the caller prepare the stack frame, and for the common case we don't even need to copy arguments around. Change-Id: I3fbb6fe575a564d05a9fd5dcc0c8f4129eac3bc2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Where applicable, rename Temp* to Register*Erik Verbruggen2017-08-031-4/+4
| | | | | Change-Id: Ib7839ac09f520aaff3fadfdb37ea63d85a257bfd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Rename a number of types from Temp(orary) to StackSlotErik Verbruggen2017-08-031-2/+2
| | | | | | | | As a preparation to also store arguments on the stack, just like the temporaries. Change-Id: If3a6ed56930e29ad77c992811065bb32ee2d030c Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Add commonly used JumpCompare instructionsErik Verbruggen2017-08-021-5/+5
| | | | | Change-Id: I00d4ed5d8b6ab30ee3459d1cc7a2737144474f8a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Introduce an accumulator in the interpreter, and change instructionsErik Verbruggen2017-08-021-8/+4
| | | | | | | | | | | | This reduces the number of stores to the stack (for which we need a write-barrier in the future) by keeping the last calculated value in the accumulator register (which is a local variable). In the future we might want to collapse certain common instruction patterns into a super-sized instruction. Change-Id: I02ebed2db957765e994c8f939bf7585894881deb Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix various signed/unsigned warningsErik Verbruggen2017-08-021-4/+4
| | | | | Change-Id: I9f4a5a8470c1abc6b07a28c71fdad0d208e1fea1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove Moth::Param from the interpreter instructionsErik Verbruggen2017-07-191-4/+4
| | | | | | | | | The Param struct is now internal to the interpreter loop. It can be removed in a second step so we can directly access constants/temporaries/locals/arguments. Change-Id: I47ecbfe7508f352a8f212af48461dc92b35f4695 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add "we mean it" disclaimer to private headerErik Verbruggen2017-06-301-0/+10
| | | | | Change-Id: I281954d1f421c9aaaa9100a1505db0ba225cf488 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Don't use IR::Function for temp allocation anymoreLars Knoll2017-06-301-6/+4
| | | | | Change-Id: Id9ab6f3e9f5ae1c1bedb0b34bf1fac6abfe0bbfc Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Switch over to new JS call setupLars Knoll2017-06-291-1/+1
| | | | | | | | | | | | | | | | Differences: - push parameters on the stack, including space for CallData members - call instructions calculate the argument start - use temp space above the calldata to evaluate arguments - fewer temporaries are needed when a call is done while generating the arguments of another call - when calling the function, the js stack space above the callData is not used, allowing for optimizations in the future - Array and ObjectLiteral use the same mechanism Change-Id: Id100fa06f12cc9d941b0f90b0b81b8270a8e4f5d Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Various compile fixesLars Knoll2017-06-221-1/+1
| | | | | | | | Make sure all libs and tests compile again after the latest changes. Change-Id: I749d3d2d0109cc97df2ecec93809ea8a1b3014a9 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Get back some line number informationLars Knoll2017-06-201-0/+9
| | | | | Change-Id: I7d7845a9d8d147bd363c0f60df41066fab355272 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Proper exception handlingLars Knoll2017-06-201-12/+48
| | | | | | | | Implement exception handling, and make it conformant with the spec. Change-Id: I6d8222617180f96f628f18e11444488e50e5c043 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Cleanup control flow handlingLars Knoll2017-06-201-2/+4
| | | | | | | | | | | | | | Replace Loop and ScopeAndFinally with a single ControlFlow data structure, that can deal with non local control flow. The control flow data structure can do required cleanup of internal scopes (for catch or with), emit finally statements and dispatch to the right continuation. Also implemented support for the with statement again. Change-Id: I8bb5414151d0312cb28f8d10e99f8d2b64484100 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Add JumpStrict(Not)Equal instructions to the interpreterLars Knoll2017-06-201-0/+16
| | | | | | | These will simplify foreach and switch handling. Change-Id: I7fb67481d7d1b82b03c03fd0987b182ea9542c7a Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Allow defining Labels as destinations for JumpsLars Knoll2017-06-201-4/+19
| | | | | | | | Those Labels can be linked to a code location further ahead. Change-Id: I82f1a719654162db0e0abb46df602ee2e01154da Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Implement support for conditional expressionsLars Knoll2017-06-201-4/+11
| | | | | | Change-Id: Ifcd57713e1cfa9514d3955e26f739a359cdaa8e5 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Rework and implement Jump handling in the bytecode generatorLars Knoll2017-06-191-13/+58
| | | | | | | | Add Label and Jump classes to facilitate the handling, and resolve them to proper offsets at finalize() time. Change-Id: Ic140a3ceb848fb29657a1b156c97b806db6dc434 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Add the push instruction required to set up the tempsLars Knoll2017-06-191-1/+2
| | | | | | | And a commented out finalize() call to the bytecodegenerator Change-Id: Iaaf8981ee658e19b6816589d4340a8e5744764b7 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Add a BytecodeGenerator classLars Knoll2017-06-191-0/+113
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>