A dynamic tracer for Linux

node.h 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. int64_t num;
  27. } num;
  28. struct {
  29. char *data;
  30. } string;
  31. };
  32. };
  33. /* debug */
  34. void node_print(struct node *n, FILE *fp);
  35. void node_dump (struct node *n, FILE *fp);
  36. void node_error(struct node *n, FILE *fp, const char *fmt, ...);
  37. typedef int (*nwalk_fn)(struct node *, void *);
  38. int node_walk(struct node *n, nwalk_fn pre, nwalk_fn post, void *ctx);
  39. int node_replace(struct node *n, struct node *new);
  40. /* constructors */
  41. struct node *node_string(char *data);
  42. struct node *node_num (int64_t num);
  43. struct node *node_ident (char *name);
  44. struct node *node_append(struct node *n, struct node *arg);
  45. struct node *node_expr (char *func, ...);
  46. /* helpers */
  47. int node_is_block(struct node *n);
  48. #define node_expr_foreach(_expr, _arg) \
  49. for ((_arg) = (_expr)->expr.args; (_arg); (_arg) = (_arg)->next)
  50. #endif /* _PLY_NODE_H */