ACPI AML decompiler w/ CFG recovery and structured pseudocode
1#ifndef TOBI_IR_H
2#define TOBI_IR_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7typedef enum tobi_ir_kind {
8 TOBI_IR_ROOT,
9 TOBI_IR_BLOCK,
10 TOBI_IR_SCOPE,
11 TOBI_IR_DEVICE,
12 TOBI_IR_METHOD,
13 TOBI_IR_PROCESSOR,
14 TOBI_IR_NAME,
15 TOBI_IR_ALIAS,
16 TOBI_IR_OPREGION,
17 TOBI_IR_FIELD,
18 TOBI_IR_FIELD_ELEM,
19 TOBI_IR_MUTEX,
20 TOBI_IR_EVENT,
21 TOBI_IR_RESOURCE,
22 TOBI_IR_BUFFER,
23 TOBI_IR_PACKAGE,
24 TOBI_IR_INTEGER,
25 TOBI_IR_STRING,
26 TOBI_IR_REF,
27 TOBI_IR_CALL,
28 TOBI_IR_EXPR,
29 TOBI_IR_STORE,
30 TOBI_IR_RETURN,
31 TOBI_IR_IF,
32 TOBI_IR_WHILE,
33 TOBI_IR_BREAK,
34 TOBI_IR_CONTINUE,
35 TOBI_IR_UNKNOWN,
36 TOBI_IR_DIAG
37} tobi_ir_kind;
38
39typedef struct tobi_ir {
40 tobi_ir_kind kind;
41 size_t id;
42 size_t parent_id;
43 size_t parent_index;
44 size_t off;
45 size_t len;
46 char *name;
47 char *path;
48 char *scope;
49 char *str;
50 char *target;
51 uint64_t value;
52 uint64_t bit_off;
53 uint64_t bit_len;
54 uint32_t raw_op;
55 unsigned access_type;
56 unsigned lock_rule;
57 unsigned update_rule;
58 unsigned method_args;
59 unsigned method_serialized;
60 unsigned method_sync;
61 struct tobi_ir **child;
62 size_t child_len;
63 size_t child_cap;
64} tobi_ir;
65
66tobi_ir *tobi_ir_new(tobi_ir_kind kind, size_t off, size_t len);
67
68void tobi_ir_free(tobi_ir *node);
69
70void tobi_ir_add(tobi_ir *parent, tobi_ir *child);
71
72void tobi_ir_assign_ids(tobi_ir *root);
73
74void tobi_ir_set_name(tobi_ir *node, const char *s);
75
76void tobi_ir_set_path(tobi_ir *node, const char *s);
77
78void tobi_ir_set_scope(tobi_ir *node, const char *s);
79
80void tobi_ir_set_str(tobi_ir *node, const char *s);
81
82void tobi_ir_set_target(tobi_ir *node, const char *s);
83
84const char *tobi_ir_kind_name(tobi_ir_kind kind);
85
86tobi_ir *tobi_ir_find_child(tobi_ir *node, tobi_ir_kind kind);
87
88size_t tobi_ir_count_kind(const tobi_ir *node, tobi_ir_kind kind);
89
90#endif