A dynamic tracer for Linux

node.h 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef _PLY_NODE_H
  2. #define _PLY_NODE_H
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. struct sym;
  6. /* symbol information is defined externally */
  7. enum ntype {
  8. N_EXPR,
  9. N_IDENT,
  10. N_NUM,
  11. N_STRING,
  12. };
  13. struct node {
  14. struct node *next, *prev, *up;
  15. enum ntype ntype;
  16. union {
  17. struct {
  18. char *func;
  19. struct node *args;
  20. } expr;
  21. struct {
  22. char *name;
  23. } ident;
  24. struct {
  25. int64_t num;
  26. } num;
  27. struct {
  28. char *data;
  29. } string;
  30. };
  31. };
  32. /* debug */
  33. void node_print(struct node *n, FILE *fp);
  34. void node_dump (struct node *n, FILE *fp);
  35. typedef int (*nwalk_fn)(struct node *, void *);
  36. int node_walk(struct node *n, nwalk_fn pre, nwalk_fn post, void *ctx);
  37. int node_replace(struct node *n, struct node *new);
  38. /* constructors */
  39. struct node *node_string(char *data);
  40. struct node *node_num (int64_t num);
  41. struct node *node_ident (char *name);
  42. struct node *node_append(struct node *n, struct node *arg);
  43. struct node *node_expr (char *func, ...);
  44. /* helpers */
  45. static inline int node_is_block(struct node *n)
  46. {
  47. if (!n || (n->ntype != N_EXPR))
  48. return 0;
  49. return n->expr.func[0] == '\0';
  50. }
  51. #define node_expr_foreach(_expr, _arg) \
  52. for ((_arg) = (_expr)->expr.args; (_arg); (_arg) = (_arg)->next)
  53. #endif /* _PLY_NODE_H */