diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eefe2f6..2dbd228 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,42 +11,6 @@ on: - synchronize jobs: - cabal: - runs-on: ubuntu-latest - strategy: - matrix: - ghc: ['8.4', '8.6', '8.8', '8.10', '9.0', '9.2'] - fail-fast: false - env: - CABAL_ARGS: --enable-tests --enable-benchmarks - - steps: - - uses: actions/checkout@v2 - - uses: haskell/actions/setup@v1 - id: setup-haskell-cabal - with: - ghc-version: ${{ matrix.ghc }} - - - run: cabal v2-update - - run: cabal v2-freeze $CABAL_ARGS - - - uses: actions/cache@v2 - with: - path: | - ${{ steps.setup-haskell-cabal.outputs.cabal-store }} - dist-newstyle - key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') - }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}- - - - name: Install dependencies - run: cabal v2-build $CABAL_ARGS --only-dependencies - - run: cabal v2-build $CABAL_ARGS all - - run: cabal v2-test $CABAL_ARGS - - run: cabal v2-haddock $CABAL_ARGS all - - run: cabal v2-sdist all - nix: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml new file mode 100644 index 0000000..56e8479 --- /dev/null +++ b/.github/workflows/haskell-ci.yml @@ -0,0 +1,265 @@ +# This GitHub workflow config has been generated by a script via +# +# haskell-ci 'github' 'language-c.cabal' +# +# To regenerate the script (for example after adjusting tested-with) run +# +# haskell-ci regenerate +# +# For more information, see https://github.com/haskell-CI/haskell-ci +# +# version: 0.17.20240109 +# +# REGENDATA ("0.17.20240109",["github","language-c.cabal"]) +# +name: Haskell-CI +on: + - push + - pull_request +jobs: + linux: + name: Haskell-CI - Linux - ${{ matrix.compiler }} + runs-on: ubuntu-20.04 + timeout-minutes: + 60 + container: + image: buildpack-deps:bionic + continue-on-error: ${{ matrix.allow-failure }} + strategy: + matrix: + include: + - compiler: ghc-9.8.1 + compilerKind: ghc + compilerVersion: 9.8.1 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.6.4 + compilerKind: ghc + compilerVersion: 9.6.4 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.4.8 + compilerKind: ghc + compilerVersion: 9.4.8 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.2.8 + compilerKind: ghc + compilerVersion: 9.2.8 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.0.2 + compilerKind: ghc + compilerVersion: 9.0.2 + setup-method: ghcup + allow-failure: false + - compiler: ghc-8.10.7 + compilerKind: ghc + compilerVersion: 8.10.7 + setup-method: ghcup + allow-failure: false + - compiler: ghc-8.8.4 + compilerKind: ghc + compilerVersion: 8.8.4 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-8.6.5 + compilerKind: ghc + compilerVersion: 8.6.5 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-8.4.4 + compilerKind: ghc + compilerVersion: 8.4.4 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-8.2.2 + compilerKind: ghc + compilerVersion: 8.2.2 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-8.0.2 + compilerKind: ghc + compilerVersion: 8.0.2 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-7.10.3 + compilerKind: ghc + compilerVersion: 7.10.3 + setup-method: hvr-ppa + allow-failure: false + fail-fast: false + steps: + - name: apt + run: | + apt-get update + apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 + if [ "${{ matrix.setup-method }}" = ghcup ]; then + mkdir -p "$HOME/.ghcup/bin" + curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup" + chmod a+x "$HOME/.ghcup/bin/ghcup" + "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false) + "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + else + apt-add-repository -y 'ppa:hvr/ghc' + apt-get update + apt-get install -y "$HCNAME" + mkdir -p "$HOME/.ghcup/bin" + curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup" + chmod a+x "$HOME/.ghcup/bin/ghcup" + "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + fi + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: Set PATH and environment variables + run: | + echo "$HOME/.cabal/bin" >> $GITHUB_PATH + echo "LANG=C.UTF-8" >> "$GITHUB_ENV" + echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV" + echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV" + HCDIR=/opt/$HCKIND/$HCVER + if [ "${{ matrix.setup-method }}" = ghcup ]; then + HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER") + HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#') + HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#') + echo "HC=$HC" >> "$GITHUB_ENV" + echo "HCPKG=$HCPKG" >> "$GITHUB_ENV" + echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + else + HC=$HCDIR/bin/$HCKIND + echo "HC=$HC" >> "$GITHUB_ENV" + echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV" + echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + fi + + HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))') + echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV" + echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV" + echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV" + echo "HEADHACKAGE=false" >> "$GITHUB_ENV" + echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV" + echo "GHCJSARITH=0" >> "$GITHUB_ENV" + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: env + run: | + env + - name: write cabal config + run: | + mkdir -p $CABAL_DIR + cat >> $CABAL_CONFIG <> $CABAL_CONFIG < cabal-plan.xz + echo 'f62ccb2971567a5f638f2005ad3173dba14693a45154c1508645c52289714cb2 cabal-plan.xz' | sha256sum -c - + xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan + rm -f cabal-plan.xz + chmod a+x $HOME/.cabal/bin/cabal-plan + cabal-plan --version + - name: checkout + uses: actions/checkout@v3 + with: + path: source + - name: initial cabal.project for sdist + run: | + touch cabal.project + echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project + cat cabal.project + - name: sdist + run: | + mkdir -p sdist + $CABAL sdist all --output-dir $GITHUB_WORKSPACE/sdist + - name: unpack + run: | + mkdir -p unpacked + find sdist -maxdepth 1 -type f -name '*.tar.gz' -exec tar -C $GITHUB_WORKSPACE/unpacked -xzvf {} \; + - name: generate cabal.project + run: | + PKGDIR_language_c="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/language-c-[0-9.]*')" + echo "PKGDIR_language_c=${PKGDIR_language_c}" >> "$GITHUB_ENV" + rm -f cabal.project cabal.project.local + touch cabal.project + touch cabal.project.local + echo "packages: ${PKGDIR_language_c}" >> cabal.project + if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package language-c" >> cabal.project ; fi + if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi + cat >> cabal.project <> cabal.project.local + cat cabal.project + cat cabal.project.local + - name: dump install plan + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all + cabal-plan + - name: restore cache + uses: actions/cache/restore@v3 + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store + restore-keys: ${{ runner.os }}-${{ matrix.compiler }}- + - name: install dependencies + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all + - name: build w/o tests + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: build + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always + - name: tests + run: | + $CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct + - name: cabal check + run: | + cd ${PKGDIR_language_c} || false + ${CABAL} -vnormal check + - name: haddock + run: | + $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all + - name: unconstrained build + run: | + rm -f cabal.project.local + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: save cache + uses: actions/cache/save@v3 + if: always() + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store diff --git a/ChangeLog b/ChangeLog.md similarity index 97% rename from ChangeLog rename to ChangeLog.md index c402276..36b9070 100644 --- a/ChangeLog +++ b/ChangeLog.md @@ -1,6 +1,9 @@ # Changelog -## WIP +## 0.9.3 + +- Add support for `__builtin_bit_cast` to support clang toolchain, + enabling builds with GHC 9.4+ on Windows. ## 0.9.2 diff --git a/README b/README.md similarity index 100% rename from README rename to README.md diff --git a/language-c.cabal b/language-c.cabal index 5bf0c23..2ba2cc8 100644 --- a/language-c.cabal +++ b/language-c.cabal @@ -1,123 +1,132 @@ -Name: language-c -Version: 0.9.2 -Cabal-Version: >= 1.10 -Build-Type: Simple -License: BSD3 -License-File: LICENSE -Copyright: LICENSE -Author: AUTHORS -Maintainer: language.c@monoid.al -Stability: experimental -Homepage: http://visq.github.io/language-c/ -Bug-reports: https://github.com/visq/language-c/issues/ - -Synopsis: Analysis and generation of C code -Description: Language C is a haskell library for the analysis and generation of C code. - It features a complete, well tested parser and pretty printer for all of C99 and a large - set of C11 and clang/GNU extensions. -Category: Language -Tested-With: GHC == 8.4.*, GHC == 8.6.*, GHC == 8.8.*, GHC == 8.10.*, GHC == 9.0.*, GHC == 9.2.* - -Extra-Source-Files: AUTHORS AUTHORS.c2hs ChangeLog README - src/Language/C/Parser/Lexer.x - src/Language/C/Parser/Parser.y - -Source-Repository head - type: git - location: https://github.com/visq/language-c.git - -Flag useByteStrings - Description: Use ByteString as InputStream datatype - Default: True -Flag allWarnings - Description: Turn on all warnings for building (development) - Default: False -Flag iecFpExtension - Description: Support IEC 60559 floating point extension (defines _Float128) - Default: True -Library - default-extensions: CPP, DeriveDataTypeable, DeriveGeneric, PatternGuards, BangPatterns, ExistentialQuantification, GeneralizedNewtypeDeriving, ScopedTypeVariables - Build-Depends: base >= 4.8 && < 5, - array, - containers >= 0.3, - deepseq >= 1.4.0.0 && < 1.6, - directory, - filepath, - mtl, - pretty < 1.2.0, - process - if flag(allWarnings) - if impl(ghc >= 8.0) - ghc-options: -Wall -Wno-redundant-constraints +cabal-version: 2.2 +name: language-c +version: 0.9.3 +license: BSD-3-Clause +license-file: LICENSE +copyright: LICENSE +maintainer: language.c@monoid.al +author: AUTHORS +tested-with: + ghc ==9.8.1 ghc ==9.6.4 ghc ==9.4.8 ghc ==9.2.8 ghc ==9.0.2 + ghc ==8.10.7 ghc ==8.8.4 ghc ==8.6.5 ghc ==8.4.4 ghc ==8.2.2 + ghc ==8.0.2 ghc ==7.10.3 + +homepage: https://visq.github.io/language-c/ +bug-reports: https://github.com/visq/language-c/issues/ +synopsis: Analysis and generation of C code +description: + Language C is a haskell library for the analysis and generation of C code. + It features a complete, well tested parser and pretty printer for all of C99 and a large + set of C11 and clang/GNU extensions. + +category: Language +build-type: Simple +extra-doc-files: + ChangeLog.md + README.md + AUTHORS + AUTHORS.c2hs + +source-repository head + type: git + location: https://github.com/visq/language-c.git + +flag usebytestrings + description: Use ByteString as InputStream datatype + +flag allwarnings + description: Turn on all warnings for building (development) + default: False + +flag iecfpextension + description: + Support IEC 60559 floating point extension (defines _Float128) + +library + exposed-modules: + Language.C + Language.C.Data + Language.C.Data.Position + Language.C.Data.Ident + Language.C.Data.Error + Language.C.Data.Name + Language.C.Data.Node + Language.C.Data.InputStream + Language.C.Syntax + Language.C.Syntax.AST + Language.C.Syntax.Constants + Language.C.Syntax.Ops + Language.C.Syntax.Utils + Language.C.Parser + Language.C.Pretty + Language.C.System.Preprocess + Language.C.System.GCC + Language.C.Analysis + Language.C.Analysis.ConstEval + Language.C.Analysis.Builtins + Language.C.Analysis.SemError + Language.C.Analysis.SemRep + Language.C.Analysis.DefTable + Language.C.Analysis.TravMonad + Language.C.Analysis.AstAnalysis + Language.C.Analysis.DeclAnalysis + Language.C.Analysis.Debug + Language.C.Analysis.TypeCheck + Language.C.Analysis.TypeConversions + Language.C.Analysis.TypeUtils + Language.C.Analysis.NameSpaceMap + Language.C.Analysis.MachineDescs + Language.C.Analysis.Export + + build-tool-depends: happy:happy, alex:alex + hs-source-dirs: src + other-modules: + Language.C.Data.RList + Language.C.Parser.Builtin + Language.C.Parser.Lexer + Language.C.Parser.ParserMonad + Language.C.Parser.Tokens + Language.C.Parser.Parser + + default-language: Haskell2010 + default-extensions: + CPP DeriveDataTypeable DeriveGeneric PatternGuards BangPatterns + ExistentialQuantification GeneralizedNewtypeDeriving + ScopedTypeVariables + + build-depends: + base >=4.8 && <5, + array <0.6, + containers >=0.3 && <0.8, + deepseq >=1.4.0.0 && <1.6, + directory <1.4, + filepath <1.6, + mtl <2.4, + pretty <1.2.0, + process <1.7 + + if flag(allwarnings) + if impl(ghc >=8.0) + ghc-options: -Wall -Wno-redundant-constraints + else - ghc-options: -Wall + ghc-options: -Wall + + if flag(usebytestrings) + build-depends: bytestring >=0.9.0 && <0.13 - if flag(useByteStrings) - Build-Depends: bytestring >= 0.9.0 else cpp-options: -DNO_BYTESTRING - if flag(iecFpExtension) + if flag(iecfpextension) cpp-options: -DIEC_60559_TYPES_EXT - Build-Tools: happy, alex - - Hs-Source-Dirs: src - Exposed-Modules: - -- top-level - Language.C - -- data - Language.C.Data - Language.C.Data.Position - Language.C.Data.Ident - Language.C.Data.Error - Language.C.Data.Name - Language.C.Data.Node - Language.C.Data.InputStream - -- syntax - Language.C.Syntax - Language.C.Syntax.AST - Language.C.Syntax.Constants - Language.C.Syntax.Ops - Language.C.Syntax.Utils - -- parser - Language.C.Parser - -- pretty printer - Language.C.Pretty - -- system - Language.C.System.Preprocess - Language.C.System.GCC - -- analysis [experimental] - Language.C.Analysis - Language.C.Analysis.ConstEval - Language.C.Analysis.Builtins - Language.C.Analysis.SemError - Language.C.Analysis.SemRep - Language.C.Analysis.DefTable - Language.C.Analysis.TravMonad - Language.C.Analysis.AstAnalysis - Language.C.Analysis.DeclAnalysis - Language.C.Analysis.Debug - Language.C.Analysis.TypeCheck - Language.C.Analysis.TypeConversions - Language.C.Analysis.TypeUtils - Language.C.Analysis.NameSpaceMap - Language.C.Analysis.MachineDescs - -- semrep -> code [alpha] - Language.C.Analysis.Export - Other-Modules: - Language.C.Data.RList - -- parser implementation - Language.C.Parser.Builtin - Language.C.Parser.Lexer - Language.C.Parser.ParserMonad - Language.C.Parser.Tokens - Language.C.Parser.Parser - default-language: Haskell2010 - --- test description -Test-Suite language-c-harness - type: exitcode-stdio-1.0 - main-is: test/harness/run-harness.hs - build-depends: base, directory, process, filepath +test-suite language-c-harness + type: exitcode-stdio-1.0 + main-is: test/harness/run-harness.hs default-language: Haskell2010 + build-depends: + base <5, + directory, + process, + filepath diff --git a/test/src/Language/C/Test/ParseTests.hs b/test/src/Language/C/Test/ParseTests.hs index 8e833f8..46efe48 100644 --- a/test/src/Language/C/Test/ParseTests.hs +++ b/test/src/Language/C/Test/ParseTests.hs @@ -22,10 +22,11 @@ equivTestTemplate,runEquivTest, compileTestTemplate, runCompileTest, ) where import Control.Exception -import Control.Monad.State +import Control.Monad +import Control.Monad.IO.Class (liftIO) +import Control.Monad.State (modify) import Data.List -import System.Process import System.Directory import System.Exit import System.FilePath (takeBaseName, takeExtension) diff --git a/test/src/Language/C/Test/TestMonad.hs b/test/src/Language/C/Test/TestMonad.hs index 7351f98..a8976b2 100644 --- a/test/src/Language/C/Test/TestMonad.hs +++ b/test/src/Language/C/Test/TestMonad.hs @@ -24,9 +24,11 @@ defaultMain, where import Control.Applicative (Applicative (..)) import Control.Exception (catch) -import Control.Monad.Cont -import Control.Monad.Reader -import Control.Monad.State +import Control.Monad +import Control.Monad.Cont (MonadCont, ContT, runContT, callCC) +import Control.Monad.IO.Class (MonadIO, liftIO) +import Control.Monad.Reader (MonadReader, ReaderT, runReaderT, local, ask) +import Control.Monad.State (MonadState, StateT, execStateT, put, get, modify, gets) import Data.Map (elems) import System.CPUTime import System.Directory