From 67ddbe297765c6f840ddbe429df3a0aa80f44271 Mon Sep 17 00:00:00 2001 From: Patrick LaFontaine <32135464+Pat-Lafon@users.noreply.github.com> Date: Sun, 10 Sep 2023 17:39:23 -0400 Subject: [PATCH] generalize to getLastInstr --- bril-ts/builder.ts | 12 ++++++------ ts2bril.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bril-ts/builder.ts b/bril-ts/builder.ts index 0f68f9924..63996077e 100644 --- a/bril-ts/builder.ts +++ b/bril-ts/builder.ts @@ -128,26 +128,26 @@ export class Builder { * Checks whether the last emitted instruction in the current function is the specified op code. * Useful for checking for terminating instructions. */ - isLastEmittedEffectOp(op: bril.EffectOpCode): boolean { + getLastInstr(): bril.Instruction | undefined { if (!this.curFunction) { - return false + return undefined } if (!this.curFunction.instrs) { - return false + return undefined } if (this.curFunction.instrs.length === 0) { - return false + return undefined } const last_instr : bril.Instruction | bril.Label = this.curFunction.instrs[this.curFunction.instrs.length - 1]; if ('label' in last_instr) { - return false + return undefined } - return last_instr.op === op + return last_instr } /** diff --git a/ts2bril.ts b/ts2bril.ts index 7b198015b..b009df1b9 100644 --- a/ts2bril.ts +++ b/ts2bril.ts @@ -215,7 +215,7 @@ function emitBril(prog: ts.Node, checker: ts.TypeChecker): bril.Program { // Statement chunks. builder.buildLabel(thenLab); emit(if_.thenStatement); - const then_branch_terminated = builder.isLastEmittedEffectOp("ret"); + const then_branch_terminated = builder.getLastInstr()?.op === "ret"; if (!then_branch_terminated) { builder.buildEffect("jmp", [], undefined, [endLab]); }