@@ -5,7 +5,8 @@ mathematical models of the computational behavior of software,
5
5
transforming these models, and proving properties about them.
6
6
7
7
SAW can currently construct models of a subset of programs written in
8
- Cryptol, LLVM (and therefore C), and JVM (and therefore Java). The
8
+ Cryptol, LLVM (and therefore C), and JVM (and therefore Java). SAW also has
9
+ experimental, incomplete support for MIR (and therefore Rust). The
9
10
models take the form of typed functional programs, so in a sense SAW can
10
11
be considered a translator from imperative programs to their functional
11
12
equivalents. Various external proof tools, including a variety of SAT
@@ -176,7 +177,7 @@ Cryptol, Haskell and ML. In particular, functions are applied by
176
177
writing them next to their arguments rather than by using parentheses
177
178
and commas. Rather than writing ` f(x, y) ` , write ` f x y ` .
178
179
179
- Comments are written as in C and Java (among many other languages). All
180
+ Comments are written as in C, Java, and Rust (among many other languages). All
180
181
text from ` // ` until the end of a line is ignored. Additionally, all
181
182
text between ` /* ` and ` */ ` is ignored, regardless of whether the line
182
183
ends.
@@ -1568,6 +1569,8 @@ analyze JVM and LLVM programs.
1568
1569
1569
1570
The first step in analyzing any code is to load it into the system.
1570
1571
1572
+ ## Loading LLVM
1573
+
1571
1574
To load LLVM code, simply provide the location of a valid bitcode file
1572
1575
to the ` llvm_load_module ` function.
1573
1576
@@ -1583,6 +1586,8 @@ most likely case of incompleteness. We aim to support every version
1583
1586
after 3.5, however, so report any parsing failures as [ on
1584
1587
GitHub] ( https://github.com/GaloisInc/saw-script/issues ) .
1585
1588
1589
+ ## Loading Java
1590
+
1586
1591
Loading Java code is slightly more complex, because of the more
1587
1592
structured nature of Java packages. First, when running ` saw ` , three flags
1588
1593
control where to look for classes:
@@ -1623,12 +1628,28 @@ unresolved issues in verifying code involving classes such as `String`. For
1623
1628
more information on these issues, refer to
1624
1629
[ this GitHub issue] ( https://github.com/GaloisInc/crucible/issues/641 ) .
1625
1630
1631
+ ## Loading MIR
1632
+
1633
+ To load a piece of Rust code, first compile it to a MIR JSON file, as described
1634
+ in [ this section] ( #compiling-mir ) , and then provide the location of the JSON
1635
+ file to the ` mir_load_module ` function:
1636
+
1637
+ * ` mir_load_module : String -> TopLevel MIRModule `
1638
+
1639
+ SAW currently supports Rust code that can be built with a [ March 22, 2020 Rust
1640
+ nightly] ( https://static.rust-lang.org/dist/2020-03-22/ ) . If you encounter a
1641
+ Rust feature that SAW does not support, please report it [ on
1642
+ GitHub] ( https://github.com/GaloisInc/saw-script/issues ) .
1643
+
1626
1644
## Notes on Compiling Code for SAW
1627
1645
1628
- SAW will generally be able to load arbitrary LLVM bitcode and JVM
1629
- bytecode files, but several guidelines can help make verification
1630
- easier or more likely to succeed. For generating LLVM with ` clang ` , it
1631
- can be helpful to:
1646
+ SAW will generally be able to load arbitrary LLVM bitcode, JVM bytecode, and
1647
+ MIR JSON files, but several guidelines can help make verification easier or
1648
+ more likely to succeed.
1649
+
1650
+ ### Compiling LLVM
1651
+
1652
+ For generating LLVM with ` clang ` , it can be helpful to:
1632
1653
1633
1654
* Turn on debugging symbols with ` -g ` so that SAW can find source
1634
1655
locations of functions, names of variables, etc.
@@ -1659,11 +1680,54 @@ behavior, and SAW currently does not have built in support for these
1659
1680
functions (though you could manually create overrides for them in a
1660
1681
verification script).
1661
1682
1683
+ [ ^ 1 ] : https://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
1684
+
1685
+ ### Compiling Java
1686
+
1662
1687
For Java, the only compilation flag that tends to be valuable is ` -g ` to
1663
1688
retain information about the names of function arguments and local
1664
1689
variables.
1665
1690
1666
- [ ^ 1 ] : https://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
1691
+ ### Compiling MIR
1692
+
1693
+ In order to verify Rust code, SAW analyzes Rust's MIR (mid-level intermediate
1694
+ representation) language. In particular, SAW analyzes a particular form of MIR
1695
+ that the [ ` mir-json ` ] ( https://github.com/GaloisInc/mir-json ) tool produces. You
1696
+ will need to intall ` mir-json ` and run it on Rust code in order to produce MIR
1697
+ JSON files that SAW can load (see [ this section] ( #loading-mir ) ).
1698
+
1699
+ For ` cargo ` -based projects, ` mir-json ` provides a ` cargo ` subcommand called
1700
+ ` cargo saw-build ` that builds a JSON file suitable for use with SAW. `cargo
1701
+ saw-build` integrates directly with ` cargo`, so you can pass flags to it like
1702
+ any other ` cargo ` subcommand. For example:
1703
+
1704
+ ```
1705
+ $ export SAW_RUST_LIBRARY_PATH=<...>
1706
+ $ cargo saw-build <other cargo flags>
1707
+ <snip>
1708
+ linking 11 mir files into <...>/example-364cf2df365c7055.linked-mir.json
1709
+ <snip>
1710
+ ```
1711
+
1712
+ Note that:
1713
+
1714
+ * The full output of ` cargo saw-build ` here is omitted. The important part is
1715
+ the ` .linked-mir.json ` file that appears after ` linking X mir files into ` , as
1716
+ that is the JSON file that must be loaded with SAW.
1717
+ * ` SAW_RUST_LIBRARY_PATH ` should point to the the MIR JSON files for the Rust
1718
+ standard library.
1719
+
1720
+ ` mir-json ` also supports compiling individual ` .rs ` files through ` mir-json ` 's
1721
+ ` saw-rustc ` command. As the name suggests, it accepts all of the flags that
1722
+ ` rustc ` accepts. For example:
1723
+
1724
+ ```
1725
+ $ export SAW_RUST_LIBRARY_PATH=<...>
1726
+ $ saw-rustc example.rs <other rustc flags>
1727
+ <snip>
1728
+ linking 11 mir files into <...>/example.linked-mir.json
1729
+ <snip>
1730
+ ```
1667
1731
1668
1732
## Notes on C++ Analysis
1669
1733
0 commit comments