summaryrefslogtreecommitdiff
path: root/src/isail.ml
AgeCommit message (Collapse)Author
2021-02-17Make sure :step_function appears in :commandsAlasdair
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-08-13Preserve file structure through initial checkAlasdair
Insert $file_start and $file_end pragmas in the AST, as well as $include_start and $include_end pragmas so we can reconstruct the original file structure later if needed, provided nothing like topological sorting has been done. Have the Lexer produce a list of comments whenever it parses a file, which can the be attached to the nearest nodes in the abstract syntax tree.
2020-04-22Add an interactive command to evaluate until the end of a functionAlasdair
Callable as either :f or :step_function Allow // to be used as a comment in the interactive toplevel
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
2019-11-11Update libsail slightly with recent changesAlasdair Armstrong
Also don't include the toplevel files in the library, and move load_files and descatter into process_file where they can be called
2019-11-06Add toplevel commands to fix specific register values and simply spec ↵Alasdair Armstrong
accordingly
2019-11-04Allow overriding the interpreter effectsAlasdair Armstrong
This allows read_mem and read_reg effects to be handled by GDB
2019-10-31Allow sail to be scripted using sailAlasdair
Currently the -is option allows a list of interactive commands to be passed to the interactive toplevel, however this is only capable of executing a sequential list of instructions which is quite limiting. This commit allows sail interactive commands to be invoked from sail functions running in the interpreter which can be freely interleaved with ordinary sail code, for example one could test an assertion at each QEMU/GDB breakpoint like so: $include <aarch64.sail> function main() -> unit = { sail_gdb_start("target-select remote localhost:1234"); while true do { sail_gdb_continue(); // Run until breakpoint sail_gdb_sync(); // Sync register state with QEMU if not(my_assertion()) { print_endline("Assertion failed") } } }
2019-10-31Allow sail interactive toplevel to connect to a running QEMU instance using ↵Alasdair Armstrong
GDB/MI After starting QEMU with -s -S we can run :gdb_qemu in isail to connect to it using a gdb-multiarch child process, which we communicate with via the gdb/mi interface. :gdb_send command sends a command to gdb and waits for it to respond. The idea is we will have a :gdb_sync command that will sync the register state of the running QEMU session with the Sail interpreter after a breakpoint, then we can run Sail code to test the state of the machine by hooking memory reads into approprate gdb commands.
2019-10-25Some more interpreter tweaksAlasdair Armstrong
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-10-14Add -Ofixed_int and -Ofixed_bits to assume fixed-precision ints and ↵Alasdair Armstrong
bitvectors in C Assumes a Sail C library that has functions with the right types to support this. Currently lib/int128 supports the -Ofixed_int option, which was previously -Oint128. Add a version of Sail C library that can be built with -nostdlib and -ffreestanding, assuming the above options. Currently just a header file without any implementation, but with the right types
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-05-31Change specialization interface slightlyAlasdair Armstrong
2019-05-24Add a :thin_slice command to isail to isolate a given set of functionsBrian Campbell
2019-04-15Merge branch 'sail2' into rmem_interpreterJon French
2019-04-05Lem: Make generated assertion messages look nicer in prover outputAlasdair
Add a new short_loc_to_string function that produces just the file and line number as a single line. loc_to_string adds a bunch of terminal color codes and other formatting designed for producing pretty error-messages in the terminal, which isn't ideal when the string appears in prover output as part of an assert statement. This is should be purely an aesthetic change.
2019-03-27C: Generate C from sliced specificationsAlasdair Armstrong
2019-03-27Interactive: Refactor sail.ml some moreAlasdair Armstrong
Separate calling the rewriter from the backend-specific parts of sail.ml
2019-03-27Interactive: Refactor sail.mlAlasdair Armstrong
Rather than having a separate variable for each backend X, opt_print_X, just have a single variable opt_print_target, where target contains a string option, such as `Some "lem"` or `Some "ocaml"`, then we have a function target that takes that string and invokes the appropriate backend, so the main function in sail.ml goes from being a giant if-then-else block to a single call to target !opt_target ast env This allows us to implement a :compile <target> command in the interactive toplevel Also implement a :rewrites <target> command which performs all the rewrites for a specific target, so rather than doing e.g. > sail -c -O -o out $FILES one could instead interactively do > sail -i :option -undefined_gen :load $FILES :option -O :option -o out :rewrites c :compile c :quit for the same result. To support this the behavior of the interactive mode has changed slightly. It no longer performs any rewrites at all, so a :rewrites interpreter is currently needed to interpret functions in the interactive toplevel, nor does it automatically set any other flags, so -undefined_gen is needed in this case, which is usually implied by the -c flag.
2019-03-27Rewriter: Finish refactoring rewrite sequencesAlasdair Armstrong
2019-03-26Rewriter: Expose rewrite passes to interactive modeAlasdair Armstrong
Rather than each rewrite being an opaque function, with separate lists of rewrites for each backend, instead put all the rewrites into a single list then have each backend define which of those rewrites it wants to use and in what order. For example, rather than having let rewrite_defs_ocaml = [ ... ("rewrite_undefined", rewrite_undefined_if_gen false); ... ] we would now have let all_rewrites = [ ... ("undefined", Bool_rewriter (fun b -> Basic_rewriter (rewrite_undefined_if_gen b))); ... ] let rewriters_ocaml = [ ... ("undefined", [Bool_arg false]); ... ] let rewrite_defs_ocaml = List.map (fun (name, args) -> (name, instantiate_rewrite (List.assoc name all_rewrites) args)) rewriters_ocaml This means we can introspect on the arguments required for each rewrite, allowing a :rewrite command in the interactive mode which can parse the arguments required for each rewrite, so we can invoke the above rewrite as sail> :rewrite undefined false with completion for the rewrite name based on all_rewrites, and hints for any arguments. The idea behind this is if we want to generate a very custom slice of a specification, we can set it up as a sequence of interpreter commands, e.g. ... :rewrite split execute :slice_roots execute_LOAD :slice_cuts rX wX :slice :rewrite tuple_assignments ... where we slice a spec just after splitting the execute function. This should help in avoiding an endless proliferation of additional options and flags on the command line.
2019-03-15Interactive: Auto-complete options and add hintsAlasdair Armstrong
2019-03-15Interactive: Auto-complete file namesAlasdair Armstrong
Mostly just a small quality-of-life improvement
2019-03-14Add various useful methods to interactive modeAlasdair Armstrong
:def <definition> evaluates a top-level definition :(b)ind <id> : <type> creates an identifier within the interactive type-checking environment :let <id> = <expression> defines an identifier Using :def the following now works and brings the correct vector operations into scope. :def default Order dec :load lib/prelude.sail Also fix a type-variable shadowing bug
2019-03-14Merge branch 'sail2' into rmem_interpreterJon French
2019-03-13Refactor interpreter monad to include pp in effect requests/failuresJon French
2019-03-11Improve ocamldoc commentsAlasdair Armstrong
Check in a slightly nicer stylesheet for OCamldoc generated documentation in etc. Most just add a maximum width and increase the font size because the default looks absolutely terrible on high-DPI monitors. Move val_spec_ids out of initial_check and into ast_util where it probably belongs. Rename some functions in util.ml to better match the OCaml stdlib.
2019-03-08C: Refactor C backendAlasdair Armstrong
Main change is splitting apart the Sail->IR compilation stage and the C code generation and optimization phase. Rather than variously calling the intermediate language either bytecode (when it's not really) or simply IR, we give it a name: Jib (a type of Sail). Most of the types are still prefixed by c/C, and I don't think it's worth changing this. The various parts of the C backend are now in the src/jib/ subdirectory src/jib/anf.ml - Sail->ANF translation src/jib/jib_util.ml - various Jib AST processing and helper functions (formerly bytecode_util) src/jib/jib_compile.ml - Sail->Jib translation (using Sail->ANF) src/jib/c_backend.ml - Jib->C code generator and optimizations Further, bytecode.ott is now jib.ott and generates jib.ml (which still lives in src/ for now) The optimizations in c_backend.ml should eventually be moved in a separate jib_optimization file. The Sail->Jib compilation can be parameterised by two functions - one is a custom ANF->ANF optimization pass that can be specified on a per Jib backend basis, and the other is the rule for translating Sail types in Jib types. This can be more or less precise depending on how precise we want to be about bit-widths etc, i.e. we only care about <64 and >64 for C, but for SMT generation we would want to be as precise as possible. Additional improvements: The Jib IR is now agnostic about whether arguments are allocated on the heap vs the stack and this is handled by the C code generator. jib.ott now has some more comments explaining various parts of the Jib AST. A Set module and comparison function for ctyps is defined, and some functions now return ctyp sets rather than lists to avoid repeated work.
2019-03-04Merge branch 'sail2' into rmem_interpreterJon French
2019-02-25Allow int-specialization for non-externs onlyAlasdair Armstrong
Add a flag in C backend ctx that allows us to generate arbitrary precision signed integer types, rather than just int64
2019-02-25Merge branch 'sail2' into rmem_interpreterJon French
2019-02-22Fix some bugs in int-specializationAlasdair Armstrong
2019-02-19Refactor specializationAlasdair Armstrong
specialize functions now take a 'specialization' parameter that specifies how they will specialize the AST. typ_ord_specialization gives the previous behaviour, whereas int_specialization allows specializing on Int-kinded arguments. Note that this can loop forever unless the appropriate case splits are inserted beforehand, presumably by monomorphisation. rename is_nat_kopt -> is_int_kopt for consistency
2019-02-14Don't do any rewrites when checking files for EmacsAlasdair Armstrong
This makes sure we don't do any kind of re-writing or de-scatter any definitions when loading files into emacs. The difference here is that normally all files are processed together, but the emacs mode loads each file one by one. This is probably what we want to be doing anyway, so location information stays accurate for scattered functions for things like type-at-cursor commands and similar. Also fix some warnings. Fixes #32
2019-02-13Merge branch 'sail2' into rmem_interpreterJon French
2019-02-12Improvements for emacs modeAlasdair Armstrong
2019-02-08Rewrite type definitions in rewrite_nexp_idsThomas Bauereiss
For example, in type xlen : Int = 64 type xlenbits = bits(xlen) rewrite the 'xlen' in the definition of 'xlenbits' to the constant 64 in order to simplify Lem generation. In order to facilitate this, pass through the global typing environment to the rewriting steps (in the AST itself, type definitions don't carry annotations with environments).
2019-02-06Emacs mode understands relationships between Sail filesAlasdair
Allow a file sail.json in the same directory as the sail source file which contains the ordering and options needed for sail files involved in a specific ISA definition. I have an example for v8.5 in sail-arm. The interactive Sail process running within emacs then knows about the relationship between Sail files, so C-c C-l works for files in the ARM spec. Also added a C-c C-x command to jump to a type error. Requires yojson library to build interactive Sail.
2019-02-06Improve emacs modeAlasdair Armstrong
Can now use C-c C-s to start an interactive Sail process, C-c C-l to load a file, and C-c C-q to kill the sail process. Type errors are highlighted in the emacs buffer (like with merlin for OCaml) with a tooltip for the type-error, as well as being displayed in the minibuffer. Need to add a C-c C-x command like merlin to jump to the error, and figure out how to handle multiple files nicely, as well as hooking the save function like tuareg/merlin, but this is already enough to make working with small examples quite a bit more pleasant.
2018-12-28Merge branch 'sail2' into rmem_interpreterJon French
2018-12-27pass typechecking environment around interpreter and rewritersJon French
2018-12-26Some cleanupAlasdair Armstrong
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-20Fix monomorpisation tests with typechecker changesAlasdair Armstrong
Add an extra argument for Type_check.prove for the location of the prove call (as prove __POS__) to help debug SMT related issues
2018-12-19Improve sizeof rewriting performanceAlasdair Armstrong
Simply constraints further before calling Z3 to improve performance of sizeof re-writing.
2018-12-10Various changes:Alasdair Armstrong
* Improve type inference for numeric if statements (if_infer test) * Correctly handle constraints for existentially quantified constructors (constraint_ctor test) * Canonicalise all numeric types in function arguments, which triggers some weird edge cases between parametric polymorphism and subtyping of numeric arguments * Because of this eq_int, eq_range, and eq_atom etc become identical * Avoid duplicating destruct_exist in Env * Handle some odd subtyping cases better
2018-12-06Re-factor initial checkAlasdair Armstrong
Mostly this is to change how we desugar types in order to make us more flexible with what we can parse as a valid constraint as type. Previously the structure of the initial check forced some awkward limitations on what was parseable due to how the parse AST is set up. As part of this, I've taken the de-scattering of scattered functions out of the initial check, and moved it to a re-writing step after type-checking, where I think it logically belongs. This doesn't change much right now, but opens up some more possibilities in the future: Since scattered functions are now typechecked normally, any future module system for Sail would be able to handle them specially, and the Latex documentation backend can now document scattered functions explicitly, rather than relying on hackish 'de-scattering' logic to present documentation as the functions originally appeared. This has one slight breaking change which is that union clauses must appear before their uses in scattered functions, so union ast = Foo : unit function clause execute(Foo()) is ok, but function clause execute(Foo()) union ast = Foo : unit is not. Previously this worked because the de-scattering moved union clauses upwards before type-checking, but as this now happens after type-checking they must appear in the correct order. This doesn't occur in ARM, RISC-V, MIPS, but did appear in Cheri and I submitted a pull request to re-order the places where it happens.