A dynamic tracer for Linux

node.h 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. struct sym *sym;
  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. union {
  27. int64_t s64;
  28. uint64_t u64;
  29. };
  30. int unsignd:1;
  31. } num;
  32. struct {
  33. char *data;
  34. } string;
  35. };
  36. };
  37. /* debug */
  38. void node_print(struct node *n, FILE *fp);
  39. typedef int (*nwalk_fn)(struct node *, void *);
  40. int node_walk(struct node *n, nwalk_fn pre, nwalk_fn post, void *ctx);
  41. int node_replace(struct node *n, struct node *new);
  42. /* constructors */
  43. struct node *node_string(char *data);
  44. struct node *node_num (const char *numstr);
  45. struct node *node_ident (char *name);
  46. struct node *node_append(struct node *n, struct node *arg);
  47. struct node *node_expr (char *func, ...);
  48. /* helpers */
  49. static inline int node_nargs(struct node *n)
  50. {
  51. struct node *arg;
  52. int nargs = 0;
  53. for (arg = n->expr.args; arg; arg = arg->next, nargs++);
  54. return nargs;
  55. }
  56. int node_is_block(struct node *n);
  57. int node_is_map (struct node *n);
  58. #define node_expr_foreach(_expr, _arg) \
  59. for ((_arg) = (_expr)->expr.args; (_arg); (_arg) = (_arg)->next)
  60. #endif /* _PLY_NODE_H */