Skip to content

Commit ea4398f

Browse files
committed
[clang][bytecode] jumpcase
1 parent 373ae2f commit ea4398f

7 files changed

Lines changed: 21 additions & 4 deletions

File tree

clang/lib/AST/ByteCode/ByteCodeEmitter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ bool ByteCodeEmitter::jumpTrue(const LabelTy &Label, SourceInfo SI) {
225225
return emitJt(getOffset(Label), SI);
226226
}
227227

228+
bool ByteCodeEmitter::jumpCase(const LabelTy &Label, SourceInfo SI) {
229+
return emitJc(getOffset(Label), SI);
230+
}
231+
228232
bool ByteCodeEmitter::jumpFalse(const LabelTy &Label, SourceInfo SI) {
229233
return emitJf(getOffset(Label), SI);
230234
}

clang/lib/AST/ByteCode/ByteCodeEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ByteCodeEmitter {
5555

5656
/// Emits jumps.
5757
bool jumpTrue(const LabelTy &Label, SourceInfo SI);
58+
bool jumpCase(const LabelTy &Label, SourceInfo SI);
5859
bool jumpFalse(const LabelTy &Label, SourceInfo SI);
5960
bool jump(const LabelTy &Label, SourceInfo SI);
6061
bool fallthrough(const LabelTy &Label);

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6675,7 +6675,7 @@ bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
66756675
// Compare and jump to the case label.
66766676
if (!this->emitEQ(ValueT, S))
66776677
return false;
6678-
if (!this->jumpTrue(CaseLabels[CS], S))
6678+
if (!this->jumpCase(CaseLabels[CS], S))
66796679
return false;
66806680
} else {
66816681
assert(!DefaultLabel);

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ bool EvalEmitter::jumpTrue(const LabelTy &Label, SourceInfo SI) {
161161
return true;
162162
}
163163

164+
bool EvalEmitter::jumpCase(const LabelTy &Label, SourceInfo SI) {
165+
return jumpTrue(Label, SI);
166+
}
167+
164168
bool EvalEmitter::jumpFalse(const LabelTy &Label, SourceInfo SI) {
165169
if (isActive()) {
166170
CurrentSource = SI;

clang/lib/AST/ByteCode/EvalEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class EvalEmitter : public SourceMapper {
7373

7474
/// Emits jumps.
7575
bool jumpTrue(const LabelTy &Label, SourceInfo SI);
76+
bool jumpCase(const LabelTy &Label, SourceInfo SI);
7677
bool jumpFalse(const LabelTy &Label, SourceInfo SI);
7778
bool jump(const LabelTy &Label, SourceInfo SI);
7879
bool fallthrough(const LabelTy &Label);

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ static bool Jmp(InterpState &S, CodePtr &PC, int32_t Offset) {
6262
return S.noteStep(PC);
6363
}
6464

65-
static bool Jt(InterpState &S, CodePtr &PC, int32_t Offset) {
66-
if (S.Stk.pop<bool>()) {
65+
/// jumpCase - like jumpTrue, but we do not note a step.
66+
static bool Jc(InterpState &S, CodePtr &PC, int32_t Offset) {
67+
if (S.Stk.pop<bool>())
6768
PC += Offset;
68-
}
69+
return true;
70+
}
71+
72+
static bool Jt(InterpState &S, CodePtr &PC, int32_t Offset) {
73+
Jc(S, PC, Offset);
6974
return S.noteStep(PC);
7075
}
7176

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ class JumpOpcode : Opcode {
175175
def Jmp : JumpOpcode;
176176
// [Bool] -> [], jumps if true.
177177
def Jt : JumpOpcode;
178+
// [Bool] -> [], jumps if true. Does NOT count as a step.
179+
def Jc : JumpOpcode;
178180
// [Bool] -> [], jumps if false.
179181
def Jf : JumpOpcode;
180182

0 commit comments

Comments
 (0)