summaryrefslogtreecommitdiff
path: root/src/interpreter.ml
AgeCommit message (Collapse)Author
2020-11-01Fix interpreter pattern matching bugAlasdair
2020-09-29Refactor: Change AST type from a union to a structAlasdair
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-04-15Add more intuitive defaults to interactive toplevelAlasdair
sail -i now starts an interactive toplevel with a few additional options set by default: - It applies the "interpreter" rewrites to any files passed on the command line. - It also applies those rewrites after the :l/:load command - Registers previously started in a disabled state, as the interactive shell made no default decision as to how to handle undefined (which is the initial value for all registers). Now -i implies -undefined_gen - Better help text for :fix_registers - Nullary interactive actions generate Sail functions that round-trip through pretty printing and parsing (bugfix) The -interact_custom flag has the same behavior as the previous -i flag This commit also improves the c/ocaml/interpreter test harness so it cleans up temporary files which could cause issues with stale files when switching ocaml versions
2020-03-25Fix a typo in write_mem for the interpreterAlasdair
2019-11-04Allow overriding the interpreter effectsAlasdair Armstrong
This allows read_mem and read_reg effects to be handled by GDB
2019-11-01More work on GDB interfaceAlasdair Armstrong
The following now works to run sail on every HVC call with hafnium function gdb_init() -> unit = { // Connect to QEMU via GDB sail_gdb_qemu(""); sail_gdb_symbol_file("hafnium.elf.sym"); sail_gdb_send("break-insert sync_lower_exception") } function gdb() -> unit = { gdb_init(); while true do { sail_gdb_send("exec-continue"); sail_gdb_sync() } }
2019-10-25Allow interactive commands to be setup outside isail.mlAlasdair Armstrong
can use Interactive.register_command to set up a new interactive command, which allows commands to be set up near where the functionality they interact with is defined, e.g. the ast slicing commands are registered in Slice.ml. Also allows help messages to be generated in a consistent way.
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-07-16Fix all remaining tests for this branchAlasdair
2019-06-04SMT: Add a fuzzing tool for the SMT builtinsAlasdair Armstrong
2019-05-13Interpreter: update memory intrinsics to include addrsize argumentJon French
2019-05-07Merge branch 'sail2' into smt_experimentsAlasdair Armstrong
2019-05-06Don't initialise registers in interpreter when register accesses not allowedBrian Campbell
Avoids having to handle unexpected undefined values during constant propagation.
2019-05-03Jib: Fix optimizations for SMT IR changesAlasdair Armstrong
Fixes C backend optimizations that were disabled due to changes in the IR while working on the SMT generation. Also add a -Oaarch64_fast option that optimizes any integer within a struct to be an int64_t, which is safe for the ARM v8.5 spec and improves performance significantly (reduces Linux boot times by 4-5 minutes). Eventually this should probably be a directive that can be attached to any arbitrary struct/type. Fixes the -c_specialize option for ARM v8.5. However this only gives a very small performance improvment for a very large increase in compilation time however.
2019-04-15Merge branch 'sail2' of github.com:rems-project/sail into sail2Jon French
2019-04-15Merge branch 'sail2' into rmem_interpreterJon French
2019-04-15Basic loop termination measures for CoqBrian Campbell
Currently only supports pure termination measures for loops with effects. The user syntax uses separate termination measure declarations, as in the previous recursive termination measures, which are rewritten into the loop AST nodes before type checking (because it would be rather difficult to calculate the correct environment to type check the separate declaration in).
2019-04-12Interpreter: remove debug printing (oops)Jon French
2019-04-06Various bugfixes and improvementsAlasdair
- Rename DeIid to Operator. It corresponds to operator <string> in the syntax. The previous name is from when it was called deinfix in sail1. - Removed things that weren't actually common from pretty_print_common.ml, e.g. printing identifiers is backend specific. The doc_id function here was only used for a very specific use case in pretty_print_lem, so I simplified it and renamed it to doc_sia_id, as it is always used for a SIA.Id whatever that is. - There is some support for anonymous records in constructors, e.g. union Foo ('a : Type) = { MkFoo : { field1 : 'a, field2 : int } } somewhat similar to the enum syntax in Rust. I'm not sure when this was added, but there were a few odd things about it. It was desugared in the preprocessor, rather than initial_check, and the desugaring generated incorrect code for polymorphic anonymous records as above. I moved the code to initial_check, so the pre-processor now just deals with pre-processor things and not generating types, and I fixed the code to work with polymorphic types. This revealed some issues in the C backend w.r.t. polymorphic structs, which is the bulk of this commit. I also added some tests for this feature. - OCaml backend can now generate a valid string_of function for polymorphic structs, previously this would cause the ocaml to fail to compile. - Some cleanup in the Sail ott definition - Add support for E_var in interpreter previously this would just cause the interpreter to fail
2019-03-14fix typo in interpreter excl_res intrinsicJon French
2019-03-13Interpreter: return frame rather than eval-looping analyse_instructionJon French
This is in order to allow register reads etc to be handled by RMEM
2019-03-13Interpreter: handling for E_consJon French
2019-03-13Interpreter: error handling when calling primopsJon French
2019-03-13Refactor interpreter monad to include pp in effect requests/failuresJon French
2019-03-13fix is_true/is_false use of == for web-interface new-interpreterJon French
2019-03-04Interpreter: remove useless string-to-rk/wk/bk functions, they're much ↵Jon French
better suited in RMEM
2019-02-13Merge branch 'sail2' into rmem_interpreterJon French
2019-02-04Fix behavior for fallthrough cases in catch blocksAlasdair Armstrong
Make all backends behave the same when a catch block does not catch a specific exception.
2018-12-28Remove opt_spc_matches_prefix from sail.h (fixes C tests)Jon French
2018-12-28Merge branch 'sail2' into rmem_interpreterJon French
2018-12-27basic Sail-side support for rmem use of interpreterJon French
2018-12-27pass typechecking environment around interpreter and rewritersJon French
2018-12-22Improve error messages and debuggingAlasdair Armstrong
Work on improving the formatting and quality of error messages When sail is invoked with sail -i, any type errors now drop the user down to the interactive prompt, with the interactive environment being the environment at the point the type error occurred, this means the typechecker state can be interactively queried in the interpreter to help diagnose type errors.
2018-12-04Remove FES_Fexps constructorAlasdair Armstrong
This makes dealing with records and field expressions in Sail much nicer because the constructors are no longer stacked together like matryoshka dolls with unnecessary layers. Previously to get the fields of a record it would be either E_aux (E_record (FES_aux (FES_Fexps (fexps, _), _)), _) but now it is simply: E_aux (E_record fexps, _)
2018-11-28Allow folding constant expressions into single register readsAlasdair
Essentially all we have to do to make this work is introduce a member of the Value type, V_attempted_read <reg>, which is returned whenever we try to read a register value with allow_registers disabled. This defers the failure from reading the register to the point where the register value is used (simply because nothing knows how to deal with V_attempted_read). However, if V_attempted_read is returned directly as the result of evaluating an expression, then we can replace the expression with a single direct register read. This optimises some indirection in the ARM specification.
2018-11-14interpreter: abstract effect requests into an Effect_request arm of frame typeJon French
2018-10-31Rename Reporting_basic to ReportingAlasdair Armstrong
There is no Reporting_complex, so it's not clear what the basic is intended to signify anyway. Add a GitHub issue link to any err_unreachable errors (as they are all bugs)
2018-10-31Improve error messages for unsolved function quantifiersAlasdair Armstrong
For example, for a function like ``` val aget_X : forall 'n, 0 <= 'n <= 31. int('n) -> bits(64) function test(n : int) -> unit = { let y = aget_X(n); () } ``` we get the message > Could not resolve quantifiers for aget_X (0 <= 'ex7# & 'ex7# <= 31) > > Try adding named type variables for n : atom('ex7#) > > The property (0 <= n & n <= 31) must hold which suggests adding a name for the type variable 'ex7#, and gives the property in terms of the variable n. If we give n a type variable name: ``` val test : int -> unit function test(n as 'N) = { let y = aget_X(n); () } ``` It will suggest a constraint involving the type variable name > Could not resolve quantifiers for aget_X (0 <= 'ex6# & 'ex6# <= 31) > > Try adding the constraint (0 <= 'N & 'N <= 31)
2018-10-24Interpreter, RISC-V: move memory actions to parts of the interpreter ↵Jon French
response and refactor RISC-V model accordingly
2018-10-24Interpreter: add handling of undefs and sizeofs, and initialize registers to ↵Jon French
undefined on startup
2018-10-24Interpreter: improve error handling/messagesJon French
2018-10-24Interpreter: don't silently use OCaml externs, only interpreter externsJon French
(Adds 'interpreter' externs as appropriate.)
2018-10-08Interpreter: refactor get/put state into more fine-grained responses in the ↵Jon French
monad
2018-10-05interpreter: Remove boxes (no longer used)Jon French
2018-08-23Fix interpreter after re-writer changeAlasdair Armstrong
Interpreter used a re-write (vector concat removal) that is dependent on the vector_string_to_bit_list rewriting pass. This fixes the interpreter to work without either vector concat removal, or turning bitstrings into vector literals like [bitzero, bitzero, bitone]. This has the upside of reducing the number of steps the interpreter needs for working with bitvectors so should improve interpreter performance. We also now test all the C compilation tests behave the same using the interpreter. Currently the real number tests fail due to limitations of Lem's rational library (this must be fixed in Lem). This required supporting configuration registers in the interpreter. As such the interpreter was refactored to more cleanly process registers when building an initial global state. The functions are also collected into the global state, which removes the need to search for them in the AST every time a function call happens. This should not only improve performance, but also removes the need to pass an AST into the interpretation functions.
2018-08-17Improve builtins testsAlasdair Armstrong
Test the builtin functions by compiling them to C, OCaml, and OCaml via Lem. Split up some of the longer builtin test programs to avoid stack overflows when compiling to OCaml, as 3000+ line long blocks can cause issues with some re-writing steps. Also test constant-folding with builtins (this should reduce the asserts in these files to assert true), and also test constant folding with the C compilation. Fix a bug whereby vectors with heap-allocated elements were not initialized correctly. Fix a bug caused by compiling and optimising empty vector literals. Fix an OCaml test case that broke due to the ref type being used. Now uses references to registers. Fix a bug where Sail would output big integers that lem can't parse. Checks if integer is between Int32.min_int and Int32.max_int and if not, use integerOfString to represent the integer. Really this should be fixed in Lem. Make the python test runner script the default for testing builtins and running the C compilation tests in test/run_tests.sh Add a ocaml_build_dir option that sets a custom build directory for OCaml. This is needed for running OCaml tests in parallel so the builds don't clobber one another.
2018-07-27Make type annotations abstract in type_check.mliAlasdair Armstrong
Rather than exporting the implementation of type annotations as type tannot = (Env.t * typ * effect) option we leave it abstract as type tannot Some additional functions have been added to type_check.mli to work with these abstract type annotations. Most use cases where the type was constructed explicitly can be handled by using either mk_tannot or empty_tannot. For pattern matching on a tannot there is a function val destruct_tannot : tannot -> (Env.t * typ * effect) option Note that it is specifically not guaranteed that using mk_tannot on the elements returned by destruct_tannot re-constructs the same tannot, as destruct_tannot is only used to give the old view of a type annotation, and we may add additional information that will not be returned by destruct_tannot.
2018-07-26Patterns: add or and not patternsAlastair Reid
These match the new ASL pattern constructors: - !p matches if the pattern p does not match - { p1, ... pn } matches if any of the patterns p1 ... pn match We desugar the set pattern "{p1, ... pn}" into "p1 | (p2 | ... pn)". ASL does not have pattern binding but Sail does. The rules at the moment are that none of the pattern can contain patterns. This could be relaxed by allowing "p1 | p2" to bind variables provided p1 and p2 both bind the same variables.
2018-06-29Constant folding improvementsAlasdair