#include "t.h" #include "cf.h" #include "dc.h" #include "p.h" int t_dc(void) { uint8_t m2[] = {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}; tobi_parse_result r; T_CHECK(tobi_parse(m2, sizeof(m2), 0, &r)); (void)tobi_cf_recover(r.root, &r.diag); char *s = tobi_dc_emit(r.root, &r.diag); T_STR(s, "method WLO0(args=1"); T_STR(s, "Local0 = 0x3"); T_STR(s, "while (Local0)"); T_STR(s, "if (Arg0)"); T_STR(s, " while"); T_STR(s, "return Local1"); free(s); tobi_parse_result_free(&r); uint8_t bad[] = {0xfe}; T_CHECK(tobi_parse(bad, sizeof(bad), 0, &r)); s = tobi_dc_emit(r.root, &r.diag); T_STR(s, "unknown opcode 0xfe at 0x0"); free(s); tobi_parse_result_free(&r); uint8_t exprm[] = { 0x14,0x19,'E','X','P','R',0x02, 0x70,0x72,0x68,0x77,0x69,0x0a,0x02,0x60,0x61,0x62, 0xa4,0x91,0x95,0x60,0x61,0x93,0x62,0x0a,0x00 }; T_CHECK(tobi_parse(exprm, sizeof(exprm), 0, &r)); s = tobi_dc_emit(r.root, &r.diag); T_STR(s, "Local2 = Arg0 + Arg1 * 0x2;"); T_STR(s, "return Local0 < Local1 || Local2 == 0x0;"); T_CHECK(strstr(s, "Arg0 + (Arg1 * 0x2)") == NULL); free(s); tobi_parse_result_free(&r); uint8_t targets[] = { 0x80,0x00,0x60, 0x99,0x0d,'4','2',0x00,0x61, 0x9e,0x68,0x0a,0x01,0x0a,0x02,0x62 }; T_CHECK(tobi_parse(targets, sizeof(targets), 0, &r)); s = tobi_dc_emit(r.root, &r.diag); T_STR(s, "Local0 = ~0x0;"); T_STR(s, "Local1 = to_integer(\"42\");"); T_STR(s, "Local2 = mid(Arg0, 0x1, 0x2);"); T_CHECK(strstr(s, "not(0x0, Local0)") == NULL); free(s); tobi_parse_result_free(&r); return 0; }