Fixed the ordering of data types.

This commit is contained in:
Samuel Hammersberg 2023-04-12 15:15:38 +02:00
parent 2b7715714e
commit 0ab13e5979

View file

@ -1,16 +1,17 @@
module Codegen.Codegen (generateCode) where module Codegen.Codegen (generateCode) where
import Codegen.CompilerState ( import Codegen.CompilerState (
CodeGenerator (instructions), CodeGenerator (instructions),
initCodeGenerator, initCodeGenerator,
) )
import Codegen.Emits (compileScs) import Codegen.Emits (compileScs)
import Codegen.LlvmIr as LIR (llvmIrToString) import Codegen.LlvmIr as LIR (llvmIrToString)
import Control.Monad.State ( import Control.Monad.State (
execStateT, execStateT,
) )
import Data.List (sortBy)
import Grammar.ErrM (Err) import Grammar.ErrM (Err)
import Monomorphizer.MonomorphizerIr as MIR (Program (..)) import Monomorphizer.MonomorphizerIr as MIR (Def (DBind, DData), Program (..))
{- | Compiles an AST and produces a LLVM Ir string. {- | Compiles an AST and produces a LLVM Ir string.
An easy way to actually "compile" this output is to An easy way to actually "compile" this output is to
@ -18,5 +19,10 @@ import Monomorphizer.MonomorphizerIr as MIR (Program (..))
-} -}
generateCode :: MIR.Program -> Err String generateCode :: MIR.Program -> Err String
generateCode (MIR.Program scs) = do generateCode (MIR.Program scs) = do
let codegen = initCodeGenerator scs let codegen = initCodeGenerator scs
llvmIrToString . instructions <$> execStateT (compileScs scs) codegen llvmIrToString . instructions <$> execStateT (compileScs (sortBy lowData scs)) codegen
lowData :: Def -> Def -> Ordering
lowData (DData _) (DBind _) = LT
lowData (DBind _) (DData _) = GT
lowData _ _ = EQ