Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Put all option handling in a single place

  • Loading branch information...
commit 9691437a4d8b45a3d14d4cef137210c68ed8413f 1 parent 7323805
@nickg authored
View
16 src/cgen.c
@@ -37,9 +37,6 @@ static LLVMModuleRef module = NULL;
static LLVMBuilderRef builder = NULL;
static LLVMValueRef mod_name = NULL;
-static bool run_optimiser = true;
-static bool dump_module = false;
-
static ident_t var_offset_i = NULL;
static ident_t local_var_i = NULL;
static ident_t sig_struct_i = NULL;
@@ -2944,13 +2941,13 @@ void cgen(tree_t top)
cgen_top(top);
- if (dump_module)
+ if (opt_get_int("dump-llvm"))
LLVMDumpModule(module);
if (LLVMVerifyModule(module, LLVMPrintMessageAction, NULL))
fatal("LLVM verification failed");
- if (run_optimiser)
+ if (opt_get_int("optimise"))
optimise();
char fname[256];
@@ -2965,12 +2962,3 @@ void cgen(tree_t top)
LLVMDisposeModule(module);
}
-void cgen_optimise_en(bool en)
-{
- run_optimiser = en;
-}
-
-void cgen_dump_en(bool on)
-{
- dump_module = on;
-}
View
16 src/link.c
@@ -31,8 +31,6 @@
static char **args = NULL;
static int n_args = 0;
-static bool optimise = true;
-static bool native = false;
__attribute__((format(printf, 1, 2)))
static void link_arg_f(const char *fmt, ...)
@@ -179,7 +177,7 @@ void link_bc(tree_t top)
link_arg_f("%s/llvm-ld", LLVM_CONFIG_BINDIR);
link_arg_f("-r");
- if (!optimise)
+ if (!opt_get_int("optimise"))
link_arg_f("--disable-opt");
link_arg_f("-b");
@@ -193,16 +191,6 @@ void link_bc(tree_t top)
link_args_end();
- if (native)
+ if (opt_get_int("native"))
link_native(top);
}
-
-void link_optimise_en(bool en)
-{
- optimise = en;
-}
-
-void link_native_en(bool en)
-{
- native = en;
-}
View
23 src/nvc.c
@@ -80,10 +80,10 @@ static int analyse(int argc, char **argv)
// getopt_long already printed an error message
exit(EXIT_FAILURE);
case 'b':
- sem_bootstrap_en(true);
+ opt_set_int("bootstrap", 1);
break;
case 'd':
- cgen_dump_en(true);
+ opt_set_int("dump-llvm", 1);
break;
default:
abort();
@@ -143,14 +143,13 @@ static int elaborate(int argc, char **argv)
while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) {
switch (c) {
case 'o':
- cgen_optimise_en(false);
- link_optimise_en(false);
+ opt_set_int("optimise", 0);
break;
case 'd':
- cgen_dump_en(true);
+ opt_set_int("dump-llvm", 1);
break;
case 'n':
- link_native_en(true);
+ opt_set_int("native", 1);
break;
case 0:
// Set a flag
@@ -245,7 +244,7 @@ static int run(int argc, char **argv)
// getopt_long already printed an error message
exit(EXIT_FAILURE);
case 't':
- rt_trace_en(true);
+ opt_set_int("rt_trace_en", 1);
break;
case 'b':
mode = BATCH;
@@ -344,6 +343,15 @@ static int dump_cmd(int argc, char **argv)
return EXIT_SUCCESS;
}
+static void set_default_opts(void)
+{
+ opt_set_int("rt_trace_en", 0);
+ opt_set_int("dump-llvm", 0);
+ opt_set_int("optimise", 1);
+ opt_set_int("native", 0);
+ opt_set_int("bootstrap", 0);
+}
+
static void usage(void)
{
printf("Usage: %s [OPTION]... COMMAND [OPTION]...\n"
@@ -402,6 +410,7 @@ int main(int argc, char **argv)
{
term_init();
register_trace_signal_handlers();
+ set_default_opts();
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
View
13 src/phase.h
@@ -27,9 +27,6 @@ bool sem_check(tree_t t);
// The number of errors found during the semantic check phase.
int sem_errors(void);
-// Enable special mode for analysing STANDARD package
-void sem_bootstrap_en(bool en);
-
// Fold all constant expressions
void simplify(tree_t top);
@@ -48,13 +45,6 @@ tree_t elab(tree_t top);
// Generate LLVM bitcode for an elaborated design
void cgen(tree_t top);
-// Toggle LLVM optimisations on and off
-void cgen_optimise_en(bool en);
-void link_optimise_en(bool en);
-
-// Toggle dumping of generated LLVM IR
-void cgen_dump_en(bool on);
-
// Dump out a VHDL representation of the given unit
void dump(tree_t top);
@@ -64,7 +54,4 @@ void opt(tree_t top);
// Link together bitcode packages with elaborated design
void link_bc(tree_t top);
-// Enable native code output
-void link_native_en(bool en);
-
#endif // _PHASE_H
View
1  src/rt/rt.h
@@ -30,7 +30,6 @@ typedef void (*sig_event_fn_t)(uint64_t, struct tree *);
void rt_batch_exec(struct tree *e, uint64_t stop_time,
struct tree_rd_ctx *ctx);
void rt_slave_exec(struct tree *e, struct tree_rd_ctx *ctx);
-void rt_trace_en(bool en);
void rt_set_event_cb(struct tree *s, sig_event_fn_t fn);
size_t rt_signal_value(struct tree *s, uint64_t *buf, size_t max);
View
7 src/rt/rtkern.c
@@ -933,6 +933,8 @@ static void rt_one_time_init(void)
jit_bind_fn("_iexp", _iexp);
jit_bind_fn("_inst_name", _inst_name);
+ trace_on = opt_get_int("rt_trace_en");
+
event_stack = rt_alloc_stack_new(sizeof(struct event));
waveform_stack = rt_alloc_stack_new(sizeof(struct waveform));
sens_list_stack = rt_alloc_stack_new(sizeof(struct sens_list));
@@ -991,11 +993,6 @@ static void rt_cleanup(tree_t top)
rt_alloc_stack_destroy(sens_list_stack);
}
-void rt_trace_en(bool en)
-{
- trace_on = en;
-}
-
static bool rt_stop_now(uint64_t stop_time)
{
struct event *peek = heap_min(eventq_heap);
View
8 src/sem.c
@@ -66,7 +66,6 @@ static bool sem_locally_static(tree_t t);
static struct scope *top_scope = NULL;
static int errors = 0;
static struct type_set *top_type_set = NULL;
-static bool bootstrap = false;
static ident_t builtin_i;
static ident_t std_standard_i;
@@ -886,7 +885,7 @@ static bool sem_check_context(tree_t t)
{
// The std.standard package is also implicit unless we are
// bootstrapping
- if (!bootstrap) {
+ if (!opt_get_int("bootstrap")) {
lib_t std = lib_find("std", true, true);
if (std == NULL)
fatal("failed to find std library");
@@ -3428,8 +3427,3 @@ int sem_errors(void)
{
return errors;
}
-
-void sem_bootstrap_en(bool en)
-{
- bootstrap = en;
-}
View
41 src/util.c
@@ -104,8 +104,15 @@ typedef void (*print_fn_t)(const char *fmt, ...);
static void def_error_fn(const char *msg, const loc_t *loc);
-static error_fn_t error_fn = def_error_fn;
-static bool want_color = false;
+struct option {
+ struct option *next;
+ const char *key;
+ int value;
+};
+
+static error_fn_t error_fn = def_error_fn;
+static bool want_color = false;
+static struct option *options = NULL;
static void paginate_msg(const char *fmt, va_list ap, int left, int right)
{
@@ -605,3 +612,33 @@ void term_init(void)
want_color = isatty(STDERR_FILENO) && (nvc_no_color == NULL);
#endif // HAVE_CURSES
}
+
+void opt_set_int(const char *name, int val)
+{
+ struct option *it;
+ for (it = options; (it != NULL) && (it->key != name); it = it->next)
+ ;
+
+ if (it != NULL)
+ it->value = val;
+ else {
+ it = xmalloc(sizeof(struct option));
+ it->key = name;
+ it->value = val;
+ it->next = options;
+
+ options = it;
+ }
+}
+
+int opt_get_int(const char *name)
+{
+ struct option *it;
+ for (it = options; (it != NULL) && (it->key != name); it = it->next)
+ ;
+
+ if (it != NULL)
+ return it->value;
+ else
+ fatal("invalid option %s", name);
+}
View
3  src/util.h
@@ -84,4 +84,7 @@ int32_t read_i32(FILE *f);
int64_t read_i64(FILE *f);
uint8_t read_u8(FILE *f);
+void opt_set_int(const char *name, int val);
+int opt_get_int(const char *name);
+
#endif // _UTIL_H
View
1  test/test_elab.c
@@ -19,6 +19,7 @@ static error_fn_t orig_error_fn = NULL;
static void setup(void)
{
lib_set_work(lib_tmp());
+ opt_set_int("bootstrap", 0);
}
static void teardown(void)
View
1  test/test_sem.c
@@ -19,6 +19,7 @@ static error_fn_t orig_error_fn = NULL;
static void setup(void)
{
lib_set_work(lib_tmp());
+ opt_set_int("bootstrap", 0);
}
static void teardown(void)
View
1  test/test_simp.c
@@ -19,6 +19,7 @@ static error_fn_t orig_error_fn = NULL;
static void setup(void)
{
lib_set_work(lib_tmp());
+ opt_set_int("bootstrap", 0);
}
static void teardown(void)

2 comments on commit 9691437

@hiyuh

FYI, opt_set_int() and opt_get_int() have problematic key/name handling.

hiyuh@0af36bf
hiyuh@b1fd358

@nickg
Owner

Thanks, applied them.

Please sign in to comment.
Something went wrong with that request. Please try again.