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

本文详细解析了gencheck和genconstants两个工具的工作原理,包括它们如何处理中间形式的程序,如何创建节点,以及如何生成检查宏和常量定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

17.   Toolof gencheck

Program after processing by front-end, is transformed into rtl form.Program in this intermediate form is constructed as a tree. Can conceive thatthe nodes in the tree are various and complex, to put node creation in easierand more controllable way. Nodes are described in tree.def and C-common.def(file specified for c & c++) similar as rtx object in rtl.def.

The instruction used to describe tree nodes is in following form.

DEFTREECODE(SYM, NAME, TYPE, LENGTH)

For example in tree.def, we can get following lines.

DEFTREECODE (IDENTIFIER_NODE,"identifier_node", 'x', 0)

In gencheck.c we can see below code snippet.

 

27    #define DEFTREECODE(SYM, NAME, TYPE, LEN) #SYM,                       in gencheck.c

28   

29    static const char *const tree_codes[] = {

30    #include "tree.def"

31    #include "c-common.def"

32    #include "gencheck.h"

33    (char*) 0

34    };

 

At line 32 above, gencheck.h will be created by Makefile which willinclude appropriate def files according to the target language.

 

44    int

45    main (int argc, char **argvATTRIBUTE_UNUSED)                                           in gencheck.c

46    {

47     int i, j;

48   

49     switch (argc)

50     {

51       case 1:

52         break;

53   

54       default:

55         usage ();

56         return (1);

57     }

58   

59     puts ("/* This file is generated using gencheck. Do not edit.*/\n");

60     puts ("#ifndef GCC_TREE_CHECK_H");

61     puts ("#define GCC_TREE_CHECK_H\n");

62   

63     /* Print macros for checks based on each ofthe tree code names. However,

64        since we include the tree nodes from alllanguages, we must check

65        for duplicate names to avoid defining thesame macro twice.  */

66      for(i = 0; tree_codes[i];i++)

67      {

68        for(j = 0; j < i; j++)

69         if (strcmp (tree_codes[i], tree_codes[j]) == 0)

70            break;

71   

72       if (i == j)

73         printf ("#define %s_CHECK(t)\tTREE_CHECK (t, %s)\n",

74                tree_codes[i], tree_codes[i]);

75     }

76   

77     puts ("\n#endif /* GCC_TREE_CHECK_H */");

78     return 0;

79    }

 

Then as for IDENTIFIER_NODE, following code will be output intotree-check.h

 

#define IDENTIFIER_NODE_CHECK(t)    TREE_CHECK (t, IDENTIFIER_NODE)

18.   Toolof genconstants

The tool will output insn-constants.h defining constants used inmachine description file.

 

52    int

53    main (int argc, char **argv)                                                                 ingenconstants.c

54    {

55     int dummy1, dummy2;

56     rtx desc;

57   

58     progname= "genconstants";

59   

60     if (argc <= 1)

61       fatal ("no input file name");

62   

63     if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)

64       return (FATAL_EXIT_CODE);

65   

66     /* Scan and discard the entire file. This hasthe side effect

67        of loading up the constants table that wewish to scan.  */

68     do

69       desc = read_md_rtx (&dummy1,&dummy2);

70     while (desc);

71   

72     puts ("/* Generated automatically by the program`genconstants'");

73     puts ("   from the machinedescription file `md'.  */\n");

74      puts ("#ifndef GCC_INSN_CONSTANTS_H");

75      puts ("#defineGCC_INSN_CONSTANTS_H\n");

76   

77      traverse_md_constants (print_md_constant, stdout);

78   

79      puts ("\n#endif /*GCC_INSN_CONSTANTS_H */");

80   

81      if (ferror (stdout) || fflush(stdout) || fclose (stdout))

82       return FATAL_EXIT_CODE;

83   

84     return SUCCESS_EXIT_CODE;

85    }

 

477  void

478  traverse_md_constants (htab_trav callback, void *info)                                  inread-rtl.c

479  {

480   if (md_constants)

481     htab_traverse (md_constants, callback, info);

482  }

 

In i386.md, it uses define_constants to define constants to be used.md_constantsabove records the constants read by read_constants.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值