Skip to content

Commit

Permalink
Print LLVM code with --print-lowered
Browse files Browse the repository at this point in the history
Just for inspection for now.
  • Loading branch information
ollef committed May 27, 2024
1 parent 601676f commit 2d1e10b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d1e10b

Please sign in to comment.