Integrated the garbage collector.

This commit is contained in:
Samuel Hammersberg 2023-03-30 12:31:03 +02:00
parent bbe0d77a19
commit b3525db7fd
5 changed files with 21 additions and 12 deletions

View file

@ -135,7 +135,7 @@ defaultStart =
, UnsafeRaw "declare i32 @printf(ptr noalias nocapture, ...)\n"
, UnsafeRaw "declare i32 @exit(i32 noundef)\n"
, UnsafeRaw "declare ptr @malloc(i32 noundef)\n"
, UnsafeRaw "declare void @_ZN2GC4Heap4initEv()\n"
, UnsafeRaw "declare void @_ZN2GC4Heap5allocEm()\n"
, UnsafeRaw "declare void @_ZN2GC4Heap7disposeEv()\n"
, UnsafeRaw "declare external void @cheap_init()\n"
, UnsafeRaw "declare external ptr @cheap_alloc(i64)\n"
, UnsafeRaw "declare external void @cheap_dispose()\n"
]

View file

@ -127,12 +127,13 @@ compileScs (MIR.DData (MIR.Data typ ts) : xs) = do
compileScs xs
firstMainContent :: [LLVMIr]
firstMainContent = []
firstMainContent = [UnsafeRaw "call void @cheap_init()\n"]
lastMainContent :: LLVMValue -> [LLVMIr]
lastMainContent var =
[ UnsafeRaw $
"call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef " <> toIr var <> ")\n"
, UnsafeRaw "call void @cheap_dispose()\n"
, Ret I64 (VInteger 0)
]
@ -169,6 +170,7 @@ emitECased t e cases = do
-- crashLbl <- TIR.Ident . ("crash_" <>) . show <$> getNewLabel
-- emit $ Label crashLbl
emit . UnsafeRaw $ "call i32 (ptr, ...) @printf(ptr noundef @.non_exhaustive_patterns, i64 noundef 6, i64 noundef 6)\n"
emit . UnsafeRaw $ "call void @cheap_dispose()\n"
emit . UnsafeRaw $ "call i32 @exit(i32 noundef 1)\n"
mapM_ (const increaseVarCount) [0 .. 1]
emit $ Br label

View file

@ -225,7 +225,7 @@ llvmIrToString = go 0
(Alloca t) -> unwords ["alloca", toIr t, "\n"]
(Malloca t) ->
concat
[ "call ptr @malloc(i32 ", show t, ")\n"]
[ "call ptr @cheap_alloc(i64 ", show t, ")\n"]
(Store t1 val t2 (Ident id2)) ->
concat
[ "store ", toIr t1, " ", toIr val