summaryrefslogtreecommitdiff
path: root/src/rewrites.ml
AgeCommit message (Collapse)Author
2020-09-29Refactor: Change AST type from a union to a structAlasdair
2020-09-28Refactor: Rename 'a defs to 'a astAlasdair
Change internal terminology so we more clearly distinguish between a list of definitions 'defs' and functions that take an entire abstract syntax trees 'ast'.
2020-09-28Move the ast defs wrapper into it's own fileAlasdair
This refactoring is intended to allow this type to have more than just a list of definitions in future.
2020-09-02Consider case expressions in early return rewriteThomas Bauereiss
2020-08-27Perform truncation of hex literals for C backend (really for isla)Brian Campbell
For example, if a 129-bit capability is given as a 132-bit hex literal and truncated, this produces a 129-bit binary literal. In isla, this will keep all of the computation concrete because 129-bit concrete values are supported.
2020-08-07Allow C/IR builds to use mono_rewrites without the rest of monomorphisationBrian Campbell
- also tie following type check to the mono_rewrites flag
2020-05-22Fix atomicity of register field writesAlasdair
Previous merge commit caused some code that was generating register.field = value to instead generate temp = register temp.field = value register = temp This was caused by rewriter changes affecting the ANF form, and the Jib compilation was sensitive to small changes in the ANF form when compiling l-expressions. Rather than applying a band-aid fix in the rewriter this commit re-factors the ANF translation of l-expressions to ensure that the jib compilation is more robust and able to consistently generate the correct l-expressions without introducing additional read-modify-write expressions in the code.
2020-05-21Merge branch 'sail2' into mono-tweaksAlasdair
2020-05-15Add coverage tracking toolAlasdair
See sailcov/README.md for a short description Fix many location info bugs discovered by eyeballing output
2020-05-11Functorise and refactor C code generatorAlasdair
Currently uses the -c2 option Now generates a sail_state struct which is passed as a pointer to all generated functions. This contains all registers, letbindings, and the exception state. (Letbindings must be included as they can contain pointers to registers). This should make it possible to use sail models in a multi-threaded program by creating multiple sail_states, provided a suitable set of thread-safe memory builtins are provided. Currently the sail_state cannot be passed to the memory builtins. For foo.sail, now generate a foo.c, foo.h, and (optionally) a foo_emu.c. foo_emu.c wraps the generated library into an emulator that behaves the same as the one we previously generated. The sail_assert and sail_match_failure builtins are now in a separate file, as they must exist even when the RTS is not used. Name mangling can be controlled via the exports and exports_mangled fields of the configuration struct (currently not exposed outside of OCaml). exports allows specifying a name in C for any Sail identifier (before name mangling) and exports_mangled allows specifiying a name for a mangled Sail identifier - this is primarily useful for generic functions and data structures which have been specialised.
2020-04-21Mono: Check for non-constant calls to make_the_valueThomas Bauereiss
... and try to resolve them using constant propagation.
2020-04-21Add rewrite for constant-folding top-level letbindingsThomas Bauereiss
This will constant-fold letbindings such as let LOG2_TAG_GRANULE : int(4) = 4 let TAG_GRANULE : int = (1 << LOG2_TAG_GRANULE) which is useful for the translation to Lem if TAG_GRANULE is used in bitvector lengths.
2020-04-21Consider literals in pattern disjointness checkThomas Bauereiss
This check is used in the guarded pattern rewrite step, which would previously generate some impossible matches (e.g. matching expression "true" against pattern "false").
2020-04-21Handle more cases in bitvector cast rewriteThomas Bauereiss
Add casts for function arguments using the constraints in the environment of the function clause (not just assertions within the function body). Also pass in the global typing environment for comparison with the environment within the function clause (and make a corresponding change in the Lem pretty-printer so that it uses the right environments).
2020-04-21Tweak types of loop combinators for prover combinatorsThomas Bauereiss
Split the variable (tuple) type into an input and output type. They are meant to be the same, but due to the way function types are instantiated, unification can fail in the case of existential types, as in the added test case (when trying to generate Lem definitions from it). The output of the loop will be checked against the expected type, though, due to a type annotation outside the loop added by the rewrite pass for variable updates.
2020-04-21Rewrite vector concat lexps to sequences of assignmentsThomas Bauereiss
... instead of a tuple assignment. This makes the rewrite independent of the tuple assignment rewrite and allows it to be moved after the latter (nesting vector concat lexps into tuple lexps is an idiom in ASL, but the other way around doesn't make sense).
2020-04-21Be more careful about type annotations in rewrites to LemThomas Bauereiss
In particular, don't add annotations for types with existentially quantified variables that only occur in constraints, not in the type, e.g. {'i1 'i2, 'i1 == div('i2, 8). int('i1)}. These seem to confuse the type checker when pulled out into the source AST.
2020-04-14Add add_symbol to the API of Process_fileAlasdair
Allows clients of sail as a library to define custom symbols for $ifdef and $ifndef Iterate vector concat assignment and tuple assignment to handle unusual nesting cases when compiling to C. These rewrites should really be one rewrite anyway though! Don't add type annotations when introducing tuple patterns during rewriting. I guess not adding them could also cause an error in some circumstances, but if that's the case it could probably be fixed by tweaking some rules in the type-checker.
2020-01-22Preserve effect annotation when realising mappingsThomas Bauereiss
2020-01-21Use hex/bin literals in Coq backendBrian Campbell
Also be more careful to avoid pattern bindings with identifiers to avoid parsing clashes, eg `let 'bytes := ...` which is confused with the notation for binary literals.
2020-01-17Merge scattered mapping fixesJames Clarke
2020-01-16Allow effects on mappingsAlasdair Armstrong
2019-12-03Prover backends: Expand Int type synonyms in type definitionsThomas Bauereiss
... not just in type abbreviations. Fixes an error in the RV32 build of CHERI-RISC-V.
2019-11-29Merge branch 'word-numerals' into sail2Thomas Bauereiss
2019-11-26Allow overriding of generated mapping functionsThomas Bauereiss
If, for example, we have a bidirectional encoding-decoding mapping as in sail-riscv, but want to translate only the decoder to a theorem prover, this commit allows us to stub out the the encoder by splicing in dummy definitions.
2019-11-06Allow specifying specific fields of a register as constant with ↵Alasdair Armstrong
:fixed_registers command
2019-11-06Add toplevel commands to fix specific register values and simply spec ↵Alasdair Armstrong
accordingly
2019-08-13Coq: fix non-exhaustive pattern match failure in riscv duopodBrian Campbell
2019-08-02Fix all warnings (except for two lem warnings)Alasdair Armstrong
Remove P_record as it's never been implemented in parser/typechecker/rewriter, and is not likely to be. This also means we can get rid of some ugliness with the fpat and mfpat types. Stubs for P_or and P_not are left as they still may get added to ASL and we might want to support them, although there are good reasons to keep our patterns simple. The lem warning for while -> while0 for ocaml doesn't matter because it's only used in lem, and the 32-bit number warning is just noise.
2019-08-01Merge branch 'sail2' into separate_bvAlasdair Armstrong
2019-08-01Merge remote-tracking branch 'origin/rv_duopod_fix' into sail2Alasdair Armstrong
Fixes #53
2019-07-16Fix all remaining tests for this branchAlasdair
2019-07-16Merge remote-tracking branch 'origin/sail2' into separate_bvAlasdair Armstrong
2019-07-11Make sure constant folding won't fold external definitions that also have ↵Alasdair Armstrong
sail definitions Definitions can be made external on a per-backend basis, so we need to make sure constant folding doesn't inline external functions that have sail definitions for backends other than the ones we are currently targetting
2019-06-30Fix bug with toplevel pattern in RISC-V duopodAlasdair
Do this by making sure that generic pattern literal re-writing gets applied to top-level function clauses. This requires re-ordering the rewrites for most backends otherwise they break, which hopefully wo anything. After doing this re-ordering I had to turn off casting when rewriting bitvector patterns, otherwise insane things can happen.
2019-06-19Rewriting improvements for monomorphic aarch64_smallBrian Campbell
- allow disjoint_pat to be used on patterns that have just been introduced by the rewrite without rechecking - don't rebuild the matched expression in the generated fallthrough case (or any wildcard fall-through) - it may be dead code and generate badly typed Lem - update the type environment passed to rewrites whenever type checking is performed; stale information broke some rewrites
2019-06-18Fix handling of E_internal_plet in rewriteThomas Bauereiss
2019-06-13Fix some bugs in Lem rewriterThomas Bauereiss
A missing type annotation in rewrite_guarded_clauses caused a crash in some cases. Also fix an effect propagation bug in rewrite_letbind_effects.
2019-06-12Handle partial matches in guarded pattern rewriteThomas Bauereiss
Add a fallthrough case that fails to potentially partial pattern matches. This also helps to preserve any guard in the final match case, which might be needed for flow typing (see the discussion on issue #51). TODO: Merge with the MakeExhaustive rewrite, which currently does not support guarded patterns.
2019-06-10Add well-formedness check for type schemes in valspecs.Brian Campbell
Fixes #47. Also adjust the nexp substitution so that the error message points to a useful location, and replace the empty environment with the initial environment in a few functions that do type checking to ensure that the prover is set up (which may be needed for the wf check).
2019-06-06Add an option to pre-compile the axiomatic model for SMTAlasdair Armstrong
2019-06-04Merge branch 'sail2' into separate_bvAlasdair Armstrong
2019-06-04Remove unused AST constructorAlasdair Armstrong
Clean up ott grammar a bit
2019-06-04SMT: Add a fuzzing tool for the SMT builtinsAlasdair Armstrong
2019-06-03Coq: support non-exhaustive pattern rewrite for exception handlingBrian Campbell
2019-05-17Get all Lem tests working with separate bitvector typeAlasdair Armstrong
2019-05-17Experiment with making vector and bitvector distinct typesAlasdair Armstrong
Only change that should be needed for 99.9% of uses is to change vector('n, 'ord, bit) to bitvector('n, 'ord), and adding $ifndef FEATURE_BITVECTOR_TYPE type bitvector('n, dec) = vector('n, dec, bit) $endif for to support any Sail before this Currently I have all C, Typechecking, and SMT tests passing, as well as the RISC-V spec building OCaml and C completely unmodified.
2019-05-1594f445 introduced a new name for _ref_deref, add it to the effect rewritingBrian Campbell
2019-04-27Merge branch 'sail2' into smt_experimentsAlasdair
2019-04-20Fix: Reduce constant-fold time for ARM from 20min+ to 10sAlasdair Armstrong
With the new interpreter changes computing the initial state for the interpreter does some significant work. The existing code was re-computing the initial state for every subexpression in the specification (not even just the ones due to be constant-folded away). Now we just compute the initial state once and use it for all constant folds. Also reduce the time taken for the simple_assignments rewrite from 20s to under 1s for ARMv8.5, by skipping l-expressions that are already in the simplest form.