A dynamic tracer for Linux

node.h 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 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_nargs(struct node *n)
  46. {
  47. struct node *arg;
  48. int nargs = 0;
  49. for (arg = n->expr.args; arg; arg = arg->next, nargs++);
  50. return nargs;
  51. }
  52. int node_is_block(struct node *n);
  53. int node_is_map (struct node *n);
  54. #define node_expr_foreach(_expr, _arg) \
  55. for ((_arg) = (_expr)->expr.args; (_arg); (_arg) = (_arg)->next)
  56. #endif /* _PLY_NODE_H */