File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ macro_rules! init_compiler {
110
110
( $file_path: expr) => { {
111
111
let ( program, file_name) = parse_program( $file_path) ;
112
112
let context = Compiler :: new_master_context( ) ;
113
- let mut compiler = Compiler :: new( context, program, $file_path, file_name) ;
113
+ let compiler = Compiler :: new( context, program, $file_path, file_name) ;
114
114
115
115
#[ cfg( debug_assertions) ]
116
116
compiler. set_debug_info( true ) ;
Original file line number Diff line number Diff line change 1
1
use crate :: Compiler ;
2
2
use gccjit_sys:: * ;
3
- use std:: { ffi:: CString , process:: exit} ;
3
+ use std:: {
4
+ ffi:: CString ,
5
+ fs:: { self , File } ,
6
+ process:: exit,
7
+ } ;
4
8
use utils:: compiler_error;
5
9
6
10
impl Compiler {
@@ -46,7 +50,7 @@ impl Compiler {
46
50
)
47
51
} ;
48
52
}
49
-
53
+
50
54
pub fn make_dynamic_library ( & self , file_path : String ) {
51
55
unsafe {
52
56
let file_path = CString :: new ( file_path) . unwrap ( ) ;
@@ -58,14 +62,24 @@ impl Compiler {
58
62
} ;
59
63
}
60
64
65
+ pub fn create_dump_file ( & self , file_path : String ) {
66
+ if !fs:: exists ( file_path. clone ( ) ) . unwrap ( ) {
67
+ if let Err ( err) = File :: create ( file_path. clone ( ) ) {
68
+ compiler_error ! ( format!( "Failed to dump source code at '{}': {}" , file_path, err) )
69
+ }
70
+ }
71
+ }
72
+
61
73
pub fn make_dump_ir ( & self , file_path : String ) {
74
+ self . create_dump_file ( file_path. clone ( ) ) ;
62
75
unsafe {
63
76
let file_path = CString :: new ( file_path) . unwrap ( ) ;
64
77
gcc_jit_context_dump_to_file ( self . context , file_path. as_ptr ( ) , self . cbool ( true ) )
65
78
} ;
66
79
}
67
-
80
+
68
81
pub fn make_dump_asm ( & self , file_path : String ) {
82
+ self . create_dump_file ( file_path. clone ( ) ) ;
69
83
unsafe {
70
84
let file_path = CString :: new ( file_path) . unwrap ( ) ;
71
85
gcc_jit_context_compile_to_file (
Original file line number Diff line number Diff line change 1
- import std::math;
2
1
import std::io;
3
2
3
+ fn sqrt(value: double): double {
4
+ return value;
5
+ }
6
+
4
7
pub fn main() {
5
8
std::io::printf("Hello World\n");
6
9
You can’t perform that action at this time.
0 commit comments