Skip to content

Commit

Permalink
Move to the new LLVM (#37)
Browse files Browse the repository at this point in the history
- Use `llvm-codegen`
- Use LLVM 17
- Use GHC 9.4.8
- Use cabal 3.8
- Add build requirements to README
- Update actions
  • Loading branch information
AzimMuradov authored Jun 21, 2024
1 parent 7f9ae50 commit 484ac57
Show file tree
Hide file tree
Showing 26 changed files with 567 additions and 664 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
ghc: ["8.10.7"]
cabal: ["3.6"]
os: [ubuntu-24.04]
ghc: ["9.4.8"]
cabal: ["3.8"]

steps:
- name: Checkout code
Expand All @@ -27,7 +27,7 @@ jobs:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
- name: Cache Cabal
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-cabal
with:
Expand All @@ -41,12 +41,14 @@ jobs:
with:
fail-on: warning
- name: Check for Ormolu formatting
uses: haskell-actions/run-ormolu@v14
uses: haskell-actions/run-ormolu@v16
with:
pattern: "**/*.hs"
version: 0.3.1.0
pattern: |
app/**/*.hs
lib/**/*.hs
test/**/*.hs
- name: Install LLVM
run: sudo apt install -y llvm-9 llvm-9-dev
run: sudo apt install -y llvm-17 llvm-17-dev
- name: Build project
run: cabal build
- name: Run tests
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
ghc: ["8.10.7"]
cabal: ["3.6"]
os: [ubuntu-24.04]
ghc: ["9.4.8"]
cabal: ["3.8"]

steps:
- name: Checkout code
Expand All @@ -26,15 +26,15 @@ jobs:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
- name: Cache Cabal
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-cabal
with:
path: ~/.cabal
key: ${{ runner.os }}-docs-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
restore-keys: ${{ runner.os }}-docs-${{ env.cache-name }}-
- name: Install LLVM
run: sudo apt install -y llvm-9 llvm-9-dev
run: sudo apt install -y llvm-17 llvm-17-dev
- name: Build docs
run: >
cabal haddock
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ Global options:

- [Implementation details](docs/dev/impl.md)
- [Development workflow](docs/dev/flow.md)

### Build Requirements

**GHC**: 9.4.8
**Cabal**: 3.8
**LLVM**: 17
15 changes: 11 additions & 4 deletions app/Commands/Compile.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Commands.Compile (compile) where

import CodeGen.Llvm.Runner (compileToBinary, compileToLlvmIr)
import CodeGen.TimedValue (TimedValue (TimedValue))
import Configuration.AppConfiguration (CompilationTarget (..), Compile (..), Debug (Yes), Output (..))
import Configuration.AppConfiguration (CompilationTarget (..), Compile (..), Debug (Yes), Input (..), Output (..))
import Control.Monad (when)
import Data.Text (Text)
import qualified Data.Text as Txt
import System.Exit (die)
import System.FilePath (takeBaseName)
import qualified Text.Printf as Printf
import Utils (inputToModuleName, ns2s, readText)
import Utils (ns2s, readText)

compile :: Compile -> Debug -> IO ()
compile (Compile input target output) debug = do
Expand All @@ -20,17 +22,22 @@ compile (Compile input target output) debug = do
TimedValue res compTime <- case target of
TargetBinary -> do
let outputFilePath = outputToFilePath output moduleName "out"
compileToBinary moduleName text outputFilePath
compileToBinary text outputFilePath
TargetLlvmIr -> do
let outputFilePath = outputToFilePath output moduleName "ll"
compileToLlvmIr moduleName text outputFilePath
compileToLlvmIr text outputFilePath

when (debug == Yes) $ do
putStrLn $ Printf.printf "Finished compiling in %0.5f sec" (ns2s compTime)
putStrLn ""

either (die . Txt.unpack) return res

inputToModuleName :: Input -> Text
inputToModuleName = \case
StdInput -> "unnamed"
FileInput filePath -> Txt.pack $ takeBaseName filePath

outputToFilePath :: Output -> Text -> Text -> FilePath
outputToFilePath output moduleName ext = case output of
FileOutput filePath -> filePath
Expand Down
5 changes: 2 additions & 3 deletions app/Commands/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import System.Exit (ExitCode (..), die, exitWith)
import System.IO (hPutStr)
import qualified System.IO as Sys
import qualified Text.Printf as Printf
import Utils (inputToModuleName, ns2s, readText)
import Utils (ns2s, readText)

run :: Run -> Debug -> IO ()
run (Run input) debug = do
let moduleName = inputToModuleName input
text <- readText input

runResult <- Llvm.run moduleName text
runResult <- Llvm.run text

case runResult of
Success stdout compTime runTime -> do
Expand Down
2 changes: 1 addition & 1 deletion app/Configuration/Commands/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runParserInfo :: ParserInfo Command
runParserInfo = info runParser runInfoMod

runParser :: Parser Command
runParser = CmdRun <$> (Run <$> inputParser)
runParser = CmdRun . Run <$> inputParser

runInfoMod :: InfoMod a
runInfoMod =
Expand Down
8 changes: 0 additions & 8 deletions app/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}

module Utils where

import CodeGen.TimedValue (Nanoseconds (..))
import Configuration.AppConfiguration (Input (..))
import Data.Text (Text)
import qualified Data.Text as Txt
import System.FilePath (takeBaseName)

readText :: Input -> IO Text
readText (FileInput path) = Txt.pack <$> readFile path
readText StdInput = Txt.pack <$> getContents

inputToModuleName :: Input -> Text
inputToModuleName = \case
StdInput -> "unnamed"
FileInput filePath -> Txt.pack $ takeBaseName filePath

ns2s :: Nanoseconds -> Double
ns2s ns = let Nanoseconds ns' = ns in fromInteger ns' / 1_000_000_000
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source-repository-package
type: git
location: https://github.com/luc-tielen/llvm-codegen.git
tag: 83b04cb576208ea74ddd62016e4fa03f0df138ac

packages: .
92 changes: 44 additions & 48 deletions cabal.project.freeze
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
active-repositories: hackage.haskell.org:merge
constraints: any.Cabal ==3.6.3.0,
Cabal -bundled-binary-generic,
constraints: any.Cabal ==3.8.1.0,
any.Cabal-syntax ==3.8.1.0,
any.StateVar ==1.2.2,
any.ansi-terminal ==1.0,
any.ansi-terminal ==1.1.1,
ansi-terminal -example,
any.ansi-terminal-types ==0.11.5,
any.ansi-terminal-types ==1.1,
any.array ==0.5.4.0,
any.assoc ==1.1,
assoc +tagged,
any.assoc ==1.1.1,
assoc -tagged,
any.async ==2.2.5,
async -bench,
any.attoparsec ==0.14.4,
attoparsec -developer,
any.base ==4.14.3.0,
any.base-orphans ==0.9.1,
any.bifunctors ==5.6.1,
any.base ==4.17.2.1,
any.base-orphans ==0.9.2,
any.bifunctors ==5.6.2,
bifunctors +tagged,
any.binary ==0.8.9.1,
any.bytestring ==0.11.2.0,
any.bytestring ==0.11.5.3,
any.cabal-doctest ==1.0.9,
any.call-stack ==0.4.0,
any.case-insensitive ==1.2.1.0,
Expand All @@ -26,44 +24,41 @@ constraints: any.Cabal ==3.6.3.0,
any.colour ==2.3.6,
any.comonad ==5.0.8,
comonad +containers +distributive +indexed-traversable,
any.containers ==0.6.8,
any.containers ==0.6.7,
any.contravariant ==1.5.5,
contravariant +semigroups +statevar +tagged,
any.data-array-byte ==0.1.0.1,
any.data-fix ==0.3.2,
any.deepseq ==1.4.4.0,
any.data-fix ==0.3.3,
any.deepseq ==1.4.8.0,
any.directory ==1.3.7.1,
any.distributive ==0.6.2.1,
distributive +semigroups +tagged,
any.exceptions ==0.10.4,
any.extra ==1.7.14,
any.fail ==4.9.0.0,
any.file-embed ==0.0.15.0,
any.filepath ==1.4.2.1,
any.dlist ==1.0,
dlist -werror,
any.exceptions ==0.10.5,
any.extra ==1.7.16,
any.file-embed ==0.0.16.0,
any.filepath ==1.4.2.2,
any.foldable1-classes-compat ==0.1,
foldable1-classes-compat +tagged,
any.free ==5.2,
any.ghc-boot-th ==8.10.7,
any.ghc-prim ==0.6.1,
any.hashable ==1.4.3.0,
hashable +integer-gmp -random-initial-seed,
any.hsc2hs ==0.68.10,
hsc2hs -in-ghc-tree,
any.indexed-traversable ==0.1.3,
any.integer-gmp ==1.0.3.0,
any.ghc-bignum ==1.3,
any.ghc-boot-th ==9.4.8,
any.ghc-prim ==0.9.1,
any.hashable ==1.4.6.0,
hashable +arch-native +integer-gmp -random-initial-seed,
any.indexed-traversable ==0.1.4,
any.integer-logarithms ==1.0.3.1,
integer-logarithms -check-bounds +integer-gmp,
any.llvm-hs ==9.0.1,
llvm-hs -debug +shared-llvm,
any.llvm-hs-pretty ==0.9.0.0,
any.llvm-hs-pure ==9.0.0,
any.llvm-codegen ==0.1.0.0,
any.logict ==0.8.0.0,
any.megaparsec ==9.2.1,
any.megaparsec ==9.6.1,
megaparsec -dev,
any.mmorph ==1.2.0,
any.mtl ==2.2.2,
any.optparse-applicative ==0.18.1.0,
optparse-applicative +process,
any.parsec ==3.1.17.0,
any.os-string ==2.0.3,
any.parsec ==3.1.16.1,
any.parser-combinators ==1.3.0,
parser-combinators -dev,
any.pretty ==1.1.3.6,
Expand All @@ -75,17 +70,18 @@ constraints: any.Cabal ==3.6.3.0,
any.primitive ==0.9.0.0,
any.process ==1.6.18.0,
any.profunctors ==5.6.2,
any.random ==1.2.1.1,
any.recursion-schemes ==5.2.2.5,
any.quote-quot ==0.2.1.0,
any.random ==1.2.1.2,
any.recursion-schemes ==5.2.3,
recursion-schemes +template-haskell,
any.rts ==1.0.1,
any.scientific ==0.3.7.0,
scientific -bytestring-builder -integer-simple,
any.semigroupoids ==6.0.0.1,
any.rts ==1.0.2,
any.scientific ==0.3.8.0,
scientific -integer-simple,
any.semigroupoids ==6.0.1,
semigroupoids +comonad +containers +contravariant +distributive +tagged +unordered-containers,
any.splitmix ==0.1.0.5,
splitmix -optimised-mixer,
any.stm ==2.5.0.1,
any.stm ==2.5.1.0,
any.string-conversions ==0.4.0.1,
any.string-transform ==1.1.1,
any.tagged ==0.8.8,
Expand All @@ -95,12 +91,12 @@ constraints: any.Cabal ==3.6.3.0,
any.tasty-golden ==2.3.5,
tasty-golden -build-example,
any.tasty-hunit ==0.10.1,
any.template-haskell ==2.16.0.0,
any.template-haskell ==2.19.0.0,
any.temporary ==1.3,
any.text ==2.0.2,
text -developer +simdutf,
any.th-abstraction ==0.6.0.0,
any.time ==1.9.3,
any.text-builder-linear ==0.1.2,
any.th-abstraction ==0.7.0.0,
any.time ==1.12.2,
any.transformers ==0.5.6.2,
any.transformers-base ==0.4.6,
transformers-base +orphaninstances,
Expand All @@ -110,7 +106,7 @@ constraints: any.Cabal ==3.6.3.0,
any.unification-fd ==0.11.2,
any.unix ==2.7.3,
any.unliftio-core ==0.2.1.0,
any.unordered-containers ==0.2.19.1,
any.unordered-containers ==0.2.20,
unordered-containers -debug,
any.utf8-string ==1.0.2
index-state: hackage.haskell.org 2024-01-02T19:29:37Z
index-state: hackage.haskell.org 2024-06-20T07:22:15Z
Loading

0 comments on commit 484ac57

Please sign in to comment.