diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-11-17 18:14:43 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-11-17 18:16:26 -0800 |
commit | 1696ed831a99585c22701953790c5c8e4ef7f8f3 (patch) | |
tree | 6381ba382399f8a453536a18ad1c280c66818d39 /mu_instructions | |
parent | 83221b4e21ec4cc8996362472987a49552df1e0b (diff) | |
download | mu-1696ed831a99585c22701953790c5c8e4ef7f8f3.tar.gz |
7261 - mu.subx: array bounds-checking done
Diffstat (limited to 'mu_instructions')
-rw-r--r-- | mu_instructions | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/mu_instructions b/mu_instructions index f487d29a..bd00e7a4 100644 --- a/mu_instructions +++ b/mu_instructions @@ -312,24 +312,28 @@ var/reg: (addr T) <- address var2: T => "8d/copy-address *(ebp+" var2.stack-offset ") " reg "/r32" # Array operations -(TODO: bounds-checking) var/reg <- index arr/rega: (addr array T), idx/regi: int - | if size-of(T) is 4 or 8 - => "8d/copy-address *(" rega "+" regi "<<" log2(size-of(T)) "+4) " reg "/r32" + | if size-of(T) is 1, 2, 4 or 8 + => "(__check-mu-array-bounds *" rega " %" regi " " size-of(T) ")" + "8d/copy-address *(" rega "+" regi "<<" log2(size-of(T)) "+4) " reg "/r32" var/reg <- index arr: (array T len), idx/regi: int - => "8d/copy-address *(ebp+" regi "<<" log2(size-of(T)) "+" (arr.stack-offset + 4) ") " reg "/r32" + => "(__check-mu-array-bounds *(ebp+" arr.stack-offset ") %" regi " " size-of(T) ")" + "8d/copy-address *(ebp+" regi "<<" log2(size-of(T)) "+" (arr.stack-offset + 4) ") " reg "/r32" var/reg <- index arr/rega: (addr array T), n - => "8d/copy-address *(" rega "+" (n*size-of(T)+4) ") " reg "/r32" + => "(__check-mu-array-bounds *" rega " " n " " size-of(T) ")" + "8d/copy-address *(" rega "+" (n*size-of(T)+4) ") " reg "/r32" var/reg <- index arr: (array T len), n - => "8d/copy-address *(ebp+" (arr.stack-offset+4+n*size-of(T)) ") " reg "/r32" + => "(__check-mu-array-bounds *(ebp+" arr.stack-offset ") " n " " size-of(T) ")" + "8d/copy-address *(ebp+" (arr.stack-offset+4+n*size-of(T)) ") " reg "/r32" var/reg: (offset T) <- compute-offset arr: (addr array T), idx/regi: int # arr can be in reg or mem => "69/multiply %" regi " " size-of(T) "/imm32 " reg "/r32" var/reg: (offset T) <- compute-offset arr: (addr array T), idx: int # arr can be in reg or mem => "69/multiply *(ebp+" idx.stack-offset ") " size-of(T) "/imm32 " reg "/r32" -var/reg <- index arr/rega: (addr array T), o/rego: offset - => "8d/copy-address *(" rega "+" rego "+4) " reg "/r32" +var/reg <- index arr/rega: (addr array T), o/rego: (offset T) + => "(__check-mu-array-bounds %" rega " %" rego " 1 \"" function-name "\")" + "8d/copy-address *(" rega "+" rego "+4) " reg "/r32" Computing the length of an array is complex. |