Esempio n. 1
0
bool ParseRepetition(Repetition *Repetition, CallExpr *Call, Assertion *A,
                     vector<ValueDecl*>& References,
                     ASTContext& Ctx) {
  unsigned Args = Call->getNumArgs();
  if (Args < 3) {
    Report("Repetition must have at least three arguments (min, max, events)",
        Call->getLocStart(), Ctx)
      << Call->getSourceRange();
    return false;
  }

  auto Min = ParseIntegerLiteral(Call->getArg(0), Ctx);
  Repetition->set_min(Min.getLimitedValue());

  auto Max = ParseIntegerLiteral(Call->getArg(1), Ctx);
  if (Max != INT_MAX) Repetition->set_max(Max.getLimitedValue());

  for (unsigned i = 2; i < Args; ++i) {
    auto Ev = Call->getArg(i);
    if (!ParseEvent(Repetition->add_event(), Ev, A, References, Ctx)) {
      Report("Failed to parse repeated event", Ev->getLocStart(), Ctx)
        << Ev->getSourceRange();
      return false;
    }
  }

  return true;
}
Esempio n. 2
0
TEST_F(ResolveConditionTest, SwitchConditionsAreResolved) {
  {
    // No runtime information is set in the specialization context. Thus the resolution of the condition must fail.
    const auto resolved_condition = ResolveCondition(_switch_instruction->getCondition(), _specialization_context);
    ASSERT_FALSE(resolved_condition);
  }
  {
    // Create runtime information (i.e., an instance of the SomeStruct parameter).
    const auto runtime_parameter = SomeStruct{std::rand() % 100, std::rand() % 100};

    // Initialize the first function argument to this value in the specialization context. This make the value
    // accessible to the specialization engine.
    _specialization_context.runtime_value_map.clear();
    _specialization_context.runtime_value_map[_switch_instruction_fn->arg_begin()] =
        std::make_shared<JitConstantRuntimePointer>(&runtime_parameter);

    const auto resolved_condition = ResolveCondition(_switch_instruction->getCondition(), _specialization_context);

    // The condition should now be replaced by an integer constant with the correct value from the runtime parameter.
    ASSERT_TRUE(resolved_condition);
    ASSERT_EQ(resolved_condition->getType(), llvm::Type::getInt32Ty(*_repository->llvm_context()));
    const auto resolved_int_condition = llvm::dyn_cast<llvm::ConstantInt>(resolved_condition);
    const auto resolved_condition_value =
        static_cast<int32_t>(resolved_int_condition->getLimitedValue(std::numeric_limits<uint64_t>::max()));
    ASSERT_EQ(resolved_condition_value, runtime_parameter.a);
  }
}