Skip to content

Commit

Permalink
Add option to add c flags through ocen CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaquraish committed Dec 5, 2023
1 parent 3aa0cfa commit 7343af3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bootstrap/stage0.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ bool debug = false;
u32 error_level = ((u32)2);
char *docs_path = NULL;
bool include_stdlib = true;
std_vector_Vector__5 *extra_c_flags;
/* function declarations */
FILE *std_File_open(char *path, char *mode);
i32 std_File_write(FILE *this, void *buf, u32 size);
Expand Down Expand Up @@ -11769,6 +11770,7 @@ void usage(i32 code) {
printf(" -d Emit debug information (default: false)""\n");
printf(" -l path Directory to search for libraries (can be used multiple times)""\n");
printf(" --docs path Output documentation JSON (default: none)""\n");
printf(" --cflags flags Additional C flags (can be used multiple times)""\n");
printf(" (Default: working directory)""\n");
printf("--------------------------------------------------------""\n");
exit(code);
Expand All @@ -11793,6 +11795,13 @@ void save_and_compile_code(ast_program_Program *program, char *code) {
strcat(cmdbuf, flag);
}
}
for (std_vector_Iterator__5 __iter = std_vector_Vector__5_iter(extra_c_flags); std_vector_Iterator__5_has_value(&__iter); std_vector_Iterator__5_next(&__iter)) {
char *flag = std_vector_Iterator__5_cur(&__iter);
{
strcat(cmdbuf, " ");
strcat(cmdbuf, flag);
}
}
if (debug) {
strcat(cmdbuf, " -ggdb3");
}
Expand All @@ -11807,6 +11816,7 @@ void save_and_compile_code(ast_program_Program *program, char *code) {
}

void parse_args(i32 argc, char **argv, ast_program_Program *program) {
extra_c_flags=std_vector_Vector__5_new(((u32)16));
for (u32 i = ((u32)1); (i < ((u32)argc)); i+=((u32)1)) {
{
char *__match_str = argv[i];
Expand Down Expand Up @@ -11839,6 +11849,8 @@ void parse_args(i32 argc, char **argv, ast_program_Program *program) {
program->check_doc_links=true;
} else if (!strcmp(__match_str, "--no-stdlib")) {
include_stdlib=false;
} else if (!strcmp(__match_str, "--cflags") || !strcmp(__match_str, "-cf")) {
std_vector_Vector__5_push(extra_c_flags, argv[++i]);
} else {
if (argv[i][((u32)0)]=='-') {
printf("Unknown option: %s""\n", argv[i]);
Expand Down
10 changes: 10 additions & 0 deletions compiler/main.oc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//* Entry point for the compiler

import std::libc::{ exit, calloc, system }
import std::vector::Vector
import .ast::program::Program
import .parser::Parser
import .passes::{ run_typecheck_passes, run_codegen_passes }
Expand All @@ -22,6 +23,7 @@ def usage(code: i32) {
println(" -d Emit debug information (default: false)")
println(" -l path Directory to search for libraries (can be used multiple times)")
println(" --docs path Output documentation JSON (default: none)")
println(" --cflags flags Additional C flags (can be used multiple times)")
println(" (Default: working directory)")
println("--------------------------------------------------------")
exit(code)
Expand All @@ -36,6 +38,7 @@ let debug: bool = false
let error_level: u32 = 2
let docs_path: str = null
let include_stdlib: bool = true
let extra_c_flags: &Vector<str>

def save_and_compile_code(program: &Program, code: str) {
if not c_path? {
Expand All @@ -54,6 +57,10 @@ def save_and_compile_code(program: &Program, code: str) {
cmdbuf.concat(" ")
cmdbuf.concat(flag)
}
for flag : extra_c_flags.iter() {
cmdbuf.concat(" ")
cmdbuf.concat(flag)
}
if debug {
cmdbuf.concat(" -ggdb3")
}
Expand All @@ -69,6 +76,8 @@ def save_and_compile_code(program: &Program, code: str) {
}

def parse_args(argc: i32, argv: &str, program: &Program) {
extra_c_flags = Vector<str>::new()

for let i = 1; i < argc as u32; i += 1 {
match argv[i] {
"-h" => usage(code: 0)
Expand Down Expand Up @@ -96,6 +105,7 @@ def parse_args(argc: i32, argv: &str, program: &Program) {
program.check_doc_links = true
}
"--no-stdlib" => include_stdlib = false
"--cflags" | "-cf" => extra_c_flags.push(argv[++i])
else => {
if argv[i][0] == '-' {
println("Unknown option: %s", argv[i])
Expand Down

0 comments on commit 7343af3

Please sign in to comment.