public void ReplaceLastNonBranchWithBranch(int numInstrs, Block target) { if (LastInstr.IsBr()) { numInstrs++; } ReplaceLastInstrsWithBranch(numInstrs, target); }
public bool CanAppend(Block other) { if (other == null || other == this || GetOnlyTarget() != other) { return(false); } // If it's eg. a leave, then don't merge them since it clears the stack. return(LastInstr.IsBr() || Instr.IsFallThrough(LastInstr.OpCode)); }
// If last instr is a br/br.s, removes it and replaces it with a fall through public void RemoveLastBr() { if (!LastInstr.IsBr()) { return; } if (fallThrough != null || (LastInstr.Operand != null && (targets == null || targets.Count != 1))) { throw new ApplicationException("Invalid block state when last instr is a br/br.s"); } fallThrough = LastInstr.Operand != null ? targets[0] : null; targets = null; instructions.RemoveAt(instructions.Count - 1); }