aboutsummaryrefslogtreecommitdiff
path: root/BuildIR.hs
diff options
context:
space:
mode:
Diffstat (limited to 'BuildIR.hs')
-rw-r--r--BuildIR.hs30
1 files changed, 16 insertions, 14 deletions
diff --git a/BuildIR.hs b/BuildIR.hs
index 5b12dc2..9eb4d62 100644
--- a/BuildIR.hs
+++ b/BuildIR.hs
@@ -338,20 +338,20 @@ convertExpression (ESubscript arr sub t) nextnext = do
subref <- convertExpression sub bl3
switchBlock bl3
offref <- genTemp (refSize subref)
- off8ref <- genTemp (refSize subref)
elemptr <- genTemp (refSize arrref)
+ arrszptr <- genTemp (sizeof TInt)
arrsz <- genTemp (sizeof TInt)
errbl <- gets errorBlock
- addIns $ ILoad arrsz arrref
+ addIns $ IAri ASub arrszptr arrref (Constant (refSize arrref) (fromIntegral $ sizeof TInt))
+ addIns $ ILoad arrsz arrszptr
bl4 <- newBlockNoSwitch
setTerm $ IJcc CUGeq subref arrsz errbl bl4
switchBlock bl4
addIns $ IAri AMul offref subref (Constant (refSize subref) (fromIntegral elemsz))
- addIns $ IAri AAdd off8ref offref (Constant (refSize subref) (fromIntegral $ sizeof TInt))
- addIns $ IAri AAdd elemptr arrref off8ref
+ addIns $ IAri AAdd elemptr arrref offref
ref <- genTemp elemsz
addIns $ ILoad ref elemptr
setTerm $ IJmp nextnext
@@ -375,13 +375,15 @@ convertExpression (ENew t sze) nextnext = do
bl2 <- newBlockNoSwitch
szref <- convertExpression sze bl2
switchBlock bl2
+ ref' <- genTemp (sizeof $ TArr t Nothing)
ref <- genTemp (sizeof $ TArr t Nothing)
argref' <- genTemp (sizeof TInt)
argref <- genTemp (sizeof TInt)
addIns $ IAri AMul argref' szref (Constant (sizeof TInt) (fromIntegral $ sizeof t))
addIns $ IAri AAdd argref argref' (Constant (sizeof TInt) (fromIntegral $ sizeof TInt))
- addIns $ ICallr ref "_builtin_malloc" [argref]
- addIns $ IStore ref szref
+ addIns $ ICallr ref' "_builtin_malloc" [argref]
+ addIns $ IStore ref' szref
+ addIns $ IAri AAdd ref ref' (Constant (refSize ref') (fromIntegral $ sizeof TInt))
setTerm $ IJmp nextnext
return ref
@@ -400,20 +402,20 @@ convertAsExpression (AESubscript ae2 expr mrt) valueref nextnext = do
bl2 <- newBlockNoSwitch
subref <- convertExpression expr bl2
switchBlock bl2
- offref' <- genTemp (sizeof TInt)
offref <- genTemp (sizeof TInt)
elemptr <- genTemp (sizeof TInt)
+ arrszptr <- genTemp (sizeof TInt)
arrsz <- genTemp (sizeof TInt)
errbl <- gets errorBlock
- addIns $ ILoad arrsz ae2ref
+ addIns $ IAri ASub arrszptr ae2ref (Constant (refSize ae2ref) (fromIntegral $ sizeof TInt))
+ addIns $ ILoad arrsz arrszptr
bl3 <- newBlockNoSwitch
setTerm $ IJcc CUGeq subref arrsz errbl bl3
switchBlock bl3
- addIns $ IAri AMul offref' subref (Constant (sizeof TInt) (fromIntegral elemsz))
- addIns $ IAri AAdd offref offref' (Constant (sizeof TInt) (fromIntegral $ sizeof TInt))
+ addIns $ IAri AMul offref subref (Constant (refSize subref) (fromIntegral elemsz))
addIns $ IAri AAdd elemptr ae2ref offref
addIns $ IStore elemptr valueref
setTerm $ IJmp nextnext
@@ -434,20 +436,20 @@ convertAsExpression (AESubscript ae2 expr mrt) valueref nextnext = do
bl2 <- newBlockNoSwitch
eref <- convertExpression expr' bl2
switchBlock bl2
- offref' <- genTemp (sizeof TInt)
offref <- genTemp (sizeof TInt)
elemptr <- genTemp (sizeof TInt)
+ arrszptr <- genTemp (sizeof TInt)
arrsz <- genTemp (sizeof TInt)
errbl <- gets errorBlock
- addIns $ ILoad arrsz ref
+ addIns $ IAri ASub arrszptr ref (Constant (refSize ref) (fromIntegral $ sizeof TInt))
+ addIns $ ILoad arrsz arrszptr
bl3 <- newBlockNoSwitch
setTerm $ IJcc CUGeq eref arrsz errbl bl3
switchBlock bl3
- addIns $ IAri AMul offref' eref (Constant (sizeof TInt) (fromIntegral elemsz))
- addIns $ IAri AAdd offref offref' (Constant (sizeof TInt) (fromIntegral $ sizeof TInt))
+ addIns $ IAri AMul offref eref (Constant (sizeof TInt) (fromIntegral elemsz))
addIns $ IAri AAdd elemptr ref offref
dstref <- genTemp elemsz
addIns $ ILoad dstref elemptr