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

Miscellaneous cleanup #4

Merged
merged 12 commits into from
May 28, 2024
18 changes: 18 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

if ! command -v fourmolu 1>/dev/null; then
echo "error: fourmolu is not installed" 1>&2
exit 1
fi

# TODO: Add an option to fourmolu to only print file names.
files=$(git diff --diff-filter=MA --cached --name-only | \
awk '/..*\.hs/' | \
xargs -r fourmolu --mode check 2>&1 | \
awk '/[a-zA-Z.\/][a-zA-Z.\/]*\.hs/')

if [ -n "${files}" ]; then
printf "The following files need to be formated with 'fourmolu':\n\n" 1>&2
printf "%s\n" "${files}" | sed 's/^/\t/' 1>&2
exit 1
fi
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ Exemplary interpreters are available as follows:

1. The [concrete interpreter][riscv-tiny github] bundled with LibRISCV itself
2. A [symbolic interpreter][binsym github] performing [symbolic execution][symbolic execution wikipedia] of RISC-V binary code
3. An interpreter for [code generation][formal-iss github] for RISC-V simulators (uses an older LibRISCV version)
3. A [custom concrete interpreter][riscv-tests interpreter] for [riscv-tests][riscv-tests github]
4. An interpreter for [code generation][formal-iss github] for RISC-V simulators (uses an older LibRISCV version)
5. A primitive implementation of [dynamic information flow tracking][riscv-dift interpreter] (uses an older LibRISCV version)

## Concrete Interpretation

Expand Down Expand Up @@ -118,6 +120,13 @@ If these dependencies are installed (e.g. if you are using the provided Docker i

$ ./riscv-tests/run.sh

### Development

Code should be formatted using [fourmolu][fourmolu github].
A githook for this purpose is available which can be enabled using:

$ git config --local core.hooksPath .githooks

## How to Cite

LibRISCV is further described in the following publication:
Expand Down Expand Up @@ -152,6 +161,9 @@ This work was supported in part by the German Federal Ministry of Education and
[agra preprint]: https://agra.informatik.uni-bremen.de/doc/konf/TFP23_ST.pdf
[haskell edsl]: https://doi.org/10.1007/978-3-031-23669-3_10
[riscv-tiny github]: https://github.com/agra-uni-bremen/libriscv/blob/master/app/Main.hs
[riscv-tests interpreter]: https://github.com/agra-uni-bremen/libriscv/blob/master/riscv-tests/Main.hs
[riscv-dift interpreter]: https://github.com/agra-uni-bremen/libriscv/tree/tfp-2023/example
[binsym github]: https://github.com/agra-uni-bremen/binsym
[formal-iss github]: https://github.com/agra-uni-bremen/formal-iss
[symbolic execution wikipedia]: https://en.wikipedia.org/wiki/Symbolic_execution
[fourmolu github]: https://github.com/fourmolu/fourmolu
63 changes: 35 additions & 28 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}

module Main where

import Options.Applicative
import Control.Monad (when)
import Control.Monad.Freer
import Control.Monad.Freer.Reader

import LibRISCV (RegIdx(SP), align)
import LibRISCV.Loader
import LibRISCV.Semantics (buildAST, writeRegister)
import LibRISCV.CmdLine
import LibRISCV.Effects.Logging.Default.Interpreter
( defaultLogging, noLogging )
import LibRISCV.Effects.Operations.Default.Interpreter
( mkArchState, getMem, dumpState, defaultInstructions )
import qualified LibRISCV.Effects.Expressions.Expr as E
import LibRISCV.Effects.Expressions.Default.Interpreter (defaultEval, evalE)
import LibRISCV.Effects.Decoding.Default.Interpreter
( defaultDecoding )
import Data.BitVector
import qualified Debug.Trace as Debug
import Data.BitVector
import Data.IORef (newIORef)
import Data.Word (Word32)
import LibRISCV (RegIdx (SP), align)
import LibRISCV.CmdLine
import LibRISCV.Effects.Decoding.Default.Interpreter (
defaultDecoding,
)
import LibRISCV.Effects.Expressions.Default.Interpreter (defaultEval, evalE)
import qualified LibRISCV.Effects.Expressions.Expr as E
import LibRISCV.Effects.Logging.Default.Interpreter (
defaultLogging,
noLogging,
)
import LibRISCV.Effects.Operations.Default.Interpreter (
defaultInstructions,
dumpState,
getMem,
mkArchState,
)
import LibRISCV.Effects.Operations.Default.Machine.Memory (storeByteString)

import LibRISCV.Loader
import LibRISCV.Semantics (buildAST, writeRegister)
import Options.Applicative

main' :: BasicArgs -> IO ()
main' (BasicArgs memAddr memSize trace putReg fp) = do
Expand All @@ -35,14 +39,14 @@ main' (BasicArgs memAddr memSize trace putReg fp) = do
entry <- startAddr elf

instRef <- newIORef (0 :: Word32)
let
let
initalSP = align (memAddr + memSize - 1)
evalEnv = ((==1), evalE)
evalEnv = ((== 1), evalE)
interpreter =
interpretM (defaultInstructions state) .
interpretM (defaultEval evalEnv) .
interpretM (defaultDecoding @BV instRef) .
interpretM (if trace then defaultLogging else noLogging)
interpretM (defaultInstructions state)
. interpretM (defaultEval evalEnv)
. interpretM (defaultDecoding @BV instRef)
. interpretM (if trace then defaultLogging else noLogging)
runM $ interpreter $ do
writeRegister (bitVec 32 $ fromEnum SP) (E.FromInt 32 $ fromIntegral initalSP)
buildAST @32 (bitVec 32 entry)
Expand All @@ -52,7 +56,10 @@ main' (BasicArgs memAddr memSize trace putReg fp) = do

main :: IO ()
main = main' =<< execParser opts
where
opts = info (basicArgs <**> helper)
where
opts =
info
(basicArgs <**> helper)
( fullDesc
<> progDesc "Concrete execution of RV32I machine code")
<> progDesc "Concrete execution of RV32I machine code"
)
3 changes: 3 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
indentation: 4
haddock-style: single-line
respectful: false
Loading
Loading