@@ -5,6 +5,7 @@ import front.token;
5
5
import middle. trans ;
6
6
import middle. resolve ;
7
7
import middle. typeck ;
8
+ import util. common ;
8
9
9
10
import std. option ;
10
11
import std. option . some ;
@@ -13,18 +14,18 @@ import std._str;
13
14
import std. _vec ;
14
15
15
16
impure fn compile_input ( session. session sess, str input, str output) {
16
- auto p = parser. new_parser ( sess, 0 , input) ;
17
- auto crate = parser. parse_crate ( p) ;
18
- crate = resolve. resolve_crate ( sess, crate ) ;
19
- crate = typeck. check_crate ( sess, crate ) ;
20
- trans. trans_crate ( sess, crate , output) ;
17
+ auto p = parser. new_parser ( sess, 0 , input) ;
18
+ auto crate = parser. parse_crate ( p) ;
19
+ crate = resolve. resolve_crate ( sess, crate ) ;
20
+ crate = typeck. check_crate ( sess, crate ) ;
21
+ trans. trans_crate ( sess, crate , output) ;
21
22
}
22
23
23
24
fn warn_wrong_compiler ( ) {
24
- log "This is the rust 'self-hosted' compiler." ;
25
- log "The one written in rust." ;
26
- log "It does nothing yet, it's a placeholder." ;
27
- log "You want rustboot, the compiler next door." ;
25
+ log "This is the rust 'self-hosted' compiler." ;
26
+ log "The one written in rust." ;
27
+ log "It does nothing yet, it's a placeholder." ;
28
+ log "You want rustboot, the compiler next door." ;
28
29
}
29
30
30
31
fn usage ( session . session sess, str argv0 ) {
@@ -38,81 +39,95 @@ fn usage(session.session sess, str argv0) {
38
39
log "" ;
39
40
}
40
41
42
+ fn get_os ( ) -> session . os {
43
+ auto s = std. os . target_os ( ) ;
44
+ if ( _str. eq ( s, "win32" ) ) { ret session. os_win32 ; }
45
+ if ( _str. eq ( s, "macos" ) ) { ret session. os_macos ; }
46
+ if ( _str. eq ( s, "linux" ) ) { ret session. os_linux ; }
47
+ }
48
+
41
49
impure fn main ( vec[ str] args) {
42
50
43
- auto sess = session. session ( ) ;
44
- let option. t[ str] input_file = none[ str] ;
45
- let option. t[ str] output_file = none[ str] ;
46
- let bool do_warn = true ;
51
+ // FIXME: don't hard-wire this.
52
+ auto target_cfg = rec ( os = get_os ( ) ,
53
+ arch = session. arch_x86 ,
54
+ int_type = common. ty_i32 ,
55
+ uint_type = common. ty_u32 ,
56
+ float_type = common. ty_f64 ) ;
57
+
58
+ auto sess = session. session ( target_cfg) ;
59
+ let option. t[ str] input_file = none[ str] ;
60
+ let option. t[ str] output_file = none[ str] ;
61
+ let bool do_warn = true ;
47
62
48
- auto i = 1 u;
49
- auto len = _vec. len [ str] ( args) ;
63
+ auto i = 1 u;
64
+ auto len = _vec. len [ str] ( args) ;
50
65
51
- // FIXME: a getopt module would be nice.
52
- while ( i < len) {
53
- auto arg = args. ( i) ;
54
- if ( _str. byte_len ( arg) > 0 u && arg. ( 0 ) == '-' as u8 ) {
55
- if ( _str. eq ( arg, "-nowarn" ) ) {
56
- do_warn = false ;
57
- } else {
58
- // FIXME: rust could use an elif construct.
59
- if ( _str. eq ( arg, "-o" ) ) {
60
- if ( i+1 u < len) {
61
- output_file = some ( args. ( i +1 u) ) ;
62
- i += 1 u;
63
- } else {
64
- usage ( sess, args. ( 0 ) ) ;
65
- sess. err ( "-o requires an argument" ) ;
66
- }
67
- } else {
68
- if ( _str. eq ( arg, "-h" ) ) {
69
- usage ( sess, args. ( 0 ) ) ;
70
- } else {
71
- usage ( sess, args. ( 0 ) ) ;
72
- sess. err ( "unrecognized option: " + arg) ;
73
- }
74
- }
75
- }
76
- } else {
77
- alt ( input_file) {
78
- case ( some[ str] ( _) ) {
79
- usage ( sess, args. ( 0 ) ) ;
80
- sess. err ( "multiple inputs provided" ) ;
81
- }
82
- case ( none[ str] ) {
83
- input_file = some[ str] ( arg) ;
84
- }
85
- }
86
- // FIXME: dummy node to work around typestate mis-wiring bug.
87
- i = i;
88
- }
89
- i += 1 u;
90
- }
66
+ // FIXME: a getopt module would be nice.
67
+ while ( i < len) {
68
+ auto arg = args. ( i) ;
69
+ if ( _str. byte_len ( arg) > 0 u && arg. ( 0 ) == '-' as u8 ) {
70
+ if ( _str. eq ( arg, "-nowarn" ) ) {
71
+ do_warn = false ;
72
+ } else {
73
+ // FIXME: rust could use an elif construct.
74
+ if ( _str. eq ( arg, "-o" ) ) {
75
+ if ( i+1 u < len) {
76
+ output_file = some ( args. ( i +1 u) ) ;
77
+ i += 1 u;
78
+ } else {
79
+ usage ( sess, args. ( 0 ) ) ;
80
+ sess. err ( "-o requires an argument" ) ;
81
+ }
82
+ } else {
83
+ if ( _str. eq ( arg, "-h" ) ) {
84
+ usage ( sess, args. ( 0 ) ) ;
85
+ } else {
86
+ usage ( sess, args. ( 0 ) ) ;
87
+ sess. err ( "unrecognized option: " + arg) ;
88
+ }
89
+ }
90
+ }
91
+ } else {
92
+ alt ( input_file) {
93
+ case ( some[ str] ( _) ) {
94
+ usage ( sess, args. ( 0 ) ) ;
95
+ sess. err ( "multiple inputs provided" ) ;
96
+ }
97
+ case ( none[ str] ) {
98
+ input_file = some[ str] ( arg) ;
99
+ }
100
+ }
101
+ // FIXME: dummy node to work around typestate mis-wiring bug.
102
+ i = i;
103
+ }
104
+ i += 1 u;
105
+ }
91
106
92
- if ( do_warn) {
93
- warn_wrong_compiler ( ) ;
94
- }
107
+ if ( do_warn) {
108
+ warn_wrong_compiler ( ) ;
109
+ }
95
110
96
- alt ( input_file) {
97
- case ( none[ str] ) {
98
- usage ( sess, args. ( 0 ) ) ;
99
- sess. err ( "no input filename" ) ;
100
- }
101
- case ( some[ str] ( ?ifile) ) {
102
- alt ( output_file) {
103
- case ( none[ str] ) {
104
- let vec[ str] parts = _str. split ( ifile, '.' as u8 ) ;
105
- parts = _vec. pop [ str] ( parts) ;
106
- parts += ".bc" ;
107
- auto ofile = _str. concat ( parts) ;
108
- compile_input ( sess, ifile, ofile) ;
109
- }
110
- case ( some[ str] ( ?ofile) ) {
111
- compile_input ( sess, ifile, ofile) ;
112
- }
113
- }
114
- }
115
- }
111
+ alt ( input_file) {
112
+ case ( none[ str] ) {
113
+ usage ( sess, args. ( 0 ) ) ;
114
+ sess. err ( "no input filename" ) ;
115
+ }
116
+ case ( some[ str] ( ?ifile) ) {
117
+ alt ( output_file) {
118
+ case ( none[ str] ) {
119
+ let vec[ str] parts = _str. split ( ifile, '.' as u8 ) ;
120
+ parts = _vec. pop [ str] ( parts) ;
121
+ parts += ".bc" ;
122
+ auto ofile = _str. concat ( parts) ;
123
+ compile_input ( sess, ifile, ofile) ;
124
+ }
125
+ case ( some[ str] ( ?ofile) ) {
126
+ compile_input ( sess, ifile, ofile) ;
127
+ }
128
+ }
129
+ }
130
+ }
116
131
}
117
132
118
133
0 commit comments