1 // SPDX-License-Identifier: MIT
3 * 'sparse' library helper routines.
5 * Copyright (C) 2003 Transmeta Corp.
6 * 2003-2004 Linus Torvalds
7 * 2017-2020 Luc Van Oostenryck
22 # define __GNUC_MINOR__ 95
23 # define __GNUC_PATCHLEVEL__ 0
34 int gcc_major
= __GNUC__
;
35 int gcc_minor
= __GNUC_MINOR__
;
36 int gcc_patchlevel
= __GNUC_PATCHLEVEL__
;
44 #define CMDLINE_INCLUDE 20
45 int cmdline_include_nr
= 0;
46 char *cmdline_include
[CMDLINE_INCLUDE
];
48 const char *base_filename
;
49 const char *diag_prefix
= "";
50 const char *gcc_base_dir
= GCC_BASE
;
51 const char *multiarch_dir
= MULTIARCH_TRIPLET
;
52 const char *outfile
= NULL
;
54 enum standard standard
= STANDARD_GNU89
;
56 int arch_big_endian
= ARCH_BIG_ENDIAN
;
57 int arch_cmodel
= CMODEL_UNKNOWN
;
58 int arch_fp_abi
= FP_ABI_NATIVE
;
59 int arch_m64
= ARCH_M64_DEFAULT
;
60 int arch_msize_long
= 0;
61 int arch_os
= OS_NATIVE
;
68 int dbg_postorder
= 0;
70 int dump_macro_defs
= 0;
71 int dump_macros_only
= 0;
73 unsigned long fdump_ir
;
75 unsigned int fmax_errors
= 100;
76 unsigned int fmax_warnings
= 100;
78 unsigned long long fmemcpy_max_count
= 100000;
79 unsigned long fpasses
= ~0UL;
83 int funsigned_bitfields
= 0;
84 int funsigned_char
= 0;
87 int Waddress_space
= 1;
89 int Wbitwise_pointer
= 0;
90 int Wcast_from_as
= 0;
92 int Wcast_truncate
= 1;
93 int Wconstant_suffix
= 0;
94 int Wconstexpr_not_const
= 0;
97 int Wdeclarationafterstatement
= -1;
98 int Wdefault_bitfield_sign
= 0;
99 int Wdesignated_init
= 1;
101 int Wenum_mismatch
= 1;
102 int Wexternal_function_has_definition
= 1;
103 int Wflexible_array_array
= 1;
104 int Wflexible_array_nested
= 0;
105 int Wflexible_array_sizeof
= 0;
106 int Wflexible_array_union
= 0;
107 int Wimplicit_int
= 1;
108 int Winit_cstring
= 0;
109 int Wint_to_pointer_cast
= 1;
110 int Wmemcpy_max_count
= 1;
111 int Wnewline_eof
= 1;
112 int Wnon_pointer_null
= 1;
113 int Wold_initializer
= 1;
114 int Wold_style_definition
= 1;
115 int Wone_bit_signed_bitfield
= 1;
116 int Woverride_init
= 1;
117 int Woverride_init_all
= 0;
118 int Woverride_init_whole_range
= 0;
119 int Wparen_string
= 0;
120 int Wpast_deep_designator
= 0;
122 int Wpointer_arith
= 0;
123 int Wpointer_to_int_cast
= 1;
124 int Wptr_subtraction_blows
= 0;
125 int Wreturn_void
= 0;
127 int Wshift_count_negative
= 1;
128 int Wshift_count_overflow
= 1;
129 int Wsizeof_bool
= 0;
130 int Wsparse_error
= FLAG_FORCE_OFF
;
131 int Wstrict_prototypes
= 1;
132 int Wtautological_compare
= 0;
133 int Wtransparent_union
= 0;
136 int Wuninitialized
= 1;
138 int Wuniversal_initializer
= 0;
139 int Wunknown_attribute
= 0;
142 ////////////////////////////////////////////////////////////////////////////////
143 // Helpers for option parsing
145 static const char *match_option(const char *arg
, const char *prefix
)
147 unsigned int n
= strlen(prefix
);
148 if (strncmp(arg
, prefix
, n
) == 0)
159 static int handle_subopt_val(const char *opt
, const char *arg
, const struct val_map
*map
, int *flag
)
164 die("missing argument for option '%s'", opt
);
165 for (;(name
= map
->name
); map
++) {
166 if (strcmp(name
, arg
) == 0 || strcmp(name
, "*") == 0) {
170 if (strcmp(name
, "?") == 0)
171 die("invalid argument '%s' in option '%s'", arg
, opt
);
182 static int apply_mask(unsigned long *val
, const char *str
, unsigned len
, const struct mask_map
*map
, int neg
)
186 for (;(name
= map
->name
); map
++) {
187 if (!strncmp(name
, str
, len
) && !name
[len
]) {
198 static int handle_suboption_mask(const char *arg
, const char *opt
, const struct mask_map
*map
, unsigned long *flag
)
201 apply_mask(flag
, "", 0, map
, 0);
207 unsigned int len
= strcspn(opt
, ",+");
211 if (!strncmp(opt
, "no-", 3)) {
216 if (apply_mask(flag
, opt
, len
, map
, neg
))
217 die("error: wrong option '%.*s' for \'%s\'", len
, opt
, arg
);
228 #define OPT_INVERSE 1
233 int (*fun
)(const char *arg
, const char *opt
, const struct flag
*, int options
);
238 static int handle_switches(const char *ori
, const char *opt
, const struct flag
*flags
)
240 const char *arg
= opt
;
243 // Prefixe "no-" mean to turn flag off.
244 if (strncmp(arg
, "no-", 3) == 0) {
249 for (; flags
->name
; flags
++) {
250 const char *opt
= match_option(arg
, flags
->name
);
259 options
|= OPT_INVERSE
;
260 if ((rc
= flags
->fun(ori
, opt
, flags
, options
)))
265 if (opt
[0] == '\0' && flags
->flag
) {
266 if (flags
->mask
& OPT_VAL
)
268 if (flags
->mask
& OPT_INVERSE
)
279 static char **handle_onoff_switch(char *arg
, char **next
, const struct flag flags
[])
285 // Prefixes "no" and "no-" mean to turn warning off.
286 if (p
[0] == 'n' && p
[1] == 'o') {
290 flag
= FLAG_FORCE_OFF
;
293 for (i
= 0; flags
[i
].name
; i
++) {
294 if (!strcmp(p
,flags
[i
].name
)) {
295 *flags
[i
].flag
= flag
;
304 static void handle_onoff_switch_finalize(const struct flag flags
[])
308 for (i
= 0; flags
[i
].name
; i
++) {
309 if (*flags
[i
].flag
== FLAG_FORCE_OFF
)
310 *flags
[i
].flag
= FLAG_OFF
;
314 static int handle_switch_setval(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
316 *(flag
->flag
) = flag
->mask
;
321 #define OPTNUM_ZERO_IS_INF 1
322 #define OPTNUM_UNLIMITED 2
324 #define OPT_NUMERIC(NAME, TYPE, FUNCTION) \
325 static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \
330 val = FUNCTION(opt, &end, 0); \
331 if (*end != '\0' || end == opt) { \
332 if ((flag & OPTNUM_UNLIMITED) && !strcmp(opt, "unlimited")) \
335 die("error: wrong argument to \'%s\'", arg); \
337 if ((flag & OPTNUM_ZERO_IS_INF) && val == 0) \
343 OPT_NUMERIC(ullong
, unsigned long long, strtoull
)
344 OPT_NUMERIC(uint
, unsigned int, strtoul
)
346 ////////////////////////////////////////////////////////////////////////////////
349 static char **handle_switch_a(char *arg
, char **next
)
351 if (!strcmp(arg
, "ansi"))
352 standard
= STANDARD_C89
;
357 static char **handle_switch_D(char *arg
, char **next
)
359 const char *name
= arg
+ 1;
360 const char *value
= "1";
365 die("argument to `-D' is missing");
380 add_pre_buffer("#define %s %s\n", name
, value
);
384 static char **handle_switch_d(char *arg
, char **next
)
386 char *arg_char
= arg
+ 1;
389 * -d<CHARS>, where <CHARS> is a sequence of characters, not preceded
390 * by a space. If you specify characters whose behaviour conflicts,
391 * the result is undefined.
395 case 'M': /* dump just the macro definitions */
396 dump_macros_only
= 1;
399 case 'D': /* like 'M', but also output pre-processed text */
401 dump_macros_only
= 0;
403 case 'N': /* like 'D', but only output macro names not bodies */
405 case 'I': /* like 'D', but also output #include directives */
407 case 'U': /* like 'D', but only output expanded macros */
415 static char **handle_switch_E(char *arg
, char **next
)
422 static int handle_ftabstop(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
428 die("error: missing argument to \"%s\"", arg
);
430 /* we silently ignore silly values */
431 val
= strtoul(opt
, &end
, 10);
432 if (*end
== '\0' && 1 <= val
&& val
<= 100)
438 static int handle_fpasses(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
444 if (options
& OPT_INVERSE
)
450 if (options
& OPT_INVERSE
)
452 if (!strcmp(opt
, "-enable")) {
456 if (!strcmp(opt
, "-disable")) {
460 if (!strcmp(opt
, "=last")) {
461 // clear everything above
469 static int handle_fdiagnostic_prefix(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
473 diag_prefix
= "sparse: ";
476 diag_prefix
= xasprintf("%s: ", opt
+1);
483 static int handle_fdump_ir(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
485 static const struct mask_map dump_ir_options
[] = {
486 { "", PASS_LINEARIZE
},
487 { "linearize", PASS_LINEARIZE
},
488 { "mem2reg", PASS_MEM2REG
},
489 { "final", PASS_FINAL
},
493 return handle_suboption_mask(arg
, opt
, dump_ir_options
, &fdump_ir
);
496 static int handle_fmemcpy_max_count(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
498 opt_ullong(arg
, opt
, &fmemcpy_max_count
, OPTNUM_ZERO_IS_INF
|OPTNUM_UNLIMITED
);
502 static int handle_fmax_errors(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
504 opt_uint(arg
, opt
, &fmax_errors
, OPTNUM_UNLIMITED
);
508 static int handle_fmax_warnings(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
510 opt_uint(arg
, opt
, &fmax_warnings
, OPTNUM_UNLIMITED
);
514 static struct flag fflags
[] = {
515 { "diagnostic-prefix", NULL
, handle_fdiagnostic_prefix
},
516 { "dump-ir", NULL
, handle_fdump_ir
},
517 { "freestanding", &fhosted
, NULL
, OPT_INVERSE
},
518 { "hosted", &fhosted
},
519 { "linearize", NULL
, handle_fpasses
, PASS_LINEARIZE
},
520 { "max-errors=", NULL
, handle_fmax_errors
},
521 { "max-warnings=", NULL
, handle_fmax_warnings
},
522 { "mem-report", &fmem_report
},
523 { "memcpy-max-count=", NULL
, handle_fmemcpy_max_count
},
524 { "tabstop=", NULL
, handle_ftabstop
},
525 { "mem2reg", NULL
, handle_fpasses
, PASS_MEM2REG
},
526 { "optim", NULL
, handle_fpasses
, PASS_OPTIM
},
527 { "pic", &fpic
, handle_switch_setval
, 1 },
528 { "PIC", &fpic
, handle_switch_setval
, 2 },
529 { "pie", &fpie
, handle_switch_setval
, 1 },
530 { "PIE", &fpie
, handle_switch_setval
, 2 },
531 { "signed-bitfields", &funsigned_bitfields
, NULL
, OPT_INVERSE
},
532 { "unsigned-bitfields", &funsigned_bitfields
, NULL
, },
533 { "signed-char", &funsigned_char
, NULL
, OPT_INVERSE
},
534 { "short-wchar", &fshort_wchar
},
535 { "unsigned-char", &funsigned_char
, NULL
, },
539 static char **handle_switch_f(char *arg
, char **next
)
541 if (handle_switches(arg
-1, arg
+1, fflags
))
547 static char **handle_switch_G(char *arg
, char **next
)
549 if (!strcmp(arg
, "G") && *next
)
550 return next
+ 1; // "-G 0"
552 return next
; // "-G0" or (bogus) terminal "-G"
555 static char **handle_base_dir(char *arg
, char **next
)
557 gcc_base_dir
= *++next
;
559 die("missing argument for -gcc-base-dir option");
563 static char **handle_switch_g(char *arg
, char **next
)
565 if (!strcmp(arg
, "gcc-base-dir"))
566 return handle_base_dir(arg
, next
);
571 static char **handle_switch_I(char *arg
, char **next
)
577 add_pre_buffer("#split_include\n");
580 case '\0': /* Plain "-I" */
583 die("missing argument for -I option");
586 add_pre_buffer("#add_include \"%s/\"\n", path
);
591 static void add_cmdline_include(char *filename
)
593 if (cmdline_include_nr
>= CMDLINE_INCLUDE
)
594 die("too many include files for %s\n", filename
);
595 cmdline_include
[cmdline_include_nr
++] = filename
;
598 static char **handle_switch_i(char *arg
, char **next
)
600 if (*next
&& !strcmp(arg
, "include"))
601 add_cmdline_include(*++next
);
602 else if (*next
&& !strcmp(arg
, "imacros"))
603 add_cmdline_include(*++next
);
604 else if (*next
&& !strcmp(arg
, "isystem")) {
605 char *path
= *++next
;
607 die("missing argument for -isystem option");
608 add_pre_buffer("#add_isystem \"%s/\"\n", path
);
609 } else if (*next
&& !strcmp(arg
, "idirafter")) {
610 char *path
= *++next
;
612 die("missing argument for -idirafter option");
613 add_pre_buffer("#add_dirafter \"%s/\"\n", path
);
618 static char **handle_switch_M(char *arg
, char **next
)
620 if (!strcmp(arg
, "MF") || !strcmp(arg
,"MQ") || !strcmp(arg
,"MT")) {
622 die("missing argument for -%s option", arg
);
628 static int handle_march(const char *opt
, const char *arg
, const struct flag
*flag
, int options
)
630 if (arch_target
->parse_march
)
631 arch_target
->parse_march(arg
);
635 static int handle_mcmodel(const char *opt
, const char *arg
, const struct flag
*flag
, int options
)
637 static const struct val_map cmodels
[] = {
638 { "kernel", CMODEL_KERNEL
},
639 { "large", CMODEL_LARGE
},
640 { "medany", CMODEL_MEDANY
},
641 { "medium", CMODEL_MEDIUM
},
642 { "medlow", CMODEL_MEDLOW
},
643 { "small", CMODEL_SMALL
},
644 { "tiny", CMODEL_TINY
},
647 return handle_subopt_val(opt
, arg
, cmodels
, flag
->flag
);
650 static int handle_mfloat_abi(const char *opt
, const char *arg
, const struct flag
*flag
, int options
) {
651 static const struct val_map fp_abis
[] = {
652 { "hard", FP_ABI_HARD
},
653 { "soft", FP_ABI_SOFT
},
654 { "softfp", FP_ABI_HYBRID
},
657 return handle_subopt_val(opt
, arg
, fp_abis
, flag
->flag
);
660 static char **handle_multiarch_dir(char *arg
, char **next
)
662 multiarch_dir
= *++next
;
664 die("missing argument for -multiarch-dir option");
668 static const struct flag mflags
[] = {
669 { "64", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP64
},
670 { "32", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP32
},
671 { "31", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP32
},
672 { "16", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP32
},
673 { "x32",&arch_m64
, NULL
, OPT_VAL
, ARCH_X32
},
674 { "size-llp64", &arch_m64
, NULL
, OPT_VAL
, ARCH_LLP64
},
675 { "size-long", &arch_msize_long
},
676 { "arch=", NULL
, handle_march
},
677 { "big-endian", &arch_big_endian
, NULL
},
678 { "little-endian", &arch_big_endian
, NULL
, OPT_INVERSE
},
679 { "cmodel", &arch_cmodel
, handle_mcmodel
},
680 { "float-abi", &arch_fp_abi
, handle_mfloat_abi
},
681 { "hard-float", &arch_fp_abi
, NULL
, OPT_VAL
, FP_ABI_HARD
},
682 { "soft-float", &arch_fp_abi
, NULL
, OPT_VAL
, FP_ABI_SOFT
},
686 static char **handle_switch_m(char *arg
, char **next
)
688 if (!strcmp(arg
, "multiarch-dir")) {
689 return handle_multiarch_dir(arg
, next
);
691 handle_switches(arg
-1, arg
+1, mflags
);
697 static char **handle_nostdinc(char *arg
, char **next
)
699 add_pre_buffer("#nostdinc\n");
703 static char **handle_switch_n(char *arg
, char **next
)
705 if (!strcmp(arg
, "nostdinc"))
706 return handle_nostdinc(arg
, next
);
711 static char **handle_switch_O(char *arg
, char **next
)
714 if (arg
[1] >= '0' && arg
[1] <= '9')
715 level
= arg
[1] - '0';
716 optimize_level
= level
;
717 optimize_size
= arg
[1] == 's';
721 static char **handle_switch_o(char *arg
, char **next
)
723 if (!strcmp(arg
, "o")) { // "-o foo"
725 die("argument to '-o' is missing");
733 static const struct flag pflags
[] = {
734 { "pedantic", &Wpedantic
, NULL
, OPT_VAL
, FLAG_ON
},
738 static char **handle_switch_p(char *arg
, char **next
)
740 handle_switches(arg
-1, arg
, pflags
);
744 static char **handle_switch_s(const char *arg
, char **next
)
746 if ((arg
= match_option(arg
, "std="))) {
747 if (!strcmp(arg
, "c89") ||
748 !strcmp(arg
, "iso9899:1990"))
749 standard
= STANDARD_C89
;
751 else if (!strcmp(arg
, "iso9899:199409"))
752 standard
= STANDARD_C94
;
754 else if (!strcmp(arg
, "c99") ||
755 !strcmp(arg
, "c9x") ||
756 !strcmp(arg
, "iso9899:1999") ||
757 !strcmp(arg
, "iso9899:199x"))
758 standard
= STANDARD_C99
;
760 else if (!strcmp(arg
, "gnu89"))
761 standard
= STANDARD_GNU89
;
763 else if (!strcmp(arg
, "gnu99") || !strcmp(arg
, "gnu9x"))
764 standard
= STANDARD_GNU99
;
766 else if (!strcmp(arg
, "c11") ||
767 !strcmp(arg
, "c1x") ||
768 !strcmp(arg
, "iso9899:2011"))
769 standard
= STANDARD_C11
;
771 else if (!strcmp(arg
, "gnu11"))
772 standard
= STANDARD_GNU11
;
774 else if (!strcmp(arg
, "c17") ||
775 !strcmp(arg
, "c18") ||
776 !strcmp(arg
, "iso9899:2017") ||
777 !strcmp(arg
, "iso9899:2018"))
778 standard
= STANDARD_C17
;
779 else if (!strcmp(arg
, "gnu17") ||
780 !strcmp(arg
, "gnu18"))
781 standard
= STANDARD_GNU17
;
784 die("Unsupported C dialect");
790 static char **handle_switch_U(char *arg
, char **next
)
792 const char *name
= arg
+ 1;
797 die("argument to `-U' is missing");
799 add_pre_buffer("#undef %s\n", name
);
803 static struct flag debugs
[] = {
804 { "compound", &dbg_compound
},
805 { "dead", &dbg_dead
},
806 { "domtree", &dbg_domtree
},
807 { "entry", &dbg_entry
},
809 { "postorder", &dbg_postorder
},
813 static char **handle_switch_v(char *arg
, char **next
)
815 char ** ret
= handle_onoff_switch(arg
, next
, debugs
);
822 } while (*++arg
== 'v');
826 static void handle_switch_v_finalize(void)
828 handle_onoff_switch_finalize(debugs
);
831 static const struct flag warnings
[] = {
832 { "address", &Waddress
},
833 { "address-space", &Waddress_space
},
834 { "bitwise", &Wbitwise
},
835 { "bitwise-pointer", &Wbitwise_pointer
},
836 { "cast-from-as", &Wcast_from_as
},
837 { "cast-to-as", &Wcast_to_as
},
838 { "cast-truncate", &Wcast_truncate
},
839 { "constant-suffix", &Wconstant_suffix
},
840 { "constexpr-not-const", &Wconstexpr_not_const
},
841 { "context", &Wcontext
},
843 { "declaration-after-statement", &Wdeclarationafterstatement
},
844 { "default-bitfield-sign", &Wdefault_bitfield_sign
},
845 { "designated-init", &Wdesignated_init
},
846 { "do-while", &Wdo_while
},
847 { "enum-mismatch", &Wenum_mismatch
},
848 { "external-function-has-definition", &Wexternal_function_has_definition
},
849 { "flexible-array-array", &Wflexible_array_array
},
850 { "flexible-array-nested", &Wflexible_array_nested
},
851 { "flexible-array-sizeof", &Wflexible_array_sizeof
},
852 { "flexible-array-union", &Wflexible_array_union
},
853 { "implicit-int", &Wimplicit_int
},
854 { "init-cstring", &Winit_cstring
},
855 { "int-to-pointer-cast", &Wint_to_pointer_cast
},
856 { "memcpy-max-count", &Wmemcpy_max_count
},
857 { "non-pointer-null", &Wnon_pointer_null
},
858 { "newline-eof", &Wnewline_eof
},
859 { "old-initializer", &Wold_initializer
},
860 { "old-style-definition", &Wold_style_definition
},
861 { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield
},
862 { "override-init", &Woverride_init
},
863 { "override-init-all", &Woverride_init_all
},
864 { "paren-string", &Wparen_string
},
865 { "past-deep-designator", &Wpast_deep_designator
},
866 { "pedantic", &Wpedantic
},
867 { "pointer-to-int-cast", &Wpointer_to_int_cast
},
868 { "ptr-subtraction-blows", &Wptr_subtraction_blows
},
869 { "return-void", &Wreturn_void
},
870 { "shadow", &Wshadow
},
871 { "shift-count-negative", &Wshift_count_negative
},
872 { "shift-count-overflow", &Wshift_count_overflow
},
873 { "sizeof-bool", &Wsizeof_bool
},
874 { "strict-prototypes", &Wstrict_prototypes
},
875 { "pointer-arith", &Wpointer_arith
},
876 { "sparse-error", &Wsparse_error
},
877 { "tautological-compare", &Wtautological_compare
},
878 { "transparent-union", &Wtransparent_union
},
879 { "typesign", &Wtypesign
},
880 { "undef", &Wundef
},
881 { "uninitialized", &Wuninitialized
},
882 { "union-cast", &Wunion_cast
},
883 { "universal-initializer", &Wuniversal_initializer
},
884 { "unknown-attribute", &Wunknown_attribute
},
889 static char **handle_switch_W(char *arg
, char **next
)
891 char ** ret
= handle_onoff_switch(arg
, next
, warnings
);
895 if (!strcmp(arg
, "Wsparse-all")) {
897 for (i
= 0; warnings
[i
].name
; i
++) {
898 if (*warnings
[i
].flag
!= FLAG_FORCE_OFF
)
899 *warnings
[i
].flag
= FLAG_ON
;
907 static void handle_switch_W_finalize(void)
909 handle_onoff_switch_finalize(warnings
);
911 /* default Wdeclarationafterstatement based on the C dialect */
912 if (-1 == Wdeclarationafterstatement
) {
916 Wdeclarationafterstatement
= 1;
919 Wdeclarationafterstatement
= 0;
925 static char **handle_switch_x(char *arg
, char **next
)
928 die("missing argument for -x option");
933 static char **handle_arch(char *arg
, char **next
)
938 die("missing argument for --arch option");
940 mach
= target_parse(arg
);
941 if (mach
!= MACH_UNKNOWN
)
947 static char **handle_param(char *arg
, char **next
)
951 /* For now just skip any '--param=*' or '--param *' */
954 } else if (isspace((unsigned char)*arg
) || *arg
== '=') {
959 die("missing argument for --param option");
964 static char **handle_os(char *arg
, char **next
)
967 die("missing argument for --os option");
974 static char **handle_version(char *arg
, char **next
)
976 printf("%s\n", sparse_version
);
982 char **(*fn
)(char *, char **);
983 unsigned int prefix
:1;
986 static char **handle_long_options(char *arg
, char **next
)
988 static struct switches cmd
[] = {
989 { "arch", handle_arch
, 1 },
990 { "os", handle_os
, 1 },
991 { "param", handle_param
, 1 },
992 { "version", handle_version
},
995 struct switches
*s
= cmd
;
998 int optlen
= strlen(s
->name
);
999 if (!strncmp(s
->name
, arg
, optlen
+ !s
->prefix
))
1000 return s
->fn(arg
+ optlen
, next
);
1006 char **handle_switch(char *arg
, char **next
)
1009 case 'a': return handle_switch_a(arg
, next
);
1010 case 'D': return handle_switch_D(arg
, next
);
1011 case 'd': return handle_switch_d(arg
, next
);
1012 case 'E': return handle_switch_E(arg
, next
);
1013 case 'f': return handle_switch_f(arg
, next
);
1014 case 'g': return handle_switch_g(arg
, next
);
1015 case 'G': return handle_switch_G(arg
, next
);
1016 case 'I': return handle_switch_I(arg
, next
);
1017 case 'i': return handle_switch_i(arg
, next
);
1018 case 'M': return handle_switch_M(arg
, next
);
1019 case 'm': return handle_switch_m(arg
, next
);
1020 case 'n': return handle_switch_n(arg
, next
);
1021 case 'o': return handle_switch_o(arg
, next
);
1022 case 'O': return handle_switch_O(arg
, next
);
1023 case 'p': return handle_switch_p(arg
, next
);
1024 case 's': return handle_switch_s(arg
, next
);
1025 case 'U': return handle_switch_U(arg
, next
);
1026 case 'v': return handle_switch_v(arg
, next
);
1027 case 'W': return handle_switch_W(arg
, next
);
1028 case 'x': return handle_switch_x(arg
, next
);
1029 case '-': return handle_long_options(arg
+ 1, next
);
1035 * Ignore unknown command line options:
1036 * they're probably gcc switches
1041 void handle_switch_finalize(void)
1043 handle_switch_v_finalize();
1044 handle_switch_W_finalize();