fix: array bounds checks in place
This commit is contained in:
@@ -22,6 +22,7 @@ object asmGenerator {
|
|||||||
private val RSI = Register(Q64, SI)
|
private val RSI = Register(Q64, SI)
|
||||||
private val RDX = Register(Q64, DX)
|
private val RDX = Register(Q64, DX)
|
||||||
private val RCX = Register(Q64, CX)
|
private val RCX = Register(Q64, CX)
|
||||||
|
private val ECX = Register(D32, CX)
|
||||||
private val argRegs = List(DI, SI, DX, CX, R8, R9)
|
private val argRegs = List(DI, SI, DX, CX, R8, R9)
|
||||||
|
|
||||||
extension [T](chain: Chain[T])
|
extension [T](chain: Chain[T])
|
||||||
@@ -195,8 +196,8 @@ object asmGenerator {
|
|||||||
chain ++= evalExprOntoStack(x)
|
chain ++= evalExprOntoStack(x)
|
||||||
chain += stack.pop(RAX)
|
chain += stack.pop(RAX)
|
||||||
chain += stack.pop(RCX)
|
chain += stack.pop(RCX)
|
||||||
// chain += Compare(RAX, RCX)
|
chain += Compare(MemLocation(RAX, D32), ECX)
|
||||||
// chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.GreaterEqual)
|
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.LessEqual)
|
||||||
chain += stack.pop(RDX)
|
chain += stack.pop(RDX)
|
||||||
|
|
||||||
chain += Move(
|
chain += Move(
|
||||||
@@ -301,6 +302,8 @@ object asmGenerator {
|
|||||||
chain += Compare(RCX, ImmediateVal(0))
|
chain += Compare(RCX, ImmediateVal(0))
|
||||||
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less)
|
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less)
|
||||||
chain += stack.pop(RAX)
|
chain += stack.pop(RAX)
|
||||||
|
chain += Compare(MemLocation(RAX, D32), ECX)
|
||||||
|
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.LessEqual)
|
||||||
// + Int because we store the length of the array at the start
|
// + Int because we store the length of the array at the start
|
||||||
chain += Move(
|
chain += Move(
|
||||||
Register(x.ty.elemSize, AX),
|
Register(x.ty.elemSize, AX),
|
||||||
|
|||||||
Reference in New Issue
Block a user