A dynamic tracer for Linux

node.h 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef _PLY_NODE_H
  2. #define _PLY_NODE_H
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include "ir.h"
  6. #include "sym.h"
  7. #include "type.h"
  8. /* enum ntype { */
  9. /* N_EXPR, */
  10. /* N_IDENT, */
  11. /* N_NUM, */
  12. /* N_STRING, */
  13. /* }; */
  14. /* struct node { */
  15. /* struct node *next, *prev, *up; */
  16. /* enum ntype ntype; */
  17. /* union { */
  18. /* struct { */
  19. /* char *func; */
  20. /* struct node *args; */
  21. /* } expr; */
  22. /* struct { */
  23. /* char *name; */
  24. /* } ident; */
  25. /* struct { */
  26. /* int64_t num; */
  27. /* } num; */
  28. /* struct { */
  29. /* char *data; */
  30. /* } string; */
  31. /* }; */
  32. /* }; */
  33. typedef struct node node_t;
  34. typedef enum kwclass {
  35. KW_SUBSCRIPT = '[',
  36. KW_ASSIGN = '=',
  37. KW_BINOP = 'b',
  38. } kwclass_t;
  39. typedef enum kwarith {
  40. KW_ADD = '+',
  41. KW_SUB = '-',
  42. KW_MUL = '*',
  43. KW_DIV = '/',
  44. } kwarith_t;
  45. typedef struct keyword {
  46. kwclass_t class;
  47. int op;
  48. } keyword_t;
  49. typedef enum ntype {
  50. N_LIST,
  51. N_KEYWORD,
  52. N_IDENT,
  53. N_NUM,
  54. N_STRING,
  55. } ntype_t;
  56. struct node {
  57. node_t *next, *prev, *up;
  58. ntype_t ntype;
  59. union {
  60. node_t *list;
  61. keyword_t keyword;
  62. const char *ident;
  63. int64_t num;
  64. const char *string;
  65. };
  66. type_t *type;
  67. sym_t *sym;
  68. irstate_t irs;
  69. };
  70. /* debug */
  71. void node_print(node_t *n, FILE *fp);
  72. void node_dump (node_t *n, FILE *fp);
  73. typedef int (*walk_fn)(node_t *, void *);
  74. int node_walk(node_t *n, walk_fn pre, walk_fn post, void *ctx);
  75. int node_replace(node_t *n, node_t *new);
  76. /* constructors */
  77. node_t *node_list (node_t *head);
  78. node_t *node_vlist (node_t *head, ...);
  79. node_t *node_keyword(kwclass_t class, int op);
  80. node_t *node_ident (const char *name);
  81. node_t *node_num (int64_t num);
  82. node_t *node_string (const char *string);
  83. static inline node_t *node_head(node_t *n)
  84. {
  85. if (!n)
  86. return NULL;
  87. for (; n->prev; n = n->prev);
  88. return n;
  89. }
  90. static inline node_t *node_prev(node_t *n)
  91. {
  92. return n ? n->prev : NULL;
  93. }
  94. static inline node_t *node_next(node_t *n)
  95. {
  96. return n ? n->next : NULL;
  97. }
  98. static inline node_t *node_up(node_t *n)
  99. {
  100. return n ? n->up : NULL;
  101. }
  102. #endif /* _PLY_NODE_H */