Пример #1
0
func buildShift(b *builder, ret, A, B *ref, op string) {
	if types.IsSigned(A.Type()) {
		b.b.Arith(ret.IR(), A.IR(), op, B.IR())
	} else {
		if op == ">>" {
			b.b.Arith(ret.IR(), A.IR(), "u>>", B.IR())
		} else {
			b.b.Arith(ret.IR(), A.IR(), op, B.IR())
		}
	}
}
Пример #2
0
func checkArrayIndex(b *builder, index *ref) ir.Ref {
	t := index.Type()
	if types.IsSigned(t) {
		neg := b.newCond()
		b.b.Arith(neg, nil, "<0", index.IR())
		negPanic := b.f.NewBlock(b.b)
		after := b.f.NewBlock(negPanic)
		b.b.JumpIfNot(neg, after)

		b.b = negPanic
		callPanic(b, "index is negative")

		b.b = after
	}
	return index.IR()
}