summaryrefslogtreecommitdiff
path: root/src/rewrites.ml
AgeCommit message (Collapse)Author
2018-02-23Allow guarded patterns rewrite to merge P_var patternsBrian Campbell
2018-02-21Can now compile aarch64/no_vector into CAlasdair Armstrong
Now compiles to C and builds a working executable. Just need to correctly implement all the library builtins (some are still stubs), and it should work.
2018-02-16Avoid nested explicit type annotationsThomas Bauereiss
Isabelle does not like nested annotations like "((exp :: typ) :: typ)".
2018-02-13Try to replace generated kids with user-defined ones from the environmentThomas Bauereiss
Solves a problem where generated kids crept into type annotations during rewriting and caused later typechecking passes to fail.
2018-02-06Add aux constructor to type patterns for consistencyAlasdair Armstrong
2018-02-05Merge changes to type_check.mlAlasdair Armstrong
2018-02-05Add typ patterns for destructuring existentialsAlasdair Armstrong
2018-02-05Allow type variables to be introduced by global let bindings.Alasdair Armstrong
This was technically allowed previously but the rules for type variable names in function types were too strict so it didn't work. Also fixed a bug where Nexp_app constructors were never considered identical and fixed a bug where top-level let bindings got annotated with the wrong environment
2018-02-02Move exp_lift_assign rewrite after fixing effects and retypecheckingBrian Campbell
2018-01-31Try to make bitvector pattern rewriting more robustThomas Bauereiss
Look deep into sub-patterns for identifiers and literals instead of relying on assumptions about possible nestings
2018-01-31Fix bug in bitvector pattern rewritingThomas Bauereiss
Make rewriter look into P_typ patterns instead of throwing them away.
2018-01-29Add rreg effect to _reg_deref in fix_val_specs rewriteThomas Bauereiss
The internal function _reg_deref is declared as pure, so that bitfield setters can be implemented as read-modify-write, while only having a wreg effect. However, for the Lem shallow embedding, the read step of those setters needs to be embedded into the monad. This could be special-cased in the Lem pretty printer, but then the pretty printer would have to replicate some logic of the letbind_effects rewriting step. It seems simplest to add the effect annotation early in the Lem rewriting pipeline, in the fix_val_specs step. This means that this rewriting step can only be used for other backends if these additional effects are acceptable.
2018-01-29Leave pure if-conditions in place instead of pulling out let-bindingsBrian Campbell
2018-01-29Get typechecking to resolve overriding in remove numeral patterns rewriteBrian Campbell
2018-01-29Move subst to ast_util, use for guarded clauses rewriteBrian Campbell
2018-01-25Omit redundant let-bindings when rewriting (bit-)vector patternsThomas Bauereiss
Only add bindings for sub-patterns if they are actually used in the pattern guard or expression, respectively.
2018-01-25Rewrite bitvector patterns for OCaml and C backendsThomas Bauereiss
Seems to increase compilation speed significantly for OCaml 4.05.
2018-01-25Fix more type annotations in rewriterThomas Bauereiss
Use consistent nesting of tuples when adding updated local mutable variables to expressions. Add test case.
2018-01-24Have some simple sail programs compiling to CAlasdair Armstrong
2018-01-23Run tests for Lem shallow embeddingThomas Bauereiss
Uses the typechecker tests for now. Also fix two minor bugs in pretty-printer and rewriter uncovered by the tests.
2018-01-23Added additional tests, and fixed ocaml build of ARM testsAlasdair Armstrong
2018-01-22Update Lem shallow embedding to Sail2Thomas Bauereiss
- Remove vector start indices - Library refactoring: Definitions in sail_operators.lem now use Bitvector type class and work for both bit list and machine word representations - Add Lem bindings to AArch64 and RISC-V preludes TODO: Merge specialised machine word operations from sail_operators_mwords into sail_operators.
2018-01-18Clean up command line options slightlyAlasdair Armstrong
Changed -mono-split to -mono_split to be consistent with other options that use underscores, -mono-split still works but gives a warning message, just so nothing breaks immediately because of this. Removed this sil commands since they really don't do anything right now.
2018-01-18Merge remote-tracking branch 'origin/experiments' into sail2Alasdair Armstrong
2018-01-18Modified unification so Type_check.instantiation_of works after sizeof rewritingAlasdair Armstrong
This change allows the AST to be type-checked after sizeof re-writing. It modifies the unification algorithm to better support checking multiplication in constraints, by using division and modulus SMT operators if they are defined. Also made sure the typechecker doesn't re-introduce E_constraint nodes, otherwise re-checking after sizeof-rewriting will re-introduce constraint nodes.
2018-01-17Use right effect annotations in early return rewritingThomas Bauereiss
Also drop redundant unit expressions when concatenating with an empty block.
2018-01-17Try to remove early returns more aggressivelyThomas Bauereiss
In particular, there is an ASL pattern with single-branch if-expressions containing an early return (and an empty else-branch), e.g. { ... if (error) then return(Fault) else (); ... return(Success); } The rewriting pass now tries to fold the rest of the block into the else-branch, since it is unreachable after the then-branch, e.g. { ... if (error) then return(Fault) else { ... return(Success); } } In combination with other rewriting rules, this allows the rewriting pass to pull out the early returns if *all* branches end in a return statement. If it is possible to pull out the return all the way, i.e., so that the function body is a single return statement, then the return can be removed. If that is not possible, then the function body is left as it was originally.
2018-01-16Fix problem with let-bindings in pattern guardsThomas Bauereiss
Monomorphisation sometimes produces pattern guard with let-bindings, e.g. | ... if (let regsize = size_itself(regsize) in eq(regsize, 32)) -> ... Previously, the rewriting pass for let-bindings (and pattern guards) pulled these out of the guard condition and into the same scope as the case expression, which potentially clashed with let-bindings for the same variables in that case expression. The rewriter now leaves let-bindings in place within pure if-conditions, solving this problem.
2018-01-16Output more type annotations in Lem backendThomas Bauereiss
Keep track of which type variables have been bound in the function declaration, and allow those to be pretty-printed
2018-01-15Support non-trivial literal patternsBrian Campbell
Previously we only did top-level literal pattern to guard conversion, this does it throughout any pattern
2018-01-12Merge remote-tracking branch 'origin/experiments' into sail2Alasdair Armstrong
2018-01-11Ocaml semantics can now run aarch64 hello world example using octapodAlasdair Armstrong
New testcase for bitfield syntax Updated to work with latest lem and linksem
2018-01-05Added bitfield syntax to replicate register bits typeAlasdair Armstrong
For example: bitfield cr : vector(8, dec, bit) = { CR0 : 7 .. 4, LT : 7, CR1 : 3 .. 2, CR2 : 1, CR3 : 0, } The difference this creates a newtype wrapper around the vector type, then generates getters and setters for all the fields once, rather than having to handle this construct separately in every backend.
2018-01-04Additional tests for ocaml backendAlasdair Armstrong
2018-01-03Lots of experimental changes on this branchAlasdair Armstrong
* Changed comment syntax to C-style /* */ and // * References to registers and mutable variables are never created implicitly - a reference to a register or variable R is now created via the expression "ref R". References are assigned like "(*Y) = X", with "(*ref R) = X" being equivalent to "R = X". Everything is always explicit now, which simplifies the logic in the typechecker. There's also now an invariant that every id directly in a LEXP is mutable, which is actually required for our rewriter steps to be sound. * More flexible syntax for L-expressions to better support wierd power-idioms, some syntax sugar means that: X.GET(a, b, c) ==> _mod_GET(X, a, b, c) X->GET(a, b, c) ==> _mod_GET(ref X, a, b, c) for setters, this can be combined with the (still somewhat poorly named) LEXP_memory construct, such that: X->SET(a, b, c) = Y ==> _mod_SET(ref X, a, b, c, Y) Currently I use the _mod_ prefix for these 'modifier' functions, but we could omit that a la rust. * The register bits typedef construct no longer exists in the typechecker. This construct never worked consistently between backends and inc/dec vectors, and it can be easily replaced by structs with fancy setters/getters if need be. One can also use custom type operators to mimic the syntax, i.e. type operator ... ('n : Int) ('m : Int) = slice('n, 'm) struct cr = { CR0 : 32 ... 35, /* 32 : LT; 33 : GT; 34 : EQ; 35 : SO; */ CR1 : 36 ... 39, /* 36 : FX; 37 : FEX; 38 : VX; 39 : OX; */ CR2 : 40 ... 43, CR3 : 44 ... 47, CR4 : 48 ... 51, CR5 : 52 ... 55, CR6 : 56 ... 59, CR7 : 60 ... 63, } This greatly simplifies a lot of the logic in the typechecker, as it means that E_field is no longer ambiguously overloaded between records and register bit typedefs. This also makes writing semantics for these constructs much simpler.
2018-01-03Updates to interpreterAlasdair Armstrong
Experimenting with porting riscv model to new typechecker
2018-01-02Experimenting with power specAlasdair Armstrong
2017-12-19Support user-defined exceptions in Lem shallow embeddingThomas Bauereiss
The type-checker already supports a user-defined "exception" type that can be used in throw and try-catch expressions. This patch adds support for that to the Lem shallow embedding by adapting the existing exception mechanisms of the state and prompt monads. User-defined exceptions are distinguished from builtin exception cases. For example, the state monad uses type ex 'e = | Exit | Assert of string | Throw of 'e to distinguish between calls to "exit", failed assertions, and user-defined exceptions, respectively. Early return is also handled using the exception mechanism, by lifting to a monad with "either 'r exception" as the exception type, where 'r is the expected return type and "exception" is the user-defined exception type.
2017-12-19Add rewriting step for numeral patternsThomas Bauereiss
Pattern matching against literal numbers is not well supported by Lem or Isabelle. This rewriting step turns them into guarded patterns (which can be picked up by the guarded pattern rewriting to if-expressions).
2017-12-14An experimental version of sail without bitvector start indexes.Alasdair Armstrong
Works with the vector branch of asl_parser
2017-12-14Fix all compiler warning except in lem pretty printer and monomorphisationAlasdair Armstrong
2017-12-13Use big_nums from LemAlasdair Armstrong
2017-12-07More OCaml test casesAlasdair Armstrong
Improved handling of try/catch Better handling of unprovable constraints when the environment contains false
2017-12-07Fix regressions in OCaml outputAlasdair Armstrong
Recent patches have made the rewriter more strict about performing type correct rewrites. This is mostly a good thing but did cause some problems with the ocaml backend. Currently the sizeof rewriter doesn't seem to preserve type correctness - I suspect this is because when it resolves the sizeofs, it generates constraints that are true, but not in a form where the typechecker can see that they are true. I disabled the re-check after the sizeof rewriting pass to fix this. Maybe we don't want to do this anyway because it's slow. Changes to function clauses with guards + monomorphisation changed how the typechecker handles literal patterns. I added a rewriting pass to rewrite literals to guarded equality checks, which is run before generating ocaml. The rewriter currently uses Env.empty in a view places. This can cause bugs because Env.empty is a totally unitialised environment that doesn't satisfy invariants we expect of an environment. This should be changed to initial_env and it shouldn't be exported, I fixed a few cases where this caused things to go wrong, but it should probably not be exported from Type_check.ml.
2017-12-07Functions with guards changes in rewritesBrian Campbell
2017-12-06Add top-level pattern match guards internallyBrian Campbell
Also fix bug in mono analysis with generated variables Breaks lots of typechecking tests because it generates unnecessary equality tests on units (and the tests don't have generic equality), which I'll fix next.
2017-12-06Merge remote branch 'experiments' into experimentsThomas Bauereiss
2017-12-05Better support for exceptions in sail for ASL specs that need them.Alasdair Armstrong
2017-12-05Update license headers for Sail sourceAlasdair Armstrong
2017-11-30Improvements to enable parsing and checking intermediate rewritingAlasdair Armstrong
steps Parser now has syntax for mutual recusion blocks mutual { ... fundefs ... } which is used for parsing and pretty printing DEF_internal_mutrec. It's stripped away by the initial_check, so the typechecker never sees DEF_internal_mutrec. Maybe this could change, as forcing mutual recursion to be explicit would probably be a good thing. Added record syntax to the new parser New option -dmagic_hash is similar to GHC's -XMagicHash in that it allows for identifiers to contain the special hash character, which is used to introduce new autogenerated variables in a way that doesn't clash with existing names. Option -sil compiles sail down to the intermediate language defined in sil.ott (not complete yet).