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_BUFFER,
22 TOBI_IR_PACKAGE,
23 TOBI_IR_INTEGER,
24 TOBI_IR_STRING,
25 TOBI_IR_REF,
26 TOBI_IR_CALL,
27 TOBI_IR_EXPR,
28 TOBI_IR_STORE,
29 TOBI_IR_RETURN,
30 TOBI_IR_IF,
31 TOBI_IR_WHILE,
32 TOBI_IR_BREAK,
33 TOBI_IR_CONTINUE,
34 TOBI_IR_UNKNOWN,
35 TOBI_IR_DIAG
36} tobi_ir_kind;
37
38typedef struct tobi_ir {
39 tobi_ir_kind kind;
40 size_t off;
41 size_t len;
42 char *name;
43 char *path;
44 char *str;
45 uint64_t value;
46 uint32_t raw_op;
47 unsigned method_args;
48 unsigned method_serialized;
49 unsigned method_sync;
50 struct tobi_ir **child;
51 size_t child_len;
52 size_t child_cap;
53} tobi_ir;
54
55tobi_ir *tobi_ir_new(tobi_ir_kind kind, size_t off, size_t len);
56
57void tobi_ir_free(tobi_ir *node);
58
59void tobi_ir_add(tobi_ir *parent, tobi_ir *child);
60
61void tobi_ir_set_name(tobi_ir *node, const char *s);
62
63void tobi_ir_set_path(tobi_ir *node, const char *s);
64
65void tobi_ir_set_str(tobi_ir *node, const char *s);
66
67const char *tobi_ir_kind_name(tobi_ir_kind kind);
68
69tobi_ir *tobi_ir_find_child(tobi_ir *node, tobi_ir_kind kind);
70
71size_t tobi_ir_count_kind(const tobi_ir *node, tobi_ir_kind kind);
72
73#endif