GCC's bacl-end & assemble emission (44)

来源:互联网 发布:知鸟论文检测系统 编辑:程序博客网 时间:2024/06/08 14:45

14.   Toolof gencodes

The tool will generate insn code for other tools usage.

 

51    int

52    main (int argc, char **argv)                                                                        ingencodes.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 file name");

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  }

 

See that only define_insn and define_expand patterns will be handled– both are used to recognize RTL generation.

 

33    static void

34    gen_insn (rtx insn, int code)                                                                              ingencodes.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    }

 

For patterns having conditional template known as false at compiletime, it needsn’t be assigned new number, as it will never be selected, insteadusing CODE_FOR_nothing as a quick recognition. Butread_md_rtx increases insn_code_numberfor every readin pattern, so the code number isn’t consecutive, there areskipped numbers.