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 off;
42 size_t len;
43 char *name;
44 char *path;
45 char *str;
46 char *target;
47 uint64_t value;
48 uint64_t bit_off;
49 uint64_t bit_len;
50 uint32_t raw_op;
51 unsigned access_type;
52 unsigned lock_rule;
53 unsigned update_rule;
54 unsigned method_args;
55 unsigned method_serialized;
56 unsigned method_sync;
57 struct tobi_ir **child;
58 size_t child_len;
59 size_t child_cap;
60} tobi_ir;
61
62tobi_ir *tobi_ir_new(tobi_ir_kind kind, size_t off, size_t len);
63
64void tobi_ir_free(tobi_ir *node);
65
66void tobi_ir_add(tobi_ir *parent, tobi_ir *child);
67
68void tobi_ir_set_name(tobi_ir *node, const char *s);
69
70void tobi_ir_set_path(tobi_ir *node, const char *s);
71
72void tobi_ir_set_str(tobi_ir *node, const char *s);
73
74void tobi_ir_set_target(tobi_ir *node, const char *s);
75
76const char *tobi_ir_kind_name(tobi_ir_kind kind);
77
78tobi_ir *tobi_ir_find_child(tobi_ir *node, tobi_ir_kind kind);
79
80size_t tobi_ir_count_kind(const tobi_ir *node, tobi_ir_kind kind);
81
82#endif