Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crucible-llvm-syntax: Concrete syntax for Crucible-LLVM #1113

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5aeddeb
crucible-syntax: Export parsing helpers for positive nats
langston-barrett Oct 31, 2023
4aa29f4
crucible-syntax: Allow passing parser hooks to `doParseCheck`
langston-barrett Oct 31, 2023
8a351b4
crucible-llvm-syntax: Concrete syntax for Crucible-LLVM
langston-barrett Oct 31, 2023
24d5da1
crucible-llvm-syntax: Allow arbitrary widths in pointer types
langston-barrett Oct 31, 2023
3367f5b
crucible-llvm-syntax: Remove dead code
langston-barrett Oct 31, 2023
63caae5
crucible-llvm-syntax: Fix warnings in test suite
langston-barrett Oct 31, 2023
1b2122a
crucible-llvm-syntax: Parse pointer type as an atom name, not a string
langston-barrett Oct 31, 2023
826112a
crucible-llvm-syntax: Add null pointer statement
langston-barrett Oct 31, 2023
4229b6f
crucible-llvm-syntax: Simplify parsing of pointer types
langston-barrett Oct 31, 2023
3d7ced7
crucible-llvm-syntax: README
langston-barrett Oct 31, 2023
2c6c89c
crucible-llvm-syntax: Fix hlint warnings
langston-barrett Oct 31, 2023
7b4c01e
crucible-llvm-syntax: Syntax for all LLVM expressions
langston-barrett Oct 31, 2023
cae6232
crucible-llvm-syntax: Syntax for LLVM alloca statement
langston-barrett Oct 31, 2023
42e85c3
crucible-llvm-syntax: Syntax for LLVM load, store statements
langston-barrett Oct 31, 2023
7022ffa
crucible-llvm-syntax: Additional documentation
langston-barrett Nov 1, 2023
00bf64e
crucible-llvm-syntax: Remove redundant `do`
langston-barrett Nov 1, 2023
dd5af77
crucible-llvm-syntax: Add haddock
langston-barrett Nov 1, 2023
30fbe47
crucible-llvm-syntax: README tweaks
langston-barrett Nov 1, 2023
a7a96a5
crucible-llvm-syntax: README typo
langston-barrett Nov 1, 2023
c9674d0
crucible-llvm-syntax: `BV` -> `Bitvector`
langston-barrett Nov 1, 2023
5c340c8
crucible-llvm-syntax: Improve error messages with `describe`
langston-barrett Nov 1, 2023
f4b2c4f
crucible-llvm-syntax: Add golden test files to extra-source-files
langston-barrett Nov 1, 2023
abac7c9
ci: Tweak syntax of hlint command
langston-barrett Nov 1, 2023
bb3501b
crucible-llvm-syntax: Add type signature for GHC 8.10 compatibility
langston-barrett Nov 1, 2023
18e4db9
crucible-llvm-syntax: Fix README typo
langston-barrett Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
crucible-llvm-syntax: Concrete syntax for Crucible-LLVM
This commit introduces an instance of crucible-syntax's `ParserHooks` for the
LLVM language extension. It's far from optimal or complete, but later commits
can build on this foundation.
  • Loading branch information
langston-barrett committed Oct 31, 2023
commit 8a351b4cb994c2c99f65f25056d27d7b09aa7b08
19 changes: 13 additions & 6 deletions .github/workflows/crux-llvm-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,28 @@ jobs:
setup_src() { if [ ! -f Setup.hs ] ; then defsetup > DefSetup.hs; fi; ls *Setup.hs; }
setup_bin() { echo setup.${{ matrix.ghc }}; }
with_ghc() { $NS -c ${@}; }
(cd crucible; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crucible-llvm; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crux; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crux-llvm; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd uc-crux-llvm; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crucible; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crucible-llvm; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crucible-llvm-syntax; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crux; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd crux-llvm; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
(cd uc-crux-llvm; with_ghc ghc -o $(setup_bin) $(setup_src) && ./$(setup_bin) clean)
langston-barrett marked this conversation as resolved.
Show resolved Hide resolved


- shell: bash
run: .github/ci.sh configure

- shell: bash
run: |
.github/ci.sh build lib:crucible-llvm-syntax
.github/ci.sh build exe:crux-llvm
.github/ci.sh build exe:crux-llvm-for-ide
.github/ci.sh build exe:crux-llvm-svcomp
.github/ci.sh build exe:uc-crux-llvm

- shell: bash
name: Haddock
run: cabal v2-haddock crucible-symio crucible-llvm crux-llvm uc-crux-llvm
run: cabal v2-haddock crucible-symio crucible-llvm{,-syntax} crux-llvm uc-crux-llvm

- shell: bash
name: Test crucible
Expand All @@ -189,6 +191,11 @@ jobs:
LLVM_AS: "llvm-as-12"
CLANG: "clang-12"

- shell: bash
name: Test crucible-llvm-syntax (Linux)
run: .github/ci.sh test crucible-llvm-syntax
if: runner.os == 'Linux'

- shell: bash
name: Test crux-llvm (Linux)
run: .github/ci.sh test crux-llvm
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/uc-crux-llvm-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ jobs:

- shell: bash
run: |
cd uc-crux-llvm/
curl --location -o hlint.tar.gz \
https://github.com/ndmitchell/hlint/releases/download/v3.3/hlint-3.3-x86_64-linux.tar.gz
tar xvf hlint.tar.gz
./hlint-3.3/hlint exe src test

pushd crucible-llvm-syntax/
../hlint-3.3/hlint src test
popd
langston-barrett marked this conversation as resolved.
Show resolved Hide resolved

cd uc-crux-llvm/
../hlint-3.3/hlint exe src test

- uses: mrkkrp/ormolu-action@v2
# This is currently disabled, since it complains about
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages:
crucible-go/
crucible-jvm/
crucible-llvm/
crucible-llvm-syntax/
crucible-mir/
crucible-wasm/
crucible-syntax/
Expand Down
8 changes: 8 additions & 0 deletions crucible-llvm-syntax/.hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# HLint's default suggestions are opinionated, so we disable all of them by
# default and enable just a small subset we can agree on.

- ignore: {} # ignore all
- error: { name: "Redundant do" }
- error: { name: "Use unless" }
- error: { name: "Use when" }

30 changes: 30 additions & 0 deletions crucible-llvm-syntax/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2023 Galois Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

* Neither the name of Galois, Inc. nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124 changes: 124 additions & 0 deletions crucible-llvm-syntax/crucible-llvm-syntax.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
Cabal-version: 2.2
Name: crucible-llvm-syntax
Version: 0.1
Author: Galois Inc.
Maintainer: [email protected]
Build-type: Simple
License: BSD-3-Clause
License-file: LICENSE
Category: Language
Synopsis: A syntax for reading and writing Crucible-LLVM control-flow graphs
-- Description:

extra-doc-files: README.md
extra-source-files:
langston-barrett marked this conversation as resolved.
Show resolved Hide resolved

common shared
-- Specifying -Wall and -Werror can cause the project to fail to build on
-- newer versions of GHC simply due to new warnings being added to -Wall. To
-- prevent this from happening we manually list which warnings should be
-- considered errors. We also list some warnings that are not in -Wall, though
-- try to avoid "opinionated" warnings (though this judgement is clearly
-- subjective).
--
-- Warnings are grouped by the GHC version that introduced them, and then
-- alphabetically.
--
-- A list of warnings and the GHC version in which they were introduced is
-- available here:
-- https://ghc.gitlab.haskell.org/ghc/doc/users_guide/using-warnings.html

-- Since GHC 8.10 or earlier:
ghc-options:
-Wall
-Werror=compat-unqualified-imports
-Werror=deferred-type-errors
-Werror=deprecated-flags
-Werror=deprecations
-Werror=deriving-defaults
-Werror=dodgy-foreign-imports
-Werror=duplicate-exports
-Werror=empty-enumerations
-Werror=identities
-Werror=inaccessible-code
-Werror=incomplete-patterns
-Werror=incomplete-record-updates
-Werror=incomplete-uni-patterns
-Werror=inline-rule-shadowing
-Werror=missed-extra-shared-lib
-Werror=missing-exported-signatures
-Werror=missing-fields
-Werror=missing-home-modules
-Werror=missing-methods
-Werror=overflowed-literals
-Werror=overlapping-patterns
-Werror=partial-fields
-Werror=partial-type-signatures
-Werror=simplifiable-class-constraints
-Werror=star-binder
-Werror=star-is-type
-Werror=tabs
-Werror=typed-holes
-Werror=unrecognised-pragmas
-Werror=unrecognised-warning-flags
-Werror=unsupported-calling-conventions
-Werror=unsupported-llvm-version
-Werror=unticked-promoted-constructors
-Werror=unused-imports
-Werror=warnings-deprecations
-Werror=wrong-do-bind

if impl(ghc >= 9.2)
ghc-options:
-Werror=ambiguous-fields
-Werror=operator-whitespace
-Werror=operator-whitespace-ext-conflict
-Werror=redundant-bang-patterns

if impl(ghc >= 9.4)
ghc-options:
-Werror=forall-identifier
-Werror=misplaced-pragmas
-Werror=redundant-strictness-flags
-Werror=type-equality-out-of-scope
-Werror=type-equality-requires-operators
ghc-prof-options: -O2 -fprof-auto-top
default-language: Haskell2010

library
import: shared

build-depends:
base >= 4.16,
crucible >= 0.1,
crucible-llvm,
crucible-syntax,
mtl,
parameterized-utils >= 0.1.7,
text,
what4,

hs-source-dirs: src

exposed-modules:
Lang.Crucible.LLVM.Syntax

test-suite crucible-llvm-syntax-tests
type: exitcode-stdio-1.0
main-is: Test.hs
hs-source-dirs: test
build-depends:
base,
containers,
crucible >= 0.1,
crucible-llvm,
crucible-llvm-syntax,
crucible-syntax,
directory,
filepath,
parameterized-utils >= 0.1.7,
tasty,
tasty-golden,
tasty-hunit,
text,
what4,
70 changes: 70 additions & 0 deletions crucible-llvm-syntax/src/Lang/Crucible/LLVM/Syntax.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeApplications #-}

module Lang.Crucible.LLVM.Syntax where

import Control.Monad (unless)
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.State.Strict (MonadState(..))
import Control.Monad.Writer.Strict (MonadWriter(..))
import Data.Functor ((<&>))

import Data.Parameterized.NatRepr (knownNat)
import Data.Parameterized.Some (Some(..))

import What4.ProgramLoc (Posd(..))

import Lang.Crucible.CFG.Reg (Atom(..), Stmt(..))
import Lang.Crucible.CFG.Extension (IsSyntaxExtension)
import Lang.Crucible.Types (TypeRepr(..))

import Lang.Crucible.LLVM.Extension (LLVM)
import Lang.Crucible.LLVM.MemModel (pattern LLVMPointerRepr)

import Lang.Crucible.Syntax.Atoms (Atomic)
import Lang.Crucible.Syntax.Concrete (ParserHooks(..), SyntaxState)
import Lang.Crucible.Syntax.ExprParse (MonadSyntax)
import qualified Lang.Crucible.Syntax.Concrete as Parse
import qualified Lang.Crucible.Syntax.ExprParse as Parse

unary :: MonadSyntax Atomic m => m b -> m a -> m a
unary p0 p = Parse.followedBy p0 (Parse.commit *> Parse.cons p Parse.emptyList) <&> fst
langston-barrett marked this conversation as resolved.
Show resolved Hide resolved

llvmParserHooks :: ParserHooks LLVM
llvmParserHooks =
ParserHooks
{ extensionTypeParser = llvmTypeParser
, extensionParser = llvmAtomParser
}

llvmTypeParser :: MonadSyntax Atomic m => m (Some TypeRepr)
llvmTypeParser = Parse.describe "LLVM type" $ Parse.call ptrType
where
ptrType :: MonadSyntax Atomic m => m (Some TypeRepr)
ptrType = do
let ptrName = do
atom <- Parse.string
unless (atom == "Ptr") Parse.cut

let ptrWidth = do
atom <- Parse.string
if atom == "64"
then pure (Some (LLVMPointerRepr (knownNat @64)))
else Parse.cut

unary ptrName ptrWidth

llvmAtomParser ::
( MonadSyntax Atomic m
, MonadWriter [Posd (Stmt ext s)] m
, MonadState (SyntaxState s) m
, MonadIO m
, IsSyntaxExtension ext
, ?parserHooks :: ParserHooks ext
) =>
m (Some (Atom s))
llvmAtomParser = Parse.cut
1 change: 1 addition & 0 deletions crucible-llvm-syntax/test-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.out
3 changes: 3 additions & 0 deletions crucible-llvm-syntax/test-data/ptr.cbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(defun @test-ptr ((_ ("Ptr" "64"))) Bool
(start start:
(return #t)))
9 changes: 9 additions & 0 deletions crucible-llvm-syntax/test-data/ptr.out.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(defun @test-ptr ((_ "Ptr64")) Bool (start start: (return #t)))

test-ptr
%0
% 3:13
$1 = boolLit(True)
% 3:5
return $1
% no postdom
Loading