ACPI AML decompiler w/ CFG recovery and structured pseudocode
1#include "t.h"
2
3#include "ir.h"
4
5int t_ir(void) {
6 tobi_ir *root = tobi_ir_new(TOBI_IR_ROOT, 0, 10);
7 tobi_ir *m = tobi_ir_new(TOBI_IR_METHOD, 2, 8);
8 tobi_ir_set_name(m, "MTH0");
9 tobi_ir_set_scope(root, "\\");
10 tobi_ir_add(root, m);
11 tobi_ir_add(m, tobi_ir_new(TOBI_IR_BLOCK, 7, 3));
12 tobi_ir_set_scope(m->child[0], "\\MTH0");
13 tobi_ir_assign_ids(root);
14 T_CHECK(root->kind == TOBI_IR_ROOT);
15 T_CHECK(root->id == 1 && root->parent_id == 0);
16 T_CHECK(root->child_len == 1);
17 T_CHECK(root->child[0]->off == 2 && root->child[0]->len == 8);
18 T_CHECK(root->child[0]->id == 2 && root->child[0]->parent_id == root->id);
19 T_CHECK(root->child[0]->parent_index == 0);
20 T_CHECK(m->child[0]->id == 3 && m->child[0]->parent_id == m->id);
21 T_CHECK(strcmp(root->scope, "\\") == 0);
22 T_CHECK(strcmp(m->child[0]->scope, "\\MTH0") == 0);
23 T_CHECK(tobi_ir_find_child(root, TOBI_IR_METHOD) == m);
24 T_CHECK(tobi_ir_count_kind(root, TOBI_IR_METHOD) == 1);
25 tobi_ir *u = tobi_ir_new(TOBI_IR_UNKNOWN, 4, 1);
26 u->raw_op = 0xfe;
27 tobi_ir_add(m->child[0], u);
28 tobi_ir_assign_ids(root);
29 T_CHECK(m->child[0]->child[0]->raw_op == 0xfe);
30 T_CHECK(m->child[0]->child[0]->id == 4);
31 T_CHECK(m->child[0]->child[0]->parent_id == m->child[0]->id);
32 T_CHECK(m->child[0]->child[0]->parent_index == 0);
33 tobi_ir_free(root);
34 return 0;
35}