aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-06-15 14:57:21 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitabe41cc2d5413faa8adeb16831f654435b6d0ef0 (patch)
tree3e08fe7d1857296ab9e41b5184b79005225361a5 /src
parent829e0174acac0adee10595cc04dd32cb64753107 (diff)
Add compiler option for number of threads to use (instead of env)
Diffstat (limited to 'src')
-rw-r--r--src/compiler.c20
-rw-r--r--src/tokenizer.c57
2 files changed, 4 insertions, 73 deletions
diff --git a/src/compiler.c b/src/compiler.c
index bdcb1c8..2b59a93 100644
--- a/src/compiler.c
+++ b/src/compiler.c
@@ -12,15 +12,6 @@
#include <limits.h>
#include <assert.h>
-static CHECK_RESULT int get_thread_count_env_var(int *thread_count) {
- char *threads;
- threads = getenv("THREADS");
- if(!threads)
- return -1;
- *thread_count = atoi(threads);
- return 0;
-}
-
static usize strnlen(const char *str, usize max_length) {
usize len;
len = 0;
@@ -70,23 +61,20 @@ static CHECK_RESULT int init_default_types(amal_compiler *compiler) {
void amal_compiler_options_init(amal_compiler_options *self) {
self->error_callback = NULL;
self->error_callback_userdata = NULL;
+ self->num_threads = 0;
}
int amal_compiler_init(amal_compiler *self, const amal_compiler_options *options) {
int i;
- int result;
- result = get_thread_count_env_var(&self->usable_thread_count);
- if(result != 0) {
+ self->usable_thread_count = options->num_threads;
+ if(self->usable_thread_count == 0) {
self->usable_thread_count = amal_get_usable_thread_count();
if(self->usable_thread_count == 0) {
amal_log_warning("Unable to get the number of threads available on the system, using 1 thread.");
- amal_log_warning("You can override the number of threads using by setting the environment variable THREADS");
+ amal_log_warning("You can override the number of threads using by setting compiler option for number of thread to use.");
self->usable_thread_count = 1;
}
- } else if(self->usable_thread_count <= 0) {
- amal_log_error("Environment variable THREADS contains invalid number for threads. THREADS has to be at least 1.");
- return AMAL_COMPILER_ERR;
}
am_memset(&self->allocator, 0, sizeof(self->allocator));
diff --git a/src/tokenizer.c b/src/tokenizer.c
index 03a72a1..bd57af7 100644
--- a/src/tokenizer.c
+++ b/src/tokenizer.c
@@ -709,63 +709,6 @@ void tokenizer_print_error_args(Tokenizer *self, int index, const char *fmt, va_
}
void tokenizer_print_error(Tokenizer *self, int index, const char *fmt, ...) {
-#if 0
- va_list args;
- int line;
- int line_start;
- int line_end;
- /*int code_start;*/
- int prev_column;
- int i;
-
- line = tokenizer_get_line_by_index(self, index);
- line_start = tokenizer_get_start_of_line_from_index(self, index);
- line_end = tokenizer_get_end_of_line_from_index(self, index);
- /*code_start = find_non_whitespace(&self->code.data[line_start], line_end - line_start);
- if(code_start != -1)
- line_start += code_start;*/
- prev_column = index - line_start;
-
- if(self->compiler_options->error_callback) {
- char buffer[2048];
- int bytes_copied;
-
- bytes_copied = 0;
- bytes_copied += max(0, snprintf(buffer + bytes_copied, sizeof(buffer) - bytes_copied, "%.*s:%d:%d: error: ", (int)self->code_name.size, self->code_name.data, line, 1 + prev_column));
-
- if(sizeof(buffer) - bytes_copied > 0) {
- va_start(args, fmt);
- bytes_copied += max(0, vsnprintf(buffer + bytes_copied, sizeof(buffer) - bytes_copied, fmt, args));
- va_end(args);
- }
-
- if(sizeof(buffer) - bytes_copied > 0)
- bytes_copied += max(0, snprintf(buffer + bytes_copied, sizeof(buffer) - bytes_copied, "\n%.*s\n", line_end - line_start, self->code.data + line_start));
-
- if(sizeof(buffer) - bytes_copied > 0) {
- for(i = 0; i < prev_column; ++i)
- bytes_copied += max(0, snprintf(buffer + bytes_copied, sizeof(buffer) - bytes_copied, " "));
- }
-
- if(sizeof(buffer) - bytes_copied > 0)
- bytes_copied += max(0, snprintf(buffer + bytes_copied, sizeof(buffer) - bytes_copied, "^\n"));
-
- self->compiler_options->error_callback(buffer, bytes_copied, self->compiler_options->error_callback_userdata);
- } else {
- amal_mutex *mutex;
- mutex = amal_log_get_mutex();
- ignore_result_int(amal_mutex_lock(mutex, "tokenizer_print_error"));
- va_start(args, fmt);
- fprintf(stderr, "\x1b[1;37m%.*s:%d:%d:\x1b[0m \x1b[1;31merror:\x1b[0m ", (int)self->code_name.size, self->code_name.data, line, 1 + prev_column);
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n%.*s\n", line_end - line_start, self->code.data + line_start);
- for(i = 0; i < prev_column; ++i)
- fprintf(stderr, " ");
- fprintf(stderr, "\x1b[1;32m^\x1b[0m\n");
- va_end(args);
- ignore_result_int(amal_mutex_unlock(mutex));
- }
-#endif
va_list args;
va_start(args, fmt);
tokenizer_print_error_args(self, index, fmt, args);