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 #include "frontend/ExpressionStatementEmitter.h"
9 #include "frontend/BytecodeEmitter.h"
10 #include "vm/Opcodes.h"
13 using namespace js::frontend
;
17 ExpressionStatementEmitter::ExpressionStatementEmitter(BytecodeEmitter
* bce
,
18 ValueUsage valueUsage
)
19 : bce_(bce
), valueUsage_(valueUsage
) {}
21 bool ExpressionStatementEmitter::prepareForExpr(uint32_t beginPos
) {
22 MOZ_ASSERT(state_
== State::Start
);
24 if (!bce_
->updateSourceCoordNotes(beginPos
)) {
29 depth_
= bce_
->bytecodeSection().stackDepth();
35 bool ExpressionStatementEmitter::emitEnd() {
36 MOZ_ASSERT(state_
== State::Expr
);
37 MOZ_ASSERT(bce_
->bytecodeSection().stackDepth() == depth_
+ 1);
41 JSOp op
= valueUsage_
== ValueUsage::WantValue
? JSOp::SetRval
: JSOp::Pop
;
42 if (!bce_
->emit1(op
)) {
43 // [stack] # if WantValue
45 // [stack] # otherwise