@@ -604,15 +604,17 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
604
604
}
605
605
} ,
606
606
"jit" => {
607
- let mut in_file: Option < & str > = None ;
608
- let mut linked: Vec < & str > = vec ! [ ] ;
607
+ let mut in_file: Option < String > = None ;
608
+ let mut linked: Vec < String > = vec ! [ ] ;
609
609
let mut link_dirs: Vec < String > = vec ! [ ] ;
610
610
let mut continue_if_err = false ;
611
611
let mut no_default_link = false ;
612
- let mut headers: Vec < & str > = vec ! [ ] ;
613
- let mut profile: Option < & str > = None ;
612
+ let mut headers: Vec < String > = vec ! [ ] ;
613
+ let mut profile: Option < String > = None ;
614
+ let mut args = Vec :: < String > :: new ( ) ;
614
615
{
615
- let mut it = args. iter ( ) . skip ( 2 ) . skip_while ( |x| x. is_empty ( ) ) ;
616
+ let mut it = std:: env:: args ( ) . skip_while ( |x| x. is_empty ( ) ) ;
617
+ args. push ( it. by_ref ( ) . take ( 2 ) . map ( |x| format ! ( "{x} " ) ) . collect :: < String > ( ) ) ;
616
618
while let Some ( arg) = it. next ( ) {
617
619
if arg. is_empty ( ) { continue ; }
618
620
if arg. as_bytes ( ) [ 0 ] == b'-' {
@@ -621,10 +623,11 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
621
623
error ! ( "respecification of input file" ) ;
622
624
exit ( 1 )
623
625
}
624
- in_file = Some ( "-" ) ;
626
+ in_file = Some ( "-" . to_string ( ) ) ;
625
627
}
626
628
else if arg. as_bytes ( ) [ 1 ] == b'-' {
627
629
match & arg[ 2 ..] {
630
+ "" => args. extend ( it. by_ref ( ) ) ,
628
631
"continue" => {
629
632
if continue_if_err {
630
633
warning ! ( "reuse of --continue flag" ) ;
@@ -651,7 +654,7 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
651
654
warning ! ( "respecification of optimization profile" ) ;
652
655
}
653
656
if let Some ( x) = it. next ( ) {
654
- profile = Some ( x. as_str ( ) ) ;
657
+ profile = Some ( x) ;
655
658
}
656
659
else {
657
660
error ! ( "expected profile after -p flag" ) ;
@@ -666,7 +669,7 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
666
669
} ,
667
670
'l' => {
668
671
if let Some ( x) = it. next ( ) {
669
- linked. push ( x. as_str ( ) ) ;
672
+ linked. push ( x) ;
670
673
}
671
674
else {
672
675
error ! ( "expected library after -l flag" ) ;
@@ -675,7 +678,7 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
675
678
} ,
676
679
'L' => {
677
680
if let Some ( x) = it. next ( ) {
678
- link_dirs. push ( x. clone ( ) ) ;
681
+ link_dirs. push ( x) ;
679
682
}
680
683
else {
681
684
error ! ( "expected directory after -L flag" ) ;
@@ -684,7 +687,7 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
684
687
} ,
685
688
'h' => {
686
689
if let Some ( x) = it. next ( ) {
687
- headers. push ( x. as_str ( ) ) ;
690
+ headers. push ( x) ;
688
691
}
689
692
else {
690
693
error ! ( "expected header file after -h flag" ) ;
@@ -704,7 +707,7 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
704
707
error ! ( "respecification of input file" ) ;
705
708
exit ( 1 )
706
709
}
707
- in_file = Some ( arg. as_str ( ) ) ;
710
+ in_file = Some ( arg) ;
708
711
}
709
712
}
710
713
}
@@ -713,11 +716,16 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
713
716
if let Ok ( home) = std:: env:: var ( "HOME" ) { link_dirs. extend_from_slice ( & [ format ! ( "{home}/.cobalt/packages" ) , format ! ( "{home}/.local/lib/cobalt" ) , "/usr/local/lib/cobalt/packages" . to_string ( ) , "/usr/lib/cobalt/packages" . to_string ( ) , "/lib/cobalt/packages" . to_string ( ) , "/usr/local/lib" . to_string ( ) , "/usr/lib" . to_string ( ) , "/lib" . to_string ( ) ] ) ; }
714
717
else { link_dirs. extend ( [ "/usr/local/lib/cobalt/packages" , "/usr/lib/cobalt/packages" , "/lib/cobalt/packages" , "/usr/local/lib" , "/usr/lib" , "/lib" ] . into_iter ( ) . map ( String :: from) ) ; }
715
718
}
716
- let ( in_file, code) = if let Some ( f) = in_file { ( f, std:: fs:: read_to_string ( f) ?) }
717
- else {
718
- let mut s = String :: new ( ) ;
719
- std:: io:: stdin ( ) . read_to_string ( & mut s) ?;
720
- ( "<stdin>" , s)
719
+ let ( in_file, code) = match in_file. as_deref ( ) . unwrap_or ( "-" ) {
720
+ "-" => {
721
+ let mut s = String :: new ( ) ;
722
+ std:: io:: stdin ( ) . read_to_string ( & mut s) ?;
723
+ ( "<stdin>" , s)
724
+ } ,
725
+ f => {
726
+ args[ 0 ] . push_str ( f) ;
727
+ ( f, std:: fs:: read_to_string ( f) ?)
728
+ }
721
729
} ;
722
730
let ink_ctx = inkwell:: context:: Context :: create ( ) ;
723
731
let mut ctx = cobalt:: context:: CompCtx :: new ( & ink_ctx, in_file) ;
@@ -762,7 +770,7 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
762
770
}
763
771
if fail || overall_fail { exit ( 101 ) }
764
772
let pm = inkwell:: passes:: PassManager :: create ( ( ) ) ;
765
- opt:: load_profile ( profile, & pm) ;
773
+ opt:: load_profile ( profile. as_deref ( ) , & pm) ;
766
774
pm. run_on ( & ctx. module ) ;
767
775
let ee = ctx. module . create_jit_execution_engine ( inkwell:: OptimizationLevel :: None ) . expect ( "Couldn't create execution engine!" ) ;
768
776
for ( lib, _) in libs {
@@ -781,9 +789,8 @@ fn driver() -> Result<(), Box<dyn std::error::Error>> {
781
789
exit ( 255 )
782
790
}
783
791
} ;
784
- let this = format ! ( "{} {in_file}" , std:: env:: args( ) . next( ) . unwrap_or( "<no exe?>" . to_string( ) ) ) ;
785
792
ee. run_static_constructors ( ) ;
786
- let ec = ee. run_function_as_main ( main_fn, & [ & this ] ) ;
793
+ let ec = ee. run_function_as_main ( main_fn, & args . iter ( ) . map ( String :: as_str ) . collect :: < Vec < _ > > ( ) ) ;
787
794
ee. run_static_destructors ( ) ;
788
795
exit ( ec) ;
789
796
}
0 commit comments