#pragma once #include "type.h" #include "ir.h" enum node_type { N_LIST, // [head] [tail] N_LIST_END, // -- N_BLOCK, // [body] N_VAR_DECL_INIT, // rtype name [value] N_VAR_DECL, // rtype name N_FUNC_DECL, // rtype name [params] [body] N_IF, // [cond] [body] [else-body] N_WHILE, // [cond] [body] N_RETURN, // -- N_RETURNV, // [value] N_NUM, // value N_VAR, // name N_BINOP, // [left] oper [right] N_UNOP, // oper [arg] N_CALL, // name [args] N_IRINS, // irins }; enum operator { // binary OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_EQ, OP_NEQ, OP_LT, OP_GT, OP_LEQ, OP_GEQ, OP_AND, OP_OR, OP_ASSIGN, // unary OP_NEG, OP_NOT, OP_DEREF, OP_ADDROF, }; struct node { enum node_type type; struct node *child1, *child2, *child3; struct type *rtype; char *name; int value; enum operator oper; struct irins *irins; struct type *valuetype; // filled in by type checker }; struct node* node_make_0(enum node_type type); struct node* node_make_1(enum node_type type, struct node *c1); struct node* node_make_2(enum node_type type, struct node *c1, struct node *c2); struct node* node_make_3(enum node_type type, struct node *c1, struct node *c2, struct node *c3); __attribute__((sentinel)) struct node* node_make_list_(struct node *first, ...); #define node_make_list(...) node_make_list_(__VA_ARGS__, NULL) int node_list_length(struct node *node); void node_delete_recursive(struct node *node); const char* node_type_string(enum node_type type); const char* oper_string(enum operator oper); void node_print(const struct node *node, FILE *f, int indent);