summaryrefslogtreecommitdiff
path: root/src/sail.ml
AgeCommit message (Collapse)Author
2017-08-28Merge branch 'experiments' of bitbucket.org:Peter_Sewell/sail into ↵Brian Campbell
mono-experiments # Conflicts: # src/gen_lib/sail_values.lem
2017-08-23Started work on an undefined literal removal pass for the ocamlAlasdair Armstrong
backed. Ocaml doesn't support undefined values, so we need a way to remove them from the specification in order to generate good ocaml code. There are more subtle issues to - like if we initialize a mutable variable with an undefined list, then the ocaml runtime has no way of telling what it's length should be (as this information is removed by the simple_types pass). We therefore rewrite undefined literals with calls to functions that create undefined types, e.g. (bool) undefined becomes undefined_bool () (vector<'n,'m,dec,bit>) undefined becomes undefined_vector(sizeof 'n, sizeof 'm, undefined_bit ()) We therefore have to generate undefined_X functions for any user defined datatype X. initial_check seems to be the logical place for this. This is straightforward provided the user defined types are not-recursive (and it shouldn't be too bad even if they are).
2017-08-23Merge branch 'experiments' into mono-experimentsBrian Campbell
2017-08-22Add option to dump monomorphised ast before (re-)typecheckingBrian Campbell
2017-08-21More work on quantifier elimination passAlasdair Armstrong
Also added a rewriting pass that removes the cast annotations and operator overloading declarations from the AST because they arn't supported by the interpreter.
2017-08-21Modified sizeof rewriting pass so it can correctly deal with existentials.Alasdair Armstrong
Basically we needed to make the rewriting step for E_sizeof and E_constraint more aggressively try to rewrite those expressions from variables in scope, without adding new parameters to pass the type variables at runtime, as this can break in the presence of existential quantification. Still some cleanup to do in this code, but tests on the arm spec show that it now introduces the minimal amount of new parameters.
2017-08-17Work on E_constraint removal pass and diagnosing bugs in E_sizeof removal passAlasdair Armstrong
2017-08-10Merge remote-tracking branch 'origin/sail_new_tc' into experimentsAlasdair Armstrong
Conflicts: src/pretty_print_common.ml
2017-08-08Add infrastructure to play with new menhir parsers.Alasdair Armstrong
Added a copy of the current parser/lexer in parser2.mly and lexer2.mll. They can be used with the -new_parser flag. Currently they are just copies of the existing files.
2017-08-02Add debugging option to dump AST after rewriting stepsThomas Bauereiss
2017-07-27Parameterise convert_ast by the bitvector orderAlasdair Armstrong
2017-07-25Improved l-expressionsAlasdair Armstrong
- Fixed a bug where some l-expressions which wrote registers wern't picking up register writes. - Can now write to registers with record types. e.g. ARM's ProcState record from ASL.
2017-07-24Separate monomorphisation from top-level type checkingBrian Campbell
2017-07-24Remove monomorphisation for old type checkerBrian Campbell
2017-07-21Everything moved to new typecheckerAlasdair Armstrong
Modified initial_check.ml so it no longer requires type_internal. It's still needs cleaned up in a few ways. Most of the things it's trying to do could be done nicer if we took some time to re-factor it, and some of the things should just be handled by the main typechecker, leaving it as a think layer between the parse_ast and the ast. Now that's done everything can be switched to the new typechecker and the _new suffixes were deleted from everything except the monomorphisation pass because I don't know the status of that.
2017-07-21Switch to new typechecker (almost)Thomas Bauereiss
Initial typecheck still uses previous typechecker
2017-07-13Make new-tc monomorphisation actually workBrian Campbell
2017-07-12Various small changesAlasdair Armstrong
* Experimented with using list<bit> to clean up manually monomorphised code in MIPS tlb * Added option -dtc_verbose to control verbosity of new typechecker * Allowed functions with val specs to omit their type declarations
2017-07-12Add checks for variable identifiers in pattern subsumptionThomas Bauereiss
2017-07-05Added split_on_char as a utility function in Util.ml, and replaced usage in ↵Alasdair Armstrong
sail.ml Current REMS install script and Jenkins CI server is on an older ocaml which doesn't have this function in String.
2017-07-05Merge remote-tracking branch 'origin/word' into sail_new_tcAlasdair Armstrong
2017-06-29Various improvements to typecheckerAlasdair Armstrong
Added vector concatenation patterns. Currently slightly more restrictive than before as each subvector's length must be inferrable from just that particular subvector - this may require additional type annotations in certain vector patterns. How exactly weird vector patterns, such as incrementing and decrementing vectors appearing in the same pattern, as well as patterns with funny start indexes should be dealt with correctly is unclear. It's probably best to be as restrictive as possible to avoid unsoundness bugs. Added a new option -ddump_tc_ast which dumps the (new) typechecked AST to stdout. Also added a new option -dno_cast which disables implicit casting in the typechecker. These options can be used in conjunction to dump the typechecked ast (which has all implicit casts resolved), and then re-typecheck it as a way to check that the typechecker is indeed resolving all casts correctly, and is reconstructing a fully type correct AST. The run_tests.sh script in test/typecheck has been modified to do this. Removed the dependency on Type_internal.ml from pretty_print_sail.ml. This means that we can no longer pretty print certain internal constructs produced by the old typechecker, but on the plus side it means that the sail pretty printer is type system agnostic and works with any annotation AST, irregardless of the type of annotations. Also fixed a few bugs where certain constructs would be pretty printed incorrectly.
2017-06-23Add option for monomorphisation splittingBrian Campbell
2017-06-22Can now typecheck register declarations and assignmentsAlasdair Armstrong
Can now properly typecheck register declarations and assignments. Also better support for assignments to mutable variables. Assignment to immutable let bound variables is disallowed as it should be, and casts when assiging to existing bound variables should be handled properly. Added additional tests for these new features, and a new option -just_check that allows the new checker to be run without the old.
2017-06-22Initial partial monomorphisation workBrian Campbell
Splits specified pattern matches on enumerations (other types to be added later); no constant propogation yet.
2017-06-15Prototype Bi-directional type checking algorithm for sailAlasdair Armstrong
Started work on a bi-directional type checking algorithm for sail based on Mark and Neel's typechecker for minisail in idl repository. It's a bit different though, because we are working with the unmodified sail AST, and not in let normal-form. Currently, we can check a fragment of sail that includes pattern matching (in both function clauses and switch statements), numeric constraints (but not set constraints), function application, casts between numeric types, assignments to local mutable variables, sequential blocks, and (implicit) let expressions. For example, we can correctly typecheck the following program: val forall Nat 'n, Nat 'm. ([:'n + 20:], [:'m:]) -> [:'n + 20 + 'm:] effect pure plus val forall Nat 'n, 'n <= -10. [:'n:] -> [:'n:] effect pure minus_ten_id val forall Nat 'n, 'n >= 10. [:'n:] -> [:'n:] effect pure ten_id val forall Nat 'N, 'N >= 63. [|10:'N|] -> [|10:'N|] effect pure branch function forall Nat 'N, 'N >= 63. [|10:'N|] branch x = { switch x { case ([|10:30|]) y -> y case ([:31:]) _ -> sizeof 'N case ([|31:40|]) _ -> plus(60,3) } } and branch (([|51:63|]) _) = ten_id(sizeof 'N) The typechecker has been set up so it can produce derivation trees for the typing judgements and constraints, so for the above program we have: Checking function branch Adding local binding x :: range<10, 'N> | Check { switch x { case (range<10, 30>) y -> y case (atom<31>) _ -> sizeof 'N case (range<31, 40>) _ -> plus(60, 3)} } <= range<10, 'N> | | Check switch x { case (range<10, 30>) y -> y case (atom<31>) _ -> sizeof 'N case (range<31, 40>) _ -> plus(60, 3)} <= range<10, 'N> | | | Infer x => range<10, 'N> | | Subset 'N >= 63 |- {'fv1 | 10 <= 'fv1 & 'fv1 <= 30} {'fv0 | 10 <= 'fv0 & 'fv0 <= 'N} | | Adding local binding y :: range<10, 30> | | | Check y <= range<10, 'N> | | | | Infer y => range<10, 30> | | | Subset 'N >= 63 |- {'fv4 | 10 <= 'fv4 & 'fv4 <= 30} {'fv3 | 10 <= 'fv3 & 'fv3 <= 'N} | | Subset 'N >= 63 |- {'fv7 | 31 <= 'fv7 & 'fv7 <= 31} {'fv6 | 10 <= 'fv6 & 'fv6 <= 'N} | | | Check sizeof 'N <= range<10, 'N> | | | | Infer sizeof 'N => atom<'N> | | | Subset 'N >= 63 |- {'fv10 | 'N <= 'fv10 & 'fv10 <= 'N} {'fv9 | 10 <= 'fv9 & 'fv9 <= 'N} | | Subset 'N >= 63 |- {'fv13 | 31 <= 'fv13 & 'fv13 <= 40} {'fv12 | 10 <= 'fv12 & 'fv12 <= 'N} | | | Check plus(60, 3) <= range<10, 'N> | | | | | Infer 60 => atom<60> | | | | | Infer 3 => atom<3> | | | | Infer plus(60, 3) => atom<((60 - 20) + (20 + 3))> | | | Subset 'N >= 63 |- {'fv20 | ((60 - 20) + (20 + 3)) <= 'fv20 & 'fv20 <= ((60 - 20) + (20 + 3))} {'fv19 | 10 <= 'fv19 & 'fv19 <= 'N} Subset 'N >= 63 |- {'fv23 | 51 <= 'fv23 & 'fv23 <= 63} {'fv22 | 10 <= 'fv22 & 'fv22 <= 'N} | Check ten_id(sizeof 'N) <= range<10, 'N> | | | Infer sizeof 'N => atom<'N> | | Prove 'N >= 63 |- 'N >= 10 | | Infer ten_id(sizeof 'N) => atom<'N> | Subset 'N >= 63 |- {'fv28 | 'N <= 'fv28 & 'fv28 <= 'N} {'fv27 | 10 <= 'fv27 & 'fv27 <= 'N} Judgements are displayed in the order they occur - inference steps go inwards bottom up, while checking steps go outwards top-down. The subtyping rules from Mark and Neel's check_sub rule all are verified using the Z3 constraint solver. I have been a set of tests in test/typecheck which aim to exhaustively test all the code paths in the typechecker, adding new tests everytime I add support for a new construct. The new checker is turned on using the -new_typecheck option, and can be tested (from the toplevel sail directory) by running: test/typecheck/run_tests.sh -new_typecheck (currently passes 32/32) and compared to the old typechecker by test/typecheck/run_tests.sh (currently passes 21/32)
2017-02-14remove the -i optionPeter Sewell
2017-02-14tidy command-line optionsPeter Sewell
2017-02-09group initial type environment into meaningful sections; pretty-print in ↵Peter Sewell
user-readable way
2017-02-05command-line option to dump initial type environmentPeter Sewell
2017-02-03fix headersPeter Sewell
2017-01-31Kathy, Peter: pp of initial type environmentPeter Sewell
2016-11-28make sail produce prompt and state version of shallow embedding files at the ↵Christopher Pulte
same time with the types both have in common factored out into separate file, rename one mips shallow embedding _extras file as required by this
2016-11-14add option -lem_sequential for producing shallow embedding that refers to ↵Christopher Pulte
state monad, library fixes
2016-10-18Expose type environment after checking, for use in analysisKathy Gray
2016-02-23Several fixesKathy Gray
Improve printing for asl to sail readability; Add -o option for selecting the name of file generation; Add additional initial check module for turning generated ast nodes into ready-to-type-check ast nodes
2015-10-06added the preliminary lem output option that for now uses ocaml ppChristopher Pulte
2015-09-29Boiler plate to generate an ml file from a sail spec. Now debugging the ↵Kathy Gray
output of such
2015-02-13Actually use new dependency information in generation of lem/etc.Kathy Gray
Also stop rewriting code in the pretty printer, instead move it all into a new general rewriting pass
2015-02-03Correct bug in typedef NAME = register bits .... for Dec not present in IncKathy Gray
Also tracking more information to help dependency eventually
2014-12-10Support splitting sail definition across multiple filesKathy Gray
2014-07-29A file can now declare that a default order is either inc or dec, and this ↵Kathy Gray
will be reflected in short hand type syntax, inc is still the default if undeclared So: default order dec register bit[32] t (* Declares t as a decreasing vector, starting at 31 on the left and decreasing to 0 *) default order inc register bit[32] o (* Declares o as an increasing vector, starting at 0 on the left and increasing to 31 *) It is presently possible to change the default mid-file; this is almost certainly bad and I will turn it into an error soon.
2014-05-15Pretty-print to stdout rather than Format.stdout_formatterGabriel Kerneis
PPrint.ToFormatter is either broken, or I do not know how to use it properly. Switching to ToChannel solves the issue nicely.
2014-04-23Rename main to sail, build pretty_printer libGabriel Kerneis