MCPcopy Create free account
hub / github.com/GJDuck/e9patch / matchDoEval

Function matchDoEval

src/e9tool/e9action.cpp:2398–2591  ·  view source on GitHub ↗

* Evaluate a matching. */

Source from the content-addressed store, hash-verified

2396 * Evaluate a matching.
2397 */
2398static MatchVal matchDoEval(const MatchExpr *expr, const ELF &elf,
2399 const std::vector<Instr> &Is, size_t idx, const InstrInfo *I,
2400 uint8_t *scratch)
2401{
2402 MatchVal lhs, rhs, res;
2403 switch (expr->op)
2404 {
2405 case MATCH_OP_ARG:
2406 {
2407 switch (expr->arg.inst)
2408 {
2409 case MATCH_INST_VAL:
2410 res = *expr->arg.val;
2411 break;
2412 case MATCH_INST_VAR:
2413 res = makeMatchValue(expr->arg.var, &elf, Is, idx, I,
2414 scratch);
2415 if (option_debug)
2416 {
2417 std::string str_var, str_val;
2418 bool hex = shouldDumpHex(*expr->arg.var);
2419 dumpExpr(*expr, str_var);
2420 dumpVal(res, str_val, hex);
2421 debug("%s0x%lx%s: \tvar %s%s = %s%s",
2422 (option_is_tty? "\33[31m": ""), I->address,
2423 (option_is_tty? "\33[0m": ""),
2424 (option_is_tty? "\33[33m": ""),
2425 str_var.c_str(), str_val.c_str(),
2426 (option_is_tty? "\33[0m": ""));
2427 }
2428 break;
2429 default:
2430 error("unexpected inst");
2431 }
2432 break;
2433 }
2434 case MATCH_OP_NOT:
2435 res = matchCastToBool(matchDoEval(expr->lhs, elf, Is, idx, I,
2436 scratch));
2437 res.i = (res.i == 0);
2438 break;
2439 case MATCH_OP_AND:
2440 res = matchCastToBool(matchDoEval(expr->lhs, elf, Is, idx, I,
2441 scratch));
2442 if (res.i == false)
2443 break;
2444 res = matchCastToBool(matchDoEval(expr->rhs, elf, Is, idx, I,
2445 scratch));
2446 break;
2447 case MATCH_OP_OR:
2448 res = matchCastToBool(matchDoEval(expr->lhs, elf, Is, idx, I,
2449 scratch));
2450 if (res.i == true)
2451 break;
2452 res = matchCastToBool(matchDoEval(expr->rhs, elf, Is, idx, I,
2453 scratch));
2454 break;
2455 case MATCH_OP_DEFINED:

Callers 1

matchEvalFunction · 0.85

Calls 8

makeMatchValueFunction · 0.85
shouldDumpHexFunction · 0.85
dumpExprFunction · 0.85
dumpValFunction · 0.85
errorFunction · 0.85
matchCastToBoolFunction · 0.85
isMemberFunction · 0.85
isSubsetFunction · 0.85

Tested by

no test coverage detected