A dynamic tracer for Linux

node.h 1.2KB

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