1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef frontend_JumpList_h
8 #define frontend_JumpList_h
10 #include <stddef.h> // ptrdiff_t
12 #include "frontend/BytecodeOffset.h" // BytecodeOffset
13 #include "js/TypeDecls.h" // jsbytecode
18 // Linked list of jump instructions that need to be patched. The linked list is
19 // stored in the bytes of the incomplete bytecode that will be patched, so no
20 // extra memory is needed, and patching the instructions destroys the list.
25 // if (!emitJump(JSOp::JumpIfFalse, &brList)) {
30 // if (!emitJumpTarget(&label)) {
34 // if (!emitJump(JSOp::Goto, &brList)) {
38 // patchJumpsToTarget(brList, label);
40 // +-> (the delta is END_OF_LIST_DELTA (=0) for the last
44 // JumpIfFalse .. <+ + +-+ JumpIfFalse ..
46 // label: | +-> label:
47 // JumpTarget | | JumpTarget
49 // Goto .. <+ +----+ +-+ Goto .. <+
56 // +------- patchJumpsToTarget -------+
59 // Offset of a jump target instruction, used for patching jump instructions.
61 BytecodeOffset offset
= BytecodeOffset::invalidOffset();
65 // Delta value for pre-patchJumpsToTarget that marks the end of the link.
66 static const ptrdiff_t END_OF_LIST_DELTA
= 0;
68 // -1 is used to mark the end of jump lists.
69 JumpList() : offset(BytecodeOffset::invalidOffset()) {}
71 BytecodeOffset offset
;
73 // Add a jump instruction to the list.
74 void push(jsbytecode
* code
, BytecodeOffset jumpOffset
);
76 // Patch all jump instructions in this list to jump to `target`. This
78 void patchAll(jsbytecode
* code
, JumpTarget target
);
81 } /* namespace frontend */
84 #endif /* frontend_JumpList_h */