#include "t.h" #include "cf.h" #include "p.h" int t_cf(void) { uint8_t ifelse[] = {0x14,0x15,'I','F','E','0',0x01,0xa0,0x06,0x68,0x70,0x0a,0x01,0x60,0xa1,0x05,0x70,0x0a,0x02,0x60,0xa4,0x60}; tobi_parse_result r; T_CHECK(tobi_parse(ifelse, sizeof(ifelse), 0, &r)); T_CHECK(tobi_cf_recover(r.root, &r.diag)); tobi_ir *ifn = r.root->child[0]->child[0]->child[0]; T_CHECK(ifn->kind == TOBI_IR_IF && ifn->child_len == 3); char *dot = tobi_cf_dot(r.root); T_STR(dot, "digraph tobi_cfg"); T_STR(dot, "then"); T_STR(dot, "else"); free(dot); tobi_parse_result_free(&r); uint8_t wh[] = {0x14,0x20,'W','L','O','0',0x01,0x70,0x0a,0x03,0x60,0xa2,0x13,0x60,0xa0,0x06,0x68,0x70,0x0a,0x01,0x61,0xa1,0x05,0x70,0x0a,0x02,0x61,0x74,0x60,0x01,0x60,0xa4,0x61}; T_CHECK(tobi_parse(wh, sizeof(wh), 0, &r)); T_CHECK(tobi_cf_recover(r.root, &r.diag)); tobi_ir *while_n = r.root->child[0]->child[0]->child[1]; T_CHECK(while_n->kind == TOBI_IR_WHILE); T_CHECK(while_n->child[1]->child[0]->kind == TOBI_IR_IF); tobi_parse_result_free(&r); uint8_t amb[] = {0xa0,0x03,0x01,0xa1}; T_CHECK(tobi_parse(amb, sizeof(amb), 0, &r)); T_CHECK(r.root->child_len == 1); T_CHECK(r.root->child[0]->kind == TOBI_IR_IF); T_CHECK(tobi_ir_find_child(r.root->child[0]->child[1], TOBI_IR_UNKNOWN) != NULL); T_CHECK(tobi_cf_recover(r.root, &r.diag)); T_CHECK(tobi_ir_find_child(r.root->child[0]->child[1], TOBI_IR_DIAG) != NULL); tobi_parse_result_free(&r); return 0; }