From d87d4ad3a6d2ec2804cb7b20128fecb6d9df4e6e Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Thu, 25 Jan 2018 00:30:24 +0000 Subject: Add simple conditional processing and file include Can now use C-style include declarations to include files within other sail files. This is done in such a way that all the location information is preserved in error messages. As an example: $include "aarch64/prelude.sail" $define SYM $ifndef SYM $include <../util.sail> $endif would include the file aarch64/prelude.sail relative to the file where the include is contained. It then defines a symbol SYM and includes another file if it is not defined. The <../util.sail> include will be accessed relative to $SAIL_DIR/lib, so $SAIL_DIR/lib/../util.sail in this case. This can be used with the standard C trick of $ifndef ONCE $define ONCE val f : unit -> unit $endif so no matter how many sail files include the above file, the valspec for f will only appear once. Currently we just have $include, $define, $ifdef and $ifndef (with $else and $endif). We're using $ rather than # because # is already used in internal identifiers, although this could be switched. --- src/parser.mly | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/parser.mly') diff --git a/src/parser.mly b/src/parser.mly index b11b4b61..32ee3368 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -182,6 +182,8 @@ let rec desugar_rchain chain s e = %token Op0l Op1l Op2l Op3l Op4l Op5l Op6l Op7l Op8l Op9l %token Op0r Op1r Op2r Op3r Op4r Op5r Op6r Op7r Op8r Op9r +%token Pragma + %token Fixity %start file @@ -1246,6 +1248,8 @@ def: { DEF_default $1 } | Mutual Lcurly fun_def_list Rcurly { DEF_internal_mutrec $3 } + | Pragma + { DEF_pragma (fst $1, snd $1, loc $startpos $endpos) } defs_list: | def -- cgit v1.2.3