Browse Source

Add `ODIN_BUILD_MODE`

gingerBill 3 years ago
parent
commit
b2a2aa15c2
4 changed files with 40 additions and 18 deletions
  1. 18 17
      core/runtime/internal.odin
  2. 19 0
      src/build_settings.cpp
  3. 2 0
      src/checker.cpp
  4. 1 1
      src/main.cpp

+ 18 - 17
core/runtime/internal.odin

@@ -3,7 +3,8 @@ package runtime
 import "core:intrinsics"
 import "core:intrinsics"
 
 
 @(private)
 @(private)
-RUNTIME_LINKAGE :: "strong" when ODIN_USE_SEPARATE_MODULES else "internal"
+RUNTIME_LINKAGE :: "strong" when (ODIN_USE_SEPARATE_MODULES || ODIN_BUILD_MODE == "dynamic_library") else "internal"
+RUNTIME_EXPORT :: ODIN_BUILD_MODE == "dynamic"
 
 
 @(private)
 @(private)
 byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte #no_bounds_check {
 byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte #no_bounds_check {
@@ -649,7 +650,7 @@ quo_quaternion256 :: proc "contextless" (q, r: quaternion256) -> quaternion256 {
 	return quaternion(t0, t1, t2, t3)
 	return quaternion(t0, t1, t2, t3)
 }
 }
 
 
-@(link_name="__truncsfhf2", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__truncsfhf2", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 truncsfhf2 :: proc "c" (value: f32) -> u16 {
 truncsfhf2 :: proc "c" (value: f32) -> u16 {
 	v: struct #raw_union { i: u32, f: f32 }
 	v: struct #raw_union { i: u32, f: f32 }
 	i, s, e, m: i32
 	i, s, e, m: i32
@@ -707,12 +708,12 @@ truncsfhf2 :: proc "c" (value: f32) -> u16 {
 }
 }
 
 
 
 
-@(link_name="__truncdfhf2", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__truncdfhf2", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 truncdfhf2 :: proc "c" (value: f64) -> u16 {
 truncdfhf2 :: proc "c" (value: f64) -> u16 {
 	return truncsfhf2(f32(value))
 	return truncsfhf2(f32(value))
 }
 }
 
 
-@(link_name="__gnu_h2f_ieee", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__gnu_h2f_ieee", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 gnu_h2f_ieee :: proc "c" (value: u16) -> f32 {
 gnu_h2f_ieee :: proc "c" (value: u16) -> f32 {
 	fp32 :: struct #raw_union { u: u32, f: f32 }
 	fp32 :: struct #raw_union { u: u32, f: f32 }
 
 
@@ -731,19 +732,19 @@ gnu_h2f_ieee :: proc "c" (value: u16) -> f32 {
 }
 }
 
 
 
 
-@(link_name="__gnu_f2h_ieee", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__gnu_f2h_ieee", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 gnu_f2h_ieee :: proc "c" (value: f32) -> u16 {
 gnu_f2h_ieee :: proc "c" (value: f32) -> u16 {
 	return truncsfhf2(value)
 	return truncsfhf2(value)
 }
 }
 
 
-@(link_name="__extendhfsf2", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__extendhfsf2", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 extendhfsf2 :: proc "c" (value: u16) -> f32 {
 extendhfsf2 :: proc "c" (value: u16) -> f32 {
 	return gnu_h2f_ieee(value)
 	return gnu_h2f_ieee(value)
 }
 }
 
 
 
 
 
 
-@(link_name="__floattidf", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__floattidf", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 floattidf :: proc "c" (a: i128) -> f64 {
 floattidf :: proc "c" (a: i128) -> f64 {
 	DBL_MANT_DIG :: 53
 	DBL_MANT_DIG :: 53
 	if a == 0 {
 	if a == 0 {
@@ -786,7 +787,7 @@ floattidf :: proc "c" (a: i128) -> f64 {
 }
 }
 
 
 
 
-@(link_name="__floattidf_unsigned", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__floattidf_unsigned", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 floattidf_unsigned :: proc "c" (a: u128) -> f64 {
 floattidf_unsigned :: proc "c" (a: u128) -> f64 {
 	DBL_MANT_DIG :: 53
 	DBL_MANT_DIG :: 53
 	if a == 0 {
 	if a == 0 {
@@ -828,14 +829,14 @@ floattidf_unsigned :: proc "c" (a: u128) -> f64 {
 
 
 
 
 
 
-@(link_name="__fixunsdfti", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__fixunsdfti", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 fixunsdfti :: #force_no_inline proc "c" (a: f64) -> u128 {
 fixunsdfti :: #force_no_inline proc "c" (a: f64) -> u128 {
 	// TODO(bill): implement `fixunsdfti` correctly
 	// TODO(bill): implement `fixunsdfti` correctly
 	x := u64(a)
 	x := u64(a)
 	return u128(x)
 	return u128(x)
 }
 }
 
 
-@(link_name="__fixunsdfdi", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__fixunsdfdi", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 fixunsdfdi :: #force_no_inline proc "c" (a: f64) -> i128 {
 fixunsdfdi :: #force_no_inline proc "c" (a: f64) -> i128 {
 	// TODO(bill): implement `fixunsdfdi` correctly
 	// TODO(bill): implement `fixunsdfdi` correctly
 	x := i64(a)
 	x := i64(a)
@@ -845,7 +846,7 @@ fixunsdfdi :: #force_no_inline proc "c" (a: f64) -> i128 {
 
 
 
 
 
 
-@(link_name="__umodti3", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__umodti3", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 umodti3 :: proc "c" (a, b: u128) -> u128 {
 umodti3 :: proc "c" (a, b: u128) -> u128 {
 	r: u128 = ---
 	r: u128 = ---
 	_ = udivmod128(a, b, &r)
 	_ = udivmod128(a, b, &r)
@@ -853,18 +854,18 @@ umodti3 :: proc "c" (a, b: u128) -> u128 {
 }
 }
 
 
 
 
-@(link_name="__udivmodti4", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__udivmodti4", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 udivmodti4 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
 udivmodti4 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
 	return udivmod128(a, b, rem)
 	return udivmod128(a, b, rem)
 }
 }
 
 
-@(link_name="__udivti3", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__udivti3", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 udivti3 :: proc "c" (a, b: u128) -> u128 {
 udivti3 :: proc "c" (a, b: u128) -> u128 {
 	return udivmodti4(a, b, nil)
 	return udivmodti4(a, b, nil)
 }
 }
 
 
 
 
-@(link_name="__modti3", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__modti3", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 modti3 :: proc "c" (a, b: i128) -> i128 {
 modti3 :: proc "c" (a, b: i128) -> i128 {
 	s_a := a >> (128 - 1)
 	s_a := a >> (128 - 1)
 	s_b := b >> (128 - 1)
 	s_b := b >> (128 - 1)
@@ -877,20 +878,20 @@ modti3 :: proc "c" (a, b: i128) -> i128 {
 }
 }
 
 
 
 
-@(link_name="__divmodti4", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__divmodti4", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 divmodti4 :: proc "c" (a, b: i128, rem: ^i128) -> i128 {
 divmodti4 :: proc "c" (a, b: i128, rem: ^i128) -> i128 {
 	u := udivmod128(transmute(u128)a, transmute(u128)b, cast(^u128)rem)
 	u := udivmod128(transmute(u128)a, transmute(u128)b, cast(^u128)rem)
 	return transmute(i128)u
 	return transmute(i128)u
 }
 }
 
 
-@(link_name="__divti3", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__divti3", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 divti3 :: proc "c" (a, b: i128) -> i128 {
 divti3 :: proc "c" (a, b: i128) -> i128 {
 	u := udivmodti4(transmute(u128)a, transmute(u128)b, nil)
 	u := udivmodti4(transmute(u128)a, transmute(u128)b, nil)
 	return transmute(i128)u
 	return transmute(i128)u
 }
 }
 
 
 
 
-@(link_name="__fixdfti", linkage=RUNTIME_LINKAGE, require)
+@(link_name="__fixdfti", linkage=RUNTIME_LINKAGE, require, export=RUNTIME_EXPORT)
 fixdfti :: proc(a: u64) -> i128 {
 fixdfti :: proc(a: u64) -> i128 {
 	significandBits :: 52
 	significandBits :: 52
 	typeWidth       :: (size_of(u64)*8)
 	typeWidth       :: (size_of(u64)*8)

+ 19 - 0
src/build_settings.cpp

@@ -166,6 +166,7 @@ struct BuildContext {
 	String ODIN_VENDOR;  // compiler vendor
 	String ODIN_VENDOR;  // compiler vendor
 	String ODIN_VERSION; // compiler version
 	String ODIN_VERSION; // compiler version
 	String ODIN_ROOT;    // Odin ROOT
 	String ODIN_ROOT;    // Odin ROOT
+	String ODIN_BUILD_MODE;
 	bool   ODIN_DEBUG;   // Odin in debug mode
 	bool   ODIN_DEBUG;   // Odin in debug mode
 	bool   ODIN_DISABLE_ASSERT; // Whether the default 'assert' et al is disabled in code or not
 	bool   ODIN_DISABLE_ASSERT; // Whether the default 'assert' et al is disabled in code or not
 	bool   ODIN_DEFAULT_TO_NIL_ALLOCATOR; // Whether the default allocator is a "nil" allocator or not (i.e. it does nothing)
 	bool   ODIN_DEFAULT_TO_NIL_ALLOCATOR; // Whether the default allocator is a "nil" allocator or not (i.e. it does nothing)
@@ -815,6 +816,24 @@ void init_build_context(TargetMetrics *cross_target) {
 	bc->ODIN_VENDOR  = str_lit("odin");
 	bc->ODIN_VENDOR  = str_lit("odin");
 	bc->ODIN_VERSION = ODIN_VERSION;
 	bc->ODIN_VERSION = ODIN_VERSION;
 	bc->ODIN_ROOT    = odin_root_dir();
 	bc->ODIN_ROOT    = odin_root_dir();
+	switch (bc->build_mode) {
+	default:
+	case BuildMode_Executable:
+		bc->ODIN_BUILD_MODE = str_lit("executable");
+		break;
+	case BuildMode_DynamicLibrary:
+		bc->ODIN_BUILD_MODE = str_lit("dynamic");
+		break;
+	case BuildMode_Object:
+		bc->ODIN_BUILD_MODE = str_lit("object");
+		break;
+	case BuildMode_Assembly:
+		bc->ODIN_BUILD_MODE = str_lit("assembly");
+		break;
+	case BuildMode_LLVM_IR:
+		bc->ODIN_BUILD_MODE = str_lit("llvm-ir");
+		break;
+	}
 	
 	
 	bc->copy_file_contents = true;
 	bc->copy_file_contents = true;
 
 

+ 2 - 0
src/checker.cpp

@@ -778,6 +778,8 @@ void init_universal(void) {
 	add_global_string_constant("ODIN_VENDOR",  bc->ODIN_VENDOR);
 	add_global_string_constant("ODIN_VENDOR",  bc->ODIN_VENDOR);
 	add_global_string_constant("ODIN_VERSION", bc->ODIN_VERSION);
 	add_global_string_constant("ODIN_VERSION", bc->ODIN_VERSION);
 	add_global_string_constant("ODIN_ROOT",    bc->ODIN_ROOT);
 	add_global_string_constant("ODIN_ROOT",    bc->ODIN_ROOT);
+	
+	add_global_string_constant("ODIN_BUILD_MODE", bc->ODIN_BUILD_MODE);
 	add_global_bool_constant("ODIN_DEBUG",                    bc->ODIN_DEBUG);
 	add_global_bool_constant("ODIN_DEBUG",                    bc->ODIN_DEBUG);
 	add_global_bool_constant("ODIN_DISABLE_ASSERT",           bc->ODIN_DISABLE_ASSERT);
 	add_global_bool_constant("ODIN_DISABLE_ASSERT",           bc->ODIN_DISABLE_ASSERT);
 	add_global_bool_constant("ODIN_DEFAULT_TO_NIL_ALLOCATOR", bc->ODIN_DEFAULT_TO_NIL_ALLOCATOR);
 	add_global_bool_constant("ODIN_DEFAULT_TO_NIL_ALLOCATOR", bc->ODIN_DEFAULT_TO_NIL_ALLOCATOR);

+ 1 - 1
src/main.cpp

@@ -1185,7 +1185,7 @@ bool parse_build_flags(Array<String> args) {
 								break;
 								break;
 							}
 							}
 
 
-							if (str == "dll" || str == "shared") {
+							if (str == "dll" || str == "shared" || str == "dynamic") {
 								build_context.build_mode = BuildMode_DynamicLibrary;
 								build_context.build_mode = BuildMode_DynamicLibrary;
 							} else if (str == "obj" || str == "object") {
 							} else if (str == "obj" || str == "object") {
 								build_context.build_mode = BuildMode_Object;
 								build_context.build_mode = BuildMode_Object;