A dynamic tracer for Linux

node.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /* REEEEEEEEEEEEEEMOVE */
  9. typedef struct node node_t;
  10. enum ntype {
  11. N_EXPR,
  12. N_IDENT,
  13. N_NUM,
  14. N_STRING,
  15. };
  16. struct node {
  17. struct node *next, *prev, *up;
  18. enum ntype ntype;
  19. union {
  20. struct {
  21. char *func;
  22. struct node *args;
  23. } expr;
  24. struct {
  25. char *name;
  26. } ident;
  27. struct {
  28. int64_t num;
  29. } num;
  30. struct {
  31. char *data;
  32. } string;
  33. };
  34. type_t *type;
  35. sym_t *sym;
  36. irstate_t irs;
  37. };
  38. /* debug */
  39. void node_print(struct node *n, FILE *fp);
  40. void node_dump (struct node *n, FILE *fp);
  41. typedef int (*walk_fn)(struct node *, void *);
  42. int node_walk(struct node *n, walk_fn pre, walk_fn post, void *ctx);
  43. int node_replace(struct node *n, struct node *new);
  44. #define node_expr_foreach(_expr, _arg) \
  45. for ((_arg) = (_expr)->expr.args; (_arg); (_arg) = (_arg)->next)
  46. /* constructors */
  47. struct node *node_string(char *data);
  48. struct node *node_num (int64_t num);
  49. struct node *node_ident (char *name);
  50. struct node *node_append(struct node *n, struct node *arg);
  51. struct node *node_expr (char *func, ...);
  52. static inline int node_is_block(struct node *n)
  53. {
  54. if (!n || (n->ntype != N_EXPR))
  55. return 0;
  56. return n->expr.func[0] == '\0';
  57. }
  58. /* static inline node_t *node_head(node_t *n) */
  59. /* { */
  60. /* if (!n) */
  61. /* return NULL; */
  62. /* for (; n->prev; n = n->prev); */
  63. /* return n; */
  64. /* } */
  65. /* static inline node_t *node_prev(node_t *n) */
  66. /* { */
  67. /* return n ? n->prev : NULL; */
  68. /* } */
  69. /* static inline node_t *node_next(node_t *n) */
  70. /* { */
  71. /* return n ? n->next : NULL; */
  72. /* } */
  73. /* static inline node_t *node_up(node_t *n) */
  74. /* { */
  75. /* return n ? n->up : NULL; */
  76. /* } */
  77. #endif /* _PLY_NODE_H */