-
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) {
|
||||
// 1. Write the C code to a temporary file
|
||||
c_file := 'middle_c.c'
|
||||
os.write_file(c_file, c_code) or {
|
||||
eprintln('Failed to write C file: $err')
|
||||
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'
|
||||
|
||||
println('Executing: ${clang_cmd}')
|
||||
|
||||
// 3. Run the command
|
||||
result := os.execute(clang_cmd)
|
||||
|
||||
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)
|
||||
} else {
|
||||
println('Compilation successful! Binary created: $output_name')
|
||||
// Optional: Remove the temporary C file
|
||||
if !keep_c {
|
||||
os.rm(c_file) or { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user