細 (整形) |
編集の要約なし |
||
1行目: | 1行目: | ||
+ | |||
− | {{header}} |
||
+ | == このページを編集する際は,[[編集に関する方針]]に従ってください. == |
||
== 概要 == |
== 概要 == |
||
5行目: | 6行目: | ||
*コンパイル単位のファイル全体をコンパイル.アセンブリとデバッグ情報が含まれたファイルを出力. |
*コンパイル単位のファイル全体をコンパイル.アセンブリとデバッグ情報が含まれたファイルを出力. |
||
− | + | 975 /* Compile an entire translation unit. Write a file of assembly |
|
− | + | 976 output and various debugging dumps. */ |
|
ちょっと実装を眺めればわかりますが,[[struct lang_hooks]] という構造体に関数ポインタが格納されていて,オブジェクト指向におけるポリモーフィズムのようなことが行われています (面白ポイント). |
ちょっと実装を眺めればわかりますが,[[struct lang_hooks]] という構造体に関数ポインタが格納されていて,オブジェクト指向におけるポリモーフィズムのようなことが行われています (面白ポイント). |
||
+ | ~ |
||
− | |||
− | + | # ターゲットとする言語や,特定の状況に応じて呼び出される (フックされている) 関数が差し替えられる. |
|
== 実装 == |
== 実装 == |
||
<code> |
<code> |
||
− | + | 978 static void |
|
− | + | 979 compile_file (void) |
|
− | + | 980 { |
|
981 /* Initialize yet another pass. */ |
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 |
|
− | </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). */ |
||
− | + | 991 [[lang_hooks]].parse_file ([[set_yydebug]]); |
|
− | + | 992 |
|
993 /* In case there were missing block closers, |
993 /* In case there were missing block closers, |
||
994 get us back to the global binding level. */ |
994 get us back to the global binding level. */ |
||
− | + | 995 [[lang_hooks]].clear_binding_stack (); |
|
− | + | 996 |
|
997 /* Compilation is now finished except for writing |
997 /* Compilation is now finished except for writing |
||
998 what's left of the symbol table output. */ |
998 what's left of the symbol table output. */ |
||
− | + | 999 [[timevar_pop]] ([[TV_PARSE]]); |
|
1000 |
1000 |
||
1001 if ([[flag_syntax_only]]) |
1001 if ([[flag_syntax_only]]) |
||
47行目: | 45行目: | ||
1006 [[finish_aliases_2]] (); |
1006 [[finish_aliases_2]] (); |
||
1007 |
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]] (); |
1011 [[coverage_finish]] (); |
||
1012 |
1012 |
||
+ | |||
− | </code> |
||
− | *gcc-4.1.0 からの新機能.バッファオーバーフローを防ぐための,配列の境界チェックなどを行うコンパイルオプション -fmudflap が有効になっていた場合. |
+ | *gcc-4.1.0 からの新機能.バッファオーバーフローを防ぐための,配列の境界チェックなどを行うコンパイルオプション -fmudflap が有効になっていた場合. |
+ | ~ |
||
− | + | (ランタイムのリンク -lmudflap オプションも,ターゲットファイル名の後に必要.すなわち,$ gcc -fmudflap foo.c -lmudflap) |
|
⚫ | |||
+ | ~ |
||
− | <code> |
||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
1014 if ([[flag_mudflap]]) |
1014 if ([[flag_mudflap]]) |
||
1015 [[mudflap_finish_file]] (); |
1015 [[mudflap_finish_file]] (); |
||
1016 |
1016 |
||
− | + | 1017 /* Write out any pending weak symbol declarations. */ |
|
1018 |
1018 |
||
1019 [[weak_finish]] (); |
1019 [[weak_finish]] (); |
||
1020 |
1020 |
||
− | + | 1021 /* Do dbx symbols. */ |
|
1022 [[timevar_push]] ([[TV_SYMOUT]]); |
1022 [[timevar_push]] ([[TV_SYMOUT]]); |
||
1023 |
1023 |
||
73行目: | 73行目: | ||
1027 #endif |
1027 #endif |
||
1028 |
1028 |
||
− | 1029 (* |
+ | 1029 (*debug_hooks->finish) ([[main_input_filename]]); |
1030 [[timevar_pop]] ([[TV_SYMOUT]]); |
1030 [[timevar_pop]] ([[TV_SYMOUT]]); |
||
1031 |
1031 |
||
− | + | 1032 /* Output some stuff at end of file if nec. */ |
|
1033 |
1033 |
||
1034 [[dw2_output_indirect_constants]] (); |
1034 [[dw2_output_indirect_constants]] (); |
||
1035 |
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]] (); |
1039 [[process_pending_assemble_externals]] (); |
||
1040 |
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]] |
1044 #ifdef [[IDENT_ASM_OP]] |
||
1045 if (![[flag_no_ident]]) |
1045 if (![[flag_no_ident]]) |
||
94行目: | 94行目: | ||
1048 #endif |
1048 #endif |
||
1049 |
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 (); |
1053 [[targetm]].asm_out.file_end (); |
||
1054 } |
1054 } |
||
+ | |||
</code> |
</code> |
||
+ | |||
− | {{related}} |
||
+ | [[特別:Whatlinkshere/Tree|{{int:Whatlinkshere}}]] |
2007年9月28日 (金) 00:00時点における版
このページを編集する際は,編集に関する方針に従ってください.
概要
- 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 }