A dynamic tracer for Linux

node.h 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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)->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 node_t *node_head(node_t *n) */
  53. /* { */
  54. /* if (!n) */
  55. /* return NULL; */
  56. /* for (; n->prev; n = n->prev); */
  57. /* return n; */
  58. /* } */
  59. /* static inline node_t *node_prev(node_t *n) */
  60. /* { */
  61. /* return n ? n->prev : NULL; */
  62. /* } */
  63. /* static inline node_t *node_next(node_t *n) */
  64. /* { */
  65. /* return n ? n->next : NULL; */
  66. /* } */
  67. /* static inline node_t *node_up(node_t *n) */
  68. /* { */
  69. /* return n ? n->up : NULL; */
  70. /* } */
  71. #endif /* _PLY_NODE_H */