diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-09-25 20:53:10 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-09-25 20:53:10 +0100 |
commit | 1e33e1510bc5891f040137b0c33fa8d49fe3a4c9 (patch) | |
tree | 7ff8718150856104a62661a659589bb8e9818f23 /src/Micro | |
parent | 0c2b9dc0c37505a5134f904ea867f2a311bfe162 (diff) | |
download | micro-lang-hs-1e33e1510bc5891f040137b0c33fa8d49fe3a4c9.tar.gz micro-lang-hs-1e33e1510bc5891f040137b0c33fa8d49fe3a4c9.zip |
Slightly better
Diffstat (limited to 'src/Micro')
-rw-r--r-- | src/Micro/Asm/Sdcc.hs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Micro/Asm/Sdcc.hs b/src/Micro/Asm/Sdcc.hs index a3f83ed..af4e7d7 100644 --- a/src/Micro/Asm/Sdcc.hs +++ b/src/Micro/Asm/Sdcc.hs @@ -62,6 +62,17 @@ mul8 a b p = do toLabel loop0 True ] +mul :: A.Expr -> A.Expr -> SourcePos -> [String] +mul a b@(A.Num v _) p + | v == 2 = oCode (emit a) ++ ["\tsla a"] + | v == 4 = oCode (emit a) ++ replicate 2 "\tsla a" + | v == 8 = oCode (emit a) ++ replicate 3 "\tsla a" + | v == 16 = oCode (emit a) ++ replicate 4 "\tsla a" + | v == 32 = oCode (emit a) ++ replicate 5 "\tsla a" + | v < 6 = oCode (emit a) ++ ["\tld c, a"] ++ replicate (fromInteger v - 1) "\tadd c" + | otherwise = mul8 a b p +mul _ _ _ = [";; unimplemented"] + data Output = Output { oPre :: [String], oInit :: [String], @@ -104,14 +115,9 @@ emit x = o {oCode = ["\txor a"]} (A.BinOp A.Mul _ (A.Num 1 _) b) -> o {oCode = oCode (emit b)} (A.BinOp A.Mul _ a (A.Num 1 _)) -> o {oCode = oCode (emit a)} - (A.BinOp A.Mul _ a (A.Num 2 _)) -> - o {oCode = oCode (emit a) ++ ["\tsla a"]} - (A.BinOp A.Mul _ (A.Num 2 _) b) -> - o {oCode = oCode (emit b) ++ ["\tsla a"]} - (A.BinOp A.Mul _ a (A.Num v _)) -> - o {oCode = oCode (emit a) ++ ["\tld c, a"] ++ replicate (fromInteger v - 1) "\tadd c"} - (A.BinOp A.Mul p a b) -> do - o {oCode = mul8 a b p} + (A.BinOp A.Mul pos a b@(A.Num _ _)) -> o {oCode = mul a b pos} + (A.BinOp A.Mul pos a@(A.Num _ _) b) -> o {oCode = mul b a pos} + (A.BinOp A.Mul p a b) -> o {oCode = mul8 a b p} (A.BinOp A.Assign _ (A.Variable id _) b) -> o {oCode = oCode (emit b) ++ ["\tld (" ++ toIdent id ++ "), a"]} _ -> o {oCode = [";; unimplemented " ++ show x]} |