Studying note of GCC-3.4.6 source (23)

3.3.3. Handling other options

Now everything is ready, it’s time to handle options other than –O, the optimization option.

 

decode_options (continue)

 

618    handle_options (argc, argv, lang_mask);

619 

620    if (flag_pie)

621      flag_pic = flag_pie;

622    if (flag_pic && ! flag_pie)

623      flag_shlib = 1;

624 

625    if (flag_no_inline == 2)

626      flag_no_inline = 0;

627    else

628      flag_really_no_inline = flag_no_inline;

629 

630    /* Set flag_no_inline before the post_options () hook. The C front

631      ends use it to determine tree inlining defaults. FIXME: such

632      code should be lang-independent when all front ends use tree

633      inlining, in which case it, and this condition, should be moved

634      to the top of process_options() instead. */

635    if (optimize == 0)

636    {

637      /* Inlining does not work if not optimizing,

638        so force it not to be done. */

639      flag_no_inline = 1;

640      warn_inline = 0;

641 

642      /* The c_decode_option function and decode_option hook set

643        this to `2' if -Wall is used, so we can avoid giving out

644        lots of errors for people who don't realize what -Wall does. */

645      if (warn_uninitialized == 1)

646        warning ("-Wuninitialized is not supported without -O");

647    }

648 

649    if (flag_really_no_inline == 2)

650      flag_really_no_inline = flag_no_inline;

651  }

 

After handling options at line 618, several variables are synchronized accordingly.

flag_pie, nonzero if we are compiling position independent code (pic) for executable. The value is 1 if we are doing "small" pic; value is 2 if we're doing "large" pic.

flag_pic, nonzero if we are compiling pure (sharable) code. Value is 1 if we are doing "small" pic; value is 2 if we're doing "large" pic.

flag_shlib, nonzero if we are compiling code for a shared library, zero for executable.

flag_no_inline (-fno-inline) if nonzero, causes the compiler to ignore the inline keyword.

flag_really_no_inline, if nonzero, means that we don't want inlining by virtue of -fno-inline, not just because the tree inliner turned us off.

Notice that, at line 618 above, lang_mask gets its value from c_common_init_options, it is one of enum value of CL_C, CL_ObjC, CL_CXX and CL_ObjCXX.

 

439  static void

440  handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)              in opts.c

441  {

442    unsigned int n, i;

443 

444    for (i = 1; i < argc; i += n)

445    {

446      const char *opt = argv[i];

447 

448      /* Interpret "-" or a non-switch as a file name.  */

449      if (opt[0] != '-' || opt[1] == '/0')

450      {

451        if (main_input_filename == NULL)

452         main_input_filename = opt;

453        add_input_filename (opt);

454        n = 1;

455        continue;

456      }

457 

458      n = handle_option (argv + i, lang_mask);

459 

460      if (!n)

461      {

462        n = 1;

463        error ("unrecognized command line option /"%s/"", opt);

464      }

465    }

466  }

 

In the function, see handle_option at line 448, it parses the command line and returns the number of switches consumed. Then in command line, option of “-“ indicates getting input from standard input (console in common), and options don’t begin with “-“ are considered as normal input files. See that input files recognition is done before handle_option, so we can wtire command line: g++ test –o test.c as well as: g++ -o test.c test.

 

327  static unsigned int

328  handle_option (const char **argv, unsigned int lang_mask)                                    in opts.c

329  {

330    size_t opt_index;

331    const char *opt, *arg = 0;

332    char *dup = 0;

333    int value = 1;

334    unsigned int result = 0;

335    const struct cl_option *option;

336 

337    opt = argv[0];

338 

339    /* Drop the "no-" from negative switches.  */

340    if ((opt[1] == 'W' || opt[1] == 'f')

341        && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')

342    {

343      size_t len = strlen (opt) - 3;

344 

345      dup = xmalloc (len + 1);

346      dup[0] = '-';

347      dup[1] = opt[1];

348      memcpy (dup + 2, opt + 5, len - 2 + 1);

349      opt = dup;

350      value = 0;

351    }

352 

353    opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);

354    if (opt_index == cl_options_count)

355      goto done;

356 

357    option = &cl_options[opt_index];

358 

359    /* Reject negative form of switches that don't take negatives as

360      unrecognized.  */

361    if (!value && (option->flags & CL_REJECT_NEGATIVE))

362      goto done;

 

From line 340 ~ 351, removes “no-“ from –[Wf]no-* and sets value to 0 to indicate negative switches. At line 357, cl_options is of type cl_option as following, which contains C/C++ family language related options.

 

27    struct cl_option                                                                                          in opts.h

28    {

29      const char *opt_text;

30      const char *help;

31      unsigned short back_chain;

32      unsigned char opt_len;

33      unsigned int flags;

34    };

 

At line 353, find_opt uses this array to find out the index within it of the option. Remember that lang_mask returned from c_common_init_options indicates the language the options applied. Thus find_opt also will check if the option is usable by this specified language, but even the options unmatches the language, the function still returns the index of it.

 

你可能感兴趣的:(Studying note of GCC-3.4.6 source (23))