aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-11-17 20:21:58 +0000
committergingerBill <bill@gingerbill.org>2017-11-17 20:21:58 +0000
commitb0e3a4e27655cff42b3645ba4be2ad3a602997b9 (patch)
tree82574f11c3e903877b43859d653ffd4f35902191 /src/main.cpp
parentb651466630f4a643711ac1e266db72eab2029e7f (diff)
`build_dll` replace with `-build-mode=dll`
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp111
1 files changed, 66 insertions, 45 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 78fbbf178..94a14a028 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -171,6 +171,35 @@ void usage(String argv0) {
}
+bool string_is_valid_identifier(String str) {
+ if (str.len <= 0) return false;
+
+ isize rune_count = 0;
+
+ isize w = 0;
+ isize offset = 0;
+ while (offset < str.len) {
+ Rune r = 0;
+ w = gb_utf8_decode(str.text, str.len, &r);
+ if (r == GB_RUNE_INVALID) {
+ return false;
+ }
+
+ if (rune_count == 0) {
+ if (!rune_is_letter(r)) {
+ return false;
+ }
+ } else {
+ if (!rune_is_letter(r) && !rune_is_digit(r)) {
+ return false;
+ }
+ }
+ rune_count += 1;
+ offset += w;
+ }
+
+ return true;
+}
enum BuildFlagKind {
BuildFlag_Invalid,
@@ -180,6 +209,7 @@ enum BuildFlagKind {
BuildFlag_ThreadCount,
BuildFlag_KeepTempFiles,
BuildFlag_Collection,
+ BuildFlag_BuildMode,
BuildFlag_COUNT,
};
@@ -201,42 +231,11 @@ struct BuildFlag {
BuildFlagParamKind param_kind;
};
-
void add_flag(Array<BuildFlag> *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind) {
BuildFlag flag = {kind, name, param_kind};
array_add(build_flags, flag);
}
-bool string_is_valid_identifier(String str) {
- if (str.len <= 0) return false;
-
- isize rune_count = 0;
-
- isize w = 0;
- isize offset = 0;
- while (offset < str.len) {
- Rune r = 0;
- w = gb_utf8_decode(str.text, str.len, &r);
- if (r == GB_RUNE_INVALID) {
- return false;
- }
-
- if (rune_count == 0) {
- if (!rune_is_letter(r)) {
- return false;
- }
- } else {
- if (!rune_is_letter(r) && !rune_is_digit(r)) {
- return false;
- }
- }
- rune_count += 1;
- offset += w;
- }
-
- return true;
-}
-
bool parse_build_flags(Array<String> args) {
Array<BuildFlag> build_flags = {};
array_init(&build_flags, heap_allocator(), BuildFlag_COUNT);
@@ -245,6 +244,7 @@ bool parse_build_flags(Array<String> args) {
add_flag(&build_flags, BuildFlag_ThreadCount, str_lit("thread-count"), BuildFlagParam_Integer);
add_flag(&build_flags, BuildFlag_KeepTempFiles, str_lit("keep-temp-files"), BuildFlagParam_None);
add_flag(&build_flags, BuildFlag_Collection, str_lit("collection"), BuildFlagParam_String);
+ add_flag(&build_flags, BuildFlag_BuildMode, str_lit("build-mode"), BuildFlagParam_String);
Array<String> flag_args = args;
@@ -391,7 +391,8 @@ bool parse_build_flags(Array<String> args) {
} else {
build_context.thread_count = count;
}
- } break;
+ break;
+ }
case BuildFlag_KeepTempFiles:
GB_ASSERT(value.kind == ExactValue_Invalid);
build_context.keep_temp_files = true;
@@ -459,7 +460,30 @@ bool parse_build_flags(Array<String> args) {
// NOTE(bill): Allow for multiple library collections
continue;
- } break;
+ }
+
+ case BuildFlag_BuildMode: {
+ GB_ASSERT(value.kind == ExactValue_String);
+ String str = value.value_string;
+
+ if (build_context.command != "build") {
+ gb_printf_err("'build-mode' can only be used with the 'build' command\n");
+ bad_flags = true;
+ break;
+ }
+
+ if (str == "dll") {
+ build_context.is_dll = true;
+ } else if (str == "exe") {
+ build_context.is_dll = false;
+ } else {
+ gb_printf_err("Unknown build mode '%.*s'\n", LIT(str));
+ bad_flags = true;
+ break;
+ }
+
+ break;
+ }
}
}
@@ -559,29 +583,24 @@ int main(int arg_count, char **arg_ptr) {
#if 1
+ String command = args[1];
+
String init_filename = {};
bool run_output = false;
- if (args[1] == "run") {
+ if (command == "run") {
if (args.count < 3) {
usage(args[0]);
return 1;
}
init_filename = args[2];
run_output = true;
- } else if (args[1] == "build_dll") {
+ } else if (command == "build") {
if (args.count < 3) {
usage(args[0]);
return 1;
}
init_filename = args[2];
- build_context.is_dll = true;
- } else if (args[1] == "build") {
- if (args.count < 3) {
- usage(args[0]);
- return 1;
- }
- init_filename = args[2];
- } else if (args[1] == "docs") {
+ } else if (command == "docs") {
if (args.count < 3) {
usage(args[0]);
return 1;
@@ -593,7 +612,7 @@ int main(int arg_count, char **arg_ptr) {
print_usage_line(0, "Documentation generation is not yet supported");
return 1;
#endif
- } else if (args[1] == "version") {
+ } else if (command == "version") {
gb_printf("%.*s version %.*s\n", LIT(args[0]), LIT(ODIN_VERSION));
return 0;
} else {
@@ -601,11 +620,14 @@ int main(int arg_count, char **arg_ptr) {
return 1;
}
+ build_context.command = command;
+
if (!parse_build_flags(args)) {
return 1;
}
+
// NOTE(bill): add 'shared' directory if it is not already set
if (!find_library_collection_path(str_lit("shared"), nullptr)) {
add_library_collection(str_lit("shared"),
@@ -686,7 +708,6 @@ int main(int arg_count, char **arg_ptr) {
String output_name = ir_gen.output_name;
String output_base = ir_gen.output_base;
- int base_name_len = cast(int)output_base.len;
build_context.optimization_level = gb_clamp(build_context.optimization_level, 0, 3);