From 121f0185d6923c84d64ee75326d15013eb5d1fe0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 3 Nov 2017 23:46:42 +0000 Subject: [PATCH] Custom thread local models --- core/sys/wgl.odin | 1 - src/check_decl.cpp | 21 ++++++++++++++------- src/entity.cpp | 2 +- src/ir.cpp | 4 ++-- src/ir_print.cpp | 10 ++++++++-- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/sys/wgl.odin b/core/sys/wgl.odin index 6ac5ffbf5..1de6790dc 100644 --- a/core/sys/wgl.odin +++ b/core/sys/wgl.odin @@ -64,7 +64,6 @@ Get_Extensions_String_ARB_Type :: #type proc "c" (Hdc) -> ^u8; get_extensions_string_arb: Get_Extensions_String_ARB_Type; - foreign opengl32 { @(link_name="wglCreateContext") create_context :: proc(hdc: Hdc) -> Hglrc ---; 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) {