diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/rts.c | 114 | ||||
| -rw-r--r-- | lib/sail.c | 8 | ||||
| -rw-r--r-- | lib/sail.h | 1 | ||||
| -rw-r--r-- | lib/trace.sail | 22 |
4 files changed, 86 insertions, 59 deletions
@@ -1,5 +1,5 @@ #include<string.h> -#include<argp.h> +#include<getopt.h> #include<inttypes.h> #include"sail.h" @@ -329,7 +329,7 @@ static uint64_t g_cycle_limit; unit cycle_count(const unit u) { if (++g_cycle_count >= g_cycle_limit && g_cycle_limit != 0) { - printf("[Sail] cycle limit %" PRId64 " reached\n", g_cycle_limit); + printf("\n[Sail] cycle limit %" PRId64 " reached\n", g_cycle_limit); exit(EXIT_SUCCESS); } @@ -338,71 +338,67 @@ unit cycle_count(const unit u) /* ***** Argument Parsing ***** */ -static char doc[] = - "Sail RTS -- Sail C run time system"; - -/* A description of the arguments we accept. */ -static char args_doc[] = "ARG"; - -static struct argp_option options[] = { - {"elf", 'e', "FILE", 0, "Load an ELF file"}, - {"entry", 'n', "ADDRESS", 0, "Manually set the entry address"}, - {"image", 'i', "FILE", 0, "Load an Linksem preprocessed ELF image"}, - {"binary", 'b', "ADDRESS,FILE", 0, "Load a raw binary file"}, - {"cyclelimit", 'l', "NUMBER", 0, "Set a cycle limit"}, - { 0 } +static struct option options[] = { + {"elf", required_argument, 0, 'e'}, + {"entry", required_argument, 0, 'n'}, + {"image", required_argument, 0, 'i'}, + {"binary", required_argument, 0, 'b'}, + {"cyclelimit", required_argument, 0, 'l'}, + {0, 0, 0, 0} }; -static error_t parse_opt(int key, char *arg, struct argp_state *state) +int process_arguments(int argc, char *argv[]) { - switch (key) { - case 'b': ; - uint64_t addr; - char *file; - - if (!sscanf(arg, "0x%" PRIx64 ",%ms", &addr, &file)) { - fprintf(stderr, "Could not parse argument %s\n", arg); - return EINVAL; - }; - - load_raw(addr, file); - free(file); - break; - - case 'i': - load_image(arg); - break; - - case 'e': - load_elf(arg); - break; - - case 'n': - if (!sscanf(arg, "0x%" PRIx64, &g_elf_entry)) { - fprintf(stderr, "Could not parse address %s\n", arg); - return EINVAL; - } - break; + int c; - case 'l': - if (!sscanf(arg, "%" PRId64, &g_cycle_limit)) { - fprintf(stderr, "Could not parse cycle limit %s\n", arg); - return EINVAL; - } - break; + while (true) { + int option_index = 0; + c = getopt_long(argc, argv, "e:n:i:b:l:", options, &option_index); - default: - return ARGP_ERR_UNKNOWN; - } + if (c == -1) break; - return 0; -} + switch (c) { + case 'b': ; + uint64_t addr; + char *file; -static struct argp argp = {options, parse_opt, args_doc, doc}; + if (!sscanf(optarg, "0x%" PRIx64 ",%ms", &addr, &file)) { + fprintf(stderr, "Could not parse argument %s\n", optarg); + return -1; + }; -int process_arguments(int argc, char *argv[]) -{ - return argp_parse (&argp, argc, argv, 0, 0, NULL); + load_raw(addr, file); + free(file); + break; + + case 'i': + load_image(optarg); + break; + + case 'e': + load_elf(optarg); + break; + + case 'n': + if (!sscanf(optarg, "0x%" PRIx64, &g_elf_entry)) { + fprintf(stderr, "Could not parse address %s\n", optarg); + return -1; + } + break; + + case 'l': + if (!sscanf(optarg, "%" PRId64, &g_cycle_limit)) { + fprintf(stderr, "Could not parse cycle limit %s\n", optarg); + return -1; + } + break; + + default: + return -1; + } + } + + return 0; } /* ***** Setup and cleanup functions for RTS ***** */ @@ -518,6 +518,14 @@ bool eq_bits(const sail_bits op1, const sail_bits op2) return true; } +bool neq_bits(const sail_bits op1, const sail_bits op2) +{ + for (mp_bitcnt_t i = 0; i < op1.len; i++) { + if (mpz_tstbit(*op1.bits, i) != mpz_tstbit(*op2.bits, i)) return true; + } + return false; +} + void vector_subrange_sail_bits(sail_bits *rop, const sail_bits op, const sail_int n_mpz, @@ -218,6 +218,7 @@ void sign_extend(sail_bits *rop, const sail_bits op, const sail_int len); void length_sail_bits(sail_int *rop, const sail_bits op); bool eq_bits(const sail_bits op1, const sail_bits op2); +bool neq_bits(const sail_bits op1, const sail_bits op2); void vector_subrange_sail_bits(sail_bits *rop, const sail_bits op, diff --git a/lib/trace.sail b/lib/trace.sail new file mode 100644 index 00000000..2c9c1ed7 --- /dev/null +++ b/lib/trace.sail @@ -0,0 +1,22 @@ +$ifndef _TRACE +$define _TRACE + +val enable_tracing = { + c: "enable_tracing" +} : unit -> unit + +function enable_tracing() = () + +val disable_tracing = { + c: "disable_tracing" +} : unit -> unit + +function disable_tracing() = () + +val is_tracing = { + c: "is_tracing" +} : unit -> bool + +function is_tracing() = false + +$endif |
