diff --git a/src/Codegen/Codegen.hs b/src/Codegen/Codegen.hs index bf35f4f..810d849 100644 --- a/src/Codegen/Codegen.hs +++ b/src/Codegen/Codegen.hs @@ -1,16 +1,17 @@ module Codegen.Codegen (generateCode) where import Codegen.CompilerState ( - CodeGenerator (instructions), - initCodeGenerator, + CodeGenerator (instructions), + initCodeGenerator, ) import Codegen.Emits (compileScs) import Codegen.LlvmIr as LIR (llvmIrToString) import Control.Monad.State ( - execStateT, + execStateT, ) +import Data.List (sortBy) 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. 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 scs) = do - let codegen = initCodeGenerator scs - llvmIrToString . instructions <$> execStateT (compileScs scs) codegen + let codegen = initCodeGenerator scs + llvmIrToString . instructions <$> execStateT (compileScs (sortBy lowData scs)) codegen + +lowData :: Def -> Def -> Ordering +lowData (DData _) (DBind _) = LT +lowData (DBind _) (DData _) = GT +lowData _ _ = EQ \ No newline at end of file