这个工具将产生为其它工具使用的指令编号。
51 int
52 main (int argc, char **argv) in gencodes.c
53 {
54 rtx desc;
55
56 progname= "gencodes";
57
58 /* We need to see all the possibilities.Elided insns may have
59 direct references to CODE_FOR_xxx in Ccode. */
60 insn_elision= 0;
61
62 if (argc <= 1)
63 fatal ("no input filename");
64
65 if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
66 return (FATAL_EXIT_CODE);
67
68 puts ("\
69 /* Generated automatically by theprogram `gencodes'\n\
70 from the machine description file `md'. */\n\
71 \n\
72 #ifndef GCC_INSN_CODES_H\n\
73 #define GCC_INSN_CODES_H\n\
74 \n\
75 enum insn_code {");
76
77 /* Read the machine description. */
78
79 while (1)
80 {
81 int line_no;
82 int insn_code_number;
83
84 desc= read_md_rtx (&line_no, &insn_code_number);
85 if (desc== NULL)
86 break;
87
88 if (GET_CODE (desc) ==DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
89 gen_insn (desc, insn_code_number);
90 }
91
92 puts (" CODE_FOR_nothing\n\
93 };\n\
94 \n\
95 #endif /* GCC_INSN_CODES_H */");
96
97 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
98 return FATAL_EXIT_CODE;
99
100 return SUCCESS_EXIT_CODE;
101 }
看到仅define_insn及define_expand模式(pattern)会得到处理——两者都是被用来识别RTL生成。
33 static void
34 gen_insn (rtx insn, int code) in gencodes.c
35 {
36 const char *name = XSTR (insn, 0);
37 int truth = maybe_eval_c_test (XSTR(insn, 2));
38
39 /* Don't mention instructions whose names arethe null string
40 or begin with '*'. They are in the machinedescription just
41 to be recognized. */
42 if (name[0] != 0 && name[0] != '*')
43 {
44 if (truth == 0)
45 printf ("#define CODE_FOR_%s CODE_FOR_nothing\n", name);
46 else
47 printf (" CODE_FOR_%s =%d,\n", name, code);
48 }
49 }
对于编译时刻已知条件模板为false的有效模式(pattern),不需要为之分配编号,因为它不会被选中,使用CODE_FOR_nothing来作为一个快速识别的方法。但是,read_md_rtx将为每个模式递增insn_code_number,因此指令编号不是连续的,中间有跳号。