GCC Wikia
(細々と修正)
 
ココサブ (トーク | 投稿記録)
25行目: 25行目:
 
987 [[timevar_push]] ([[TV_PARSE]]);
 
987 [[timevar_push]] ([[TV_PARSE]]);
 
988
 
988
  +
</code>
  +
*C言語であれば[[c_common_parse_file]]が呼ばれる
  +
<code>
 
989 /* Call the parser, which parses the entire file (calling
 
989 /* Call the parser, which parses the entire file (calling
 
990 rest_of_compilation for each function). */
 
990 rest_of_compilation for each function). */

2007年8月31日 (金) 11:01時点における版

このページを編集する際は,編集に関する方針に従ってください.

概要

  • gcc-4.1.0/gcc/toplev.cにて定義
  • コンパイル単位のファイル全体をコンパイル.アセンブリとデバッグ情報が含まれたファイルを出力.
975 /* Compile an entire translation unit.  Write a file of assembly
976    output and various debugging dumps.  */

ちょっと実装を眺めればわかりますが,struct lang_hooks という構造体に関数ポインタが格納されていて,オブジェクト指向におけるポリモーフィズムのようなことが行われています (面白ポイント).

(ターゲットとする言語や,特定の状況に応じて呼び出される (フックされている) 関数が差し替えられる.)

実装

978 static void
979 compile_file (void)
980 {
981   /* Initialize yet another pass.  */
982 
983   init_cgraph ();
984   init_final (main_input_filename);
985   coverage_init (aux_base_name);
986 
987   timevar_push (TV_PARSE);
988 

989   /* Call the parser, which parses the entire file (calling
990      rest_of_compilation for each function).  */
991   lang_hooks.parse_file (set_yydebug);
992 
993   /* In case there were missing block closers,
994      get us back to the global binding level.  */
995   lang_hooks.clear_binding_stack ();
996 
997   /* Compilation is now finished except for writing
998      what's left of the symbol table output.  */
999   timevar_pop (TV_PARSE);
1000 
1001   if (flag_syntax_only)
1002     return;
1003 
1004   lang_hooks.decls.final_write_globals ();
1005   cgraph_varpool_assemble_pending_decls ();
1006   finish_aliases_2 ();
1007 
1008   /* This must occur after the loop to output deferred functions.
1009      Else the coverage initializer would not be emitted if all the
1010      functions in this compilation unit were deferred.  */
1011   coverage_finish ();
1012

  • gcc-4.1.0 からの新機能.バッファオーバーフローを防ぐための,配列の境界チェックなどを行うコンパイルオプション -fmudflap が有効になっていた場合.
    • (ランタイムのリンク -lmudflap オプションも,ターゲットファイル名の後に必要.すなわち,$ gcc -fmudflap foo.c -lmudflap)
    • (ちなみに,mudflap とは,自転車などのタイヤについている「泥除け」とかのことらしい.)

1013   /* Likewise for mudflap static object registrations.  */
1014   if (flag_mudflap)
1015     mudflap_finish_file ();
1016 
1017   /* Write out any pending weak symbol declarations.  */
1018 
1019   weak_finish ();
1020 
1021   /* Do dbx symbols.  */
1022   timevar_push (TV_SYMOUT);
1023 
1024 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1025   if (dwarf2out_do_frame ())
1026     dwarf2out_frame_finish ();
1027 #endif
1028 
1029   (*debug_hooks->finish) (main_input_filename);
1030   timevar_pop (TV_SYMOUT);
1031 
1032   /* Output some stuff at end of file if nec.  */
1033 
1034   dw2_output_indirect_constants ();
1035 
1036   /* Flush any pending external directives.  cgraph did this for
1037      assemble_external calls from the front end, but the RTL
1038      expander can also generate them.  */
1039   process_pending_assemble_externals ();
1040 
1041   /* Attach a special .ident directive to the end of the file to identify
1042      the version of GCC which compiled this code.  The format of the .ident
1043      string is patterned after the ones produced by native SVR4 compilers.  */
1044 #ifdef IDENT_ASM_OP
1045   if (!flag_no_ident)
1046     fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1047              IDENT_ASM_OP, version_string);
1048 #endif
1049 
1050   /* This must be at the end.  Some target ports emit end of file directives
1051      into the assembly file here, and hence we can not output anything to the
1052      assembly file after this point.  */
1053   targetm.asm_out.file_end ();
1054 }



リンク元