-
This commit is contained in:
@@ -134,20 +134,16 @@ fn (mut g Generator) gen_c(program []Stmt) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compile_with_clang(c_code string, output_name string, keep_c bool) {
|
fn compile_with_clang(c_code string, output_name string, keep_c bool) {
|
||||||
// 1. Write the C code to a temporary file
|
|
||||||
c_file := 'middle_c.c'
|
c_file := 'middle_c.c'
|
||||||
os.write_file(c_file, c_code) or {
|
os.write_file(c_file, c_code) or {
|
||||||
eprintln('Failed to write C file: $err')
|
eprintln('Failed to write C file: $err')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Construct the clang command
|
|
||||||
// We'll use -O2 for optimization and -o to specify the output binary
|
|
||||||
clang_cmd := 'clang ${c_file} -o ${output_name} -O2'
|
clang_cmd := 'clang ${c_file} -o ${output_name} -O2'
|
||||||
|
|
||||||
println('Executing: ${clang_cmd}')
|
println('Executing: ${clang_cmd}')
|
||||||
|
|
||||||
// 3. Run the command
|
|
||||||
result := os.execute(clang_cmd)
|
result := os.execute(clang_cmd)
|
||||||
|
|
||||||
if result.exit_code != 0 {
|
if result.exit_code != 0 {
|
||||||
@@ -155,7 +151,6 @@ fn compile_with_clang(c_code string, output_name string, keep_c bool) {
|
|||||||
eprintln(result.output)
|
eprintln(result.output)
|
||||||
} else {
|
} else {
|
||||||
println('Compilation successful! Binary created: $output_name')
|
println('Compilation successful! Binary created: $output_name')
|
||||||
// Optional: Remove the temporary C file
|
|
||||||
if !keep_c {
|
if !keep_c {
|
||||||
os.rm(c_file) or { }
|
os.rm(c_file) or { }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user