macaw/macaw-semmc
Ryan Scott c9cbb4c7fc Support building with GHC 9.2
This contains various tweaks needed to make the packages in the `macaw` repo
build with GHC 9.2:

* In `template-haskell-2.18.*`, the type of `ConP` gained an additional field
  (see [here](https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.2?version_id=7e2ce63ba042c1934654c4316dc02028d8d3dd31#template-haskell-218)).
  As a result, I needed to use some CPP in `macaw-semmc:Data.Macaw.SemMC.TH` to
  make the two uses of `ConP` compile. To minimize the amount of CPP that I
  needed, I factored out this logic into a `conPCompat` function.
* The following submodules were bumped to bring in changes needed to support
  building with GHC 9.2:
  * `asl-translator`: GaloisInc/asl-translator#45
  * `dismantle`: travitch/dismantle#39
  * `dwarf`: GaloisInc/dwarf#5
  * `elf-edit`: GaloisInc/elf-edit#32
  * `flexdis86`: GaloisInc/flexdis86#39
  * `grift`: GaloisInc/grift#6
  * `semmc`: GaloisInc/semmc#75
2022-05-31 15:50:48 -04:00
..
src/Data/Macaw/SemMC Support building with GHC 9.2 2022-05-31 15:50:48 -04:00
ChangeLog.md first commit 2017-08-28 15:48:55 -07:00
LICENSE first commit 2017-08-28 15:48:55 -07:00
macaw-semmc.cabal Submodule updates (#291) 2022-05-24 18:45:23 -07:00
README.rst Documentation updates 2018-05-21 17:53:01 -07:00
Setup.hs first commit 2017-08-28 15:48:55 -07:00

Overview
========

This repository implements some shared code that can be re-used by multiple
architecture-specific backends to bridge the semantics defined in the semmc
repository [SemMC]_ to macaw [macaw]_.  The semantics in SemMC are defined in
terms of the ExprBuilder [EB]_ IR from Crucible/What4.  The code in this library
translates those ExprBuilder-based formulas into a Haskell function that
generates macaw IR expressions (see the ``genExecInstruction`` function in
``Data.Macaw.SemMC.TH``).  This repository contains code shared between all
architectures; the intent is that each architecture will also define
architecture-specific operations that are taken as an input to this library.

Architecture-Specific Backends
==============================

See macaw-ppc as an example for what is required in an architecture-specific
backend.  At a high level, the required steps are:

1. Define an architecture-specific register type
2. Define architecture-specific functions and statements
3. Define a transformation from architecture-specific locations into TH expressions
4. Define a function to translate ExprBuilder ``NonceApp``s into TH expressions
5. Define a function translate ExprBuilder ``App``s into TH expressions
6. Define a function to translate *instructions* into TH expressions

Architecture-Specific Register Type
-----------------------------------

Architecture-Specific Functions
-------------------------------

Translating Architecture-Specific Locations
-------------------------------------------

Translating ``NonceApp``
------------------------

This translator is for translating architecture-specific uninterpreted
functions, which are represented using ``NonceApp`` in ExprBuilder.  These
will be most often translated into architecture-specific functions, but may also
require architecture-specific statements to represent side effects (including
exceptions).  This is also where all floating point operations are translated,
as there are no floating point operations in macaw.

Translating ``App``
-------------------

Very few ``App`` constructors in ExprBuilder require custom translation.  This
is primarily intended to translate division-type operations into
architecture-specific functions, as there are no division operations defined in
macaw.

Translating Instructions
------------------------

The final specialized matcher is for doing direct translations of instructions
into architecture-specific statements.  This is meant for instructions for which
we cannot express semantics in the ExprBuilder IR due to special side effects.
Often, trap and system call-type instructions fall into this category.

Note that this function is specified by TH ``Name`` instead of as a value-level
function; this is required, as its type signature refers to an
architecture-specific type, which we cannot mention in this shared library
without incurring undesired dependencies.


.. [SemMC] https://github.com/GaloisInc/semmc
.. [macaw] https://github.com/GaloisInc/macaw
.. [EB] https://github.com/GaloisInc/crucible/blob/master/what4/src/What4/Expr/Builder.hs