#ifndef TOBI_IR_H #define TOBI_IR_H #include #include typedef enum tobi_ir_kind { TOBI_IR_ROOT, TOBI_IR_BLOCK, TOBI_IR_SCOPE, TOBI_IR_DEVICE, TOBI_IR_METHOD, TOBI_IR_PROCESSOR, TOBI_IR_NAME, TOBI_IR_ALIAS, TOBI_IR_OPREGION, TOBI_IR_FIELD, TOBI_IR_FIELD_ELEM, TOBI_IR_MUTEX, TOBI_IR_EVENT, TOBI_IR_RESOURCE, TOBI_IR_BUFFER, TOBI_IR_PACKAGE, TOBI_IR_INTEGER, TOBI_IR_STRING, TOBI_IR_REF, TOBI_IR_CALL, TOBI_IR_EXPR, TOBI_IR_STORE, TOBI_IR_RETURN, TOBI_IR_IF, TOBI_IR_WHILE, TOBI_IR_BREAK, TOBI_IR_CONTINUE, TOBI_IR_UNKNOWN, TOBI_IR_DIAG } tobi_ir_kind; typedef struct tobi_ir { tobi_ir_kind kind; size_t id; size_t parent_id; size_t parent_index; size_t off; size_t len; char *name; char *path; char *scope; char *str; char *target; char *source; uint64_t value; uint64_t bit_off; uint64_t bit_len; uint32_t raw_op; unsigned access_type; unsigned lock_rule; unsigned update_rule; unsigned method_args; unsigned method_serialized; unsigned method_sync; struct tobi_ir **child; size_t child_len; size_t child_cap; size_t input_index; int has_source; } tobi_ir; tobi_ir *tobi_ir_new(tobi_ir_kind kind, size_t off, size_t len); void tobi_ir_free(tobi_ir *node); void tobi_ir_add(tobi_ir *parent, tobi_ir *child); void tobi_ir_assign_ids(tobi_ir *root); void tobi_ir_set_name(tobi_ir *node, const char *s); void tobi_ir_set_path(tobi_ir *node, const char *s); void tobi_ir_set_scope(tobi_ir *node, const char *s); void tobi_ir_set_str(tobi_ir *node, const char *s); void tobi_ir_set_target(tobi_ir *node, const char *s); void tobi_ir_set_source(tobi_ir *node, const char *s, size_t input_index); void tobi_ir_set_source_recursive(tobi_ir *node, const char *s, size_t input_index); const char *tobi_ir_kind_name(tobi_ir_kind kind); tobi_ir *tobi_ir_find_child(tobi_ir *node, tobi_ir_kind kind); size_t tobi_ir_count_kind(const tobi_ir *node, tobi_ir_kind kind); #endif