@@ -3,14 +3,7 @@ use encoding_rs::Encoding;
3
3
use std:: { ffi:: OsStr , path:: Path } ;
4
4
use structopt:: { clap:: ArgGroup , StructOpt } ;
5
5
6
- #[ derive( PartialEq , Debug ) ]
7
- pub enum FormatOption {
8
- Static ,
9
- PIC ,
10
- Shared ,
11
- Bitcode ,
12
- IR ,
13
- }
6
+ use crate :: FormatOption ;
14
7
15
8
// => Set the default output format here:
16
9
const DEFAULT_FORMAT : FormatOption = FormatOption :: Static ;
@@ -56,6 +49,13 @@ pub struct CompileParameters {
56
49
#[ structopt( long = "static" , group = "format" , help = "Emit an object as output" ) ]
57
50
pub output_obj_code : bool ,
58
51
52
+ #[ structopt(
53
+ long = "relocatable" ,
54
+ group = "format" ,
55
+ help = "Emit an object as output"
56
+ ) ]
57
+ pub output_reloc_code : bool ,
58
+
59
59
#[ structopt(
60
60
long = "bc" ,
61
61
group = "format" ,
@@ -126,6 +126,8 @@ impl CompileParameters {
126
126
Some ( FormatOption :: Shared )
127
127
} else if self . output_obj_code {
128
128
Some ( FormatOption :: Static )
129
+ } else if self . output_reloc_code {
130
+ Some ( FormatOption :: Relocatable )
129
131
} else {
130
132
None
131
133
}
@@ -146,6 +148,7 @@ impl CompileParameters {
146
148
} else {
147
149
let ending = match out_format {
148
150
FormatOption :: Bitcode => ".bc" ,
151
+ FormatOption :: Relocatable => ".o" ,
149
152
FormatOption :: Static if self . skip_linking => ".o" ,
150
153
FormatOption :: Static => "" ,
151
154
FormatOption :: Shared | FormatOption :: PIC => ".so" ,
@@ -164,7 +167,8 @@ impl CompileParameters {
164
167
165
168
#[ cfg( test) ]
166
169
mod cli_tests {
167
- use super :: { CompileParameters , FormatOption , ParameterError } ;
170
+ use super :: { CompileParameters , ParameterError } ;
171
+ use crate :: FormatOption ;
168
172
use pretty_assertions:: assert_eq;
169
173
use structopt:: clap:: ErrorKind ;
170
174
@@ -206,6 +210,10 @@ mod cli_tests {
206
210
vec_of_strings ! [ "input.st" , "--ir" , "--shared" , "--pic" , "--bc" ] ,
207
211
ErrorKind :: ArgumentConflict ,
208
212
) ;
213
+ expect_argument_error (
214
+ vec_of_strings ! [ "input.st" , "--ir" , "--relocatable" ] ,
215
+ ErrorKind :: ArgumentConflict ,
216
+ ) ;
209
217
}
210
218
211
219
#[ test]
@@ -336,41 +344,56 @@ mod cli_tests {
336
344
assert_eq ! ( parameters. output_obj_code, false ) ;
337
345
assert_eq ! ( parameters. output_pic_obj, false ) ;
338
346
assert_eq ! ( parameters. output_shared_obj, false ) ;
347
+ assert_eq ! ( parameters. output_reloc_code, false ) ;
339
348
340
349
let parameters = CompileParameters :: parse ( vec_of_strings ! ( "input.st" , "--bc" ) ) . unwrap ( ) ;
341
350
assert_eq ! ( parameters. output_ir, false ) ;
342
351
assert_eq ! ( parameters. output_bit_code, true ) ;
343
352
assert_eq ! ( parameters. output_obj_code, false ) ;
344
353
assert_eq ! ( parameters. output_pic_obj, false ) ;
345
354
assert_eq ! ( parameters. output_shared_obj, false ) ;
355
+ assert_eq ! ( parameters. output_reloc_code, false ) ;
346
356
347
357
let parameters = CompileParameters :: parse ( vec_of_strings ! ( "input.st" , "--static" ) ) . unwrap ( ) ;
348
358
assert_eq ! ( parameters. output_ir, false ) ;
349
359
assert_eq ! ( parameters. output_bit_code, false ) ;
350
360
assert_eq ! ( parameters. output_obj_code, true ) ;
351
361
assert_eq ! ( parameters. output_pic_obj, false ) ;
352
362
assert_eq ! ( parameters. output_shared_obj, false ) ;
363
+ assert_eq ! ( parameters. output_reloc_code, false ) ;
353
364
354
365
let parameters = CompileParameters :: parse ( vec_of_strings ! ( "input.st" , "--pic" ) ) . unwrap ( ) ;
355
366
assert_eq ! ( parameters. output_ir, false ) ;
356
367
assert_eq ! ( parameters. output_bit_code, false ) ;
357
368
assert_eq ! ( parameters. output_obj_code, false ) ;
358
369
assert_eq ! ( parameters. output_pic_obj, true ) ;
359
370
assert_eq ! ( parameters. output_shared_obj, false ) ;
371
+ assert_eq ! ( parameters. output_reloc_code, false ) ;
360
372
361
373
let parameters = CompileParameters :: parse ( vec_of_strings ! ( "input.st" , "--shared" ) ) . unwrap ( ) ;
362
374
assert_eq ! ( parameters. output_ir, false ) ;
363
375
assert_eq ! ( parameters. output_bit_code, false ) ;
364
376
assert_eq ! ( parameters. output_obj_code, false ) ;
365
377
assert_eq ! ( parameters. output_pic_obj, false ) ;
366
378
assert_eq ! ( parameters. output_shared_obj, true ) ;
379
+ assert_eq ! ( parameters. output_reloc_code, false ) ;
380
+
381
+ let parameters =
382
+ CompileParameters :: parse ( vec_of_strings ! ( "input.st" , "--relocatable" ) ) . unwrap ( ) ;
383
+ assert_eq ! ( parameters. output_ir, false ) ;
384
+ assert_eq ! ( parameters. output_bit_code, false ) ;
385
+ assert_eq ! ( parameters. output_obj_code, false ) ;
386
+ assert_eq ! ( parameters. output_pic_obj, false ) ;
387
+ assert_eq ! ( parameters. output_shared_obj, false ) ;
388
+ assert_eq ! ( parameters. output_reloc_code, true ) ;
367
389
368
390
let parameters = CompileParameters :: parse ( vec_of_strings ! ( "input.st" ) ) . unwrap ( ) ;
369
391
assert_eq ! ( parameters. output_ir, false ) ;
370
392
assert_eq ! ( parameters. output_bit_code, false ) ;
371
393
assert_eq ! ( parameters. output_obj_code, false ) ;
372
394
assert_eq ! ( parameters. output_pic_obj, false ) ;
373
395
assert_eq ! ( parameters. output_shared_obj, false ) ;
396
+ assert_eq ! ( parameters. output_reloc_code, false ) ;
374
397
}
375
398
376
399
#[ test]
0 commit comments