A dynamic tracer for Linux

node.h 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef _PLY_NODE_H
  2. #define _PLY_NODE_H
  3. #include <stdint.h>
  4. typedef struct sym sym_t;
  5. typedef struct atom atom_t;
  6. typedef struct expr expr_t;
  7. typedef struct node node_t;
  8. typedef enum atype {
  9. A_INVALID,
  10. A_IDENT,
  11. A_NUM,
  12. A_STRING,
  13. } atype_t;
  14. struct atom {
  15. atype_t atype;
  16. union {
  17. char *ident;
  18. int64_t num;
  19. char *string;
  20. };
  21. };
  22. typedef enum etype {
  23. E_INVALID = '\0',
  24. E_AGG = '@',
  25. E_CALL = '(',
  26. E_DEREF = '*',
  27. E_DOT = '.',
  28. E_MAP = 'm',
  29. E_SCOPE = '{',
  30. } etype_t;
  31. struct expr {
  32. etype_t etype;
  33. node_t *arg;
  34. };
  35. typedef enum ntype {
  36. N_INVALID,
  37. N_ATOM,
  38. N_EXPR,
  39. } ntype_t;
  40. struct node {
  41. ntype_t ntype;
  42. node_t *up;
  43. node_t *next;
  44. sym_t *sym;
  45. union {
  46. atom_t atom;
  47. expr_t expr;
  48. };
  49. };
  50. /* walk a node tree */
  51. typedef int (*walk_fn)(node_t *, void *);
  52. int node_walk(node_t *n, walk_fn pre, walk_fn post, void *ctx);
  53. /* node constructors */
  54. node_t *node_ident (char *name);
  55. node_t *node_num (int64_t num);
  56. node_t *node_string(char *string);
  57. node_t *node_expr (etype_t etype, node_t *arg);
  58. node_t *node_cons (node_t *head, node_t *tail);
  59. /* debug */
  60. typedef struct node_dump_info {
  61. FILE *fp;
  62. int indent;
  63. } node_dump_info_t;
  64. void node_dump(node_t *n, node_dump_info_t *info);
  65. #endif /* _PLY_NODE_H */