From 2d1e10ba539d009093c29a4bf1db3e322e6e49c4 Mon Sep 17 00:00:00 2001 From: Olle Fredriksson Date: Mon, 27 May 2024 23:41:36 +0200 Subject: [PATCH] Print LLVM code with --print-lowered Just for inspection for now. --- src/Compiler.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Compiler.hs b/src/Compiler.hs index 055c64c..b48f8bb 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -2,12 +2,16 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TupleSections #-} module Compiler where import qualified Data.ByteString.Lazy as Lazy +import qualified Data.OrderedHashSet as OrderedHashSet import Data.String (String) import Low.Pretty as Pretty +import qualified LowToLLVM +import Monad (runM) import qualified Name import qualified Paths_sixty as Paths import Prettyprinter @@ -38,6 +42,13 @@ compile assemblyDir saveAssembly outputExecutableFile maybeOptimisationLevel pri forM_ maybeLoweredDef \loweredDef -> liftIO $ putDocW 120 $ Pretty.prettyDefinition emptyPrettyEnv defName loweredDef <> line <> line + lowDefs <- + catMaybes <$> forM (OrderedHashSet.toList defNames) \defName -> do + maybeLoweredDef <- fetch $ Query.LoweredDefinition defName + pure $ (defName,) <$> maybeLoweredDef + llvmIR <- runM $ LowToLLVM.assembleModule lowDefs + putStrLn llvmIR + llvmModule <- fetch $ Query.LLVMModule moduleName let llvmFileName = moduleAssemblyDir toS moduleNameText <.> "ll" liftIO $ Lazy.writeFile llvmFileName llvmModule