aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-11-03 23:46:42 +0000
committergingerBill <bill@gingerbill.org>2017-11-03 23:46:42 +0000
commit121f0185d6923c84d64ee75326d15013eb5d1fe0 (patch)
treeefdd5144c55a761d2f9a81f5d04f4fed264661d6 /src
parente7999f8450aca9c4c81e272470be438e6a183939 (diff)
Custom thread local models
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp21
-rw-r--r--src/entity.cpp2
-rw-r--r--src/ir.cpp4
-rw-r--r--src/ir_print.cpp10
4 files changed, 25 insertions, 12 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 813028ab1..b38575e24 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -761,16 +761,23 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
error(elem, "Expected a string value for `%.*s`", LIT(name));
}
} else if (name == "thread_local") {
- if (ev.kind == ExactValue_Invalid) {
- if (!e->scope->is_file) {
- error(elem, "Only a variable at file scope can be thread local");
- } else if (init_expr_list.count > 0) {
- error(elem, "A thread local variable declaration cannot have initialization values");
+ if (!e->scope->is_file) {
+ error(elem, "Only a variable at file scope can be thread local");
+ } else if (init_expr_list.count > 0) {
+ error(elem, "A thread local variable declaration cannot have initialization values");
+ } else if (ev.kind == ExactValue_Invalid) {
+ e->Variable.thread_local_model = str_lit("default");
+ } else if (ev.kind == ExactValue_String) {
+ String model = ev.value_string;
+ if (model == "localdynamic" ||
+ model == "initialexec" ||
+ model == "localexec") {
+ e->Variable.thread_local_model = model;
} else {
- e->Variable.is_thread_local = true;
+ error(elem, "Invalid thread local model `%.*s`", LIT(model));
}
} else {
- error(elem, "Expected no value for `%.*s`", LIT(name));
+ error(elem, "Expected either no value or a string for `%.*s`", LIT(name));
}
} else if (name == "link_prefix") {
if (ev.kind == ExactValue_String) {
diff --git a/src/entity.cpp b/src/entity.cpp
index b84d9a7e0..8fb6f8b69 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -84,7 +84,7 @@ struct Entity {
bool default_is_undef;
bool default_is_location;
bool is_immutable;
- bool is_thread_local;
+ String thread_local_model;
bool is_foreign;
bool is_export;
Entity * foreign_library;
diff --git a/src/ir.cpp b/src/ir.cpp
index e554666f2..4056dc88f 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -363,7 +363,7 @@ struct irValueGlobal {
bool is_constant;
bool is_export;
bool is_private;
- bool is_thread_local;
+ String thread_local_model;
bool is_foreign;
bool is_unnamed_addr;
};
@@ -8191,7 +8191,7 @@ void ir_gen_tree(irGen *s) {
irValue *g = ir_value_global(a, e, nullptr);
g->Global.name = name;
- g->Global.is_thread_local = e->Variable.is_thread_local;
+ g->Global.thread_local_model = e->Variable.thread_local_model;
g->Global.is_foreign = is_foreign;
g->Global.is_export = is_export;
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
index 637486912..27704133f 100644
--- a/src/ir_print.cpp
+++ b/src/ir_print.cpp
@@ -1934,8 +1934,14 @@ void print_llvm_ir(irGen *ir) {
ir_write_string(f, str_lit("dllexport "));
}
}
- if (g->is_thread_local) {
- ir_write_string(f, str_lit("thread_local "));
+ if (g->thread_local_model.len > 0) {
+ String model = g->thread_local_model;
+ if (model == "default") {
+ ir_write_string(f, str_lit("thread_local "));
+ } else {
+ ir_fprintf(f, "thread_local(%.*s) ", LIT(model));
+
+ }
}
if (g->is_private) {