Exemplo n.º 1
0
Function *
Function::make_first(void)
{
    const Type *ty = RandomReturnType();
    ERROR_GUARD(NULL);

    Function *f = new Function(RandomFunctionName(), ty);
    // dummy variable representing return variable, we don't care about the type, so use 0
    string rvname = f->name + "_" + "rv";
    CVQualifiers ret_qfer = CVQualifiers::random_qualifiers(ty);
    ERROR_GUARD(NULL);
    f->rv = Variable::CreateVariable(rvname, ty, NULL, &ret_qfer);

    // create a fact manager for this function, with empty global facts
    FactMgr* fm = new FactMgr(f);
    FMList.push_back(fm);

    ExtensionMgr::GenerateFirstParameterList(*f);

    // No Parameter List
    f->GenerateBody(CGContext::get_empty_context());
    if (CGOptions::inline_function() && rnd_flipcoin(InlineFunctionProb))
        f->is_inlined = true;
    fm->setup_in_out_maps(true);

    // update global facts to merged facts at all possible function exits
    fm->global_facts = fm->map_facts_out[f->body];
    f->body->add_back_return_facts(fm, fm->global_facts);

    // collect info about global dangling pointers
    fm->find_dangling_global_ptrs(f);
    return f;
}
Exemplo n.º 2
0
Function *
Function::make_random(const CGContext& cg_context, const Type* type, const CVQualifiers* qfer)
{
    Function* f = make_random_signature(cg_context, type, qfer);
    ERROR_GUARD(NULL);
    f->GenerateBody(cg_context);
    ERROR_GUARD(NULL);
    return f;
}
Exemplo n.º 3
0
void
Function::make_builtin_function(const string &function_string)
{
    vector<string> v;
    StringUtils::split_string(function_string, v, ";");
    if (v.size() == 4) {
        if (!CGOptions::enabled_builtin(v[3]))
            return;
    }
    else if (v.size() == 3) {
        if (!CGOptions::enabled_builtin("generic"))
            return;
    }
    else {
        assert(0 && "Invalid builtin function format!");
    }

    const Type *ty = Type::get_type_from_string(v[0]);
    Function *f = new Function(v[1], ty, /*is_builtin*/true);

    // dummy variable representing return variable, we don't care about the type, so use 0
    string rvname = f->name + "_" + "rv";
    CVQualifiers ret_qfer = CVQualifiers::random_qualifiers(ty);
    f->rv = Variable::CreateVariable(rvname, ty, NULL, &ret_qfer);

    // create a fact manager for this function, with empty global facts
    FactMgr* fm = new FactMgr(f);
    FMList.push_back(fm);

    GenerateParameterListFromString(*f, StringUtils::get_substring(v[2], '(', ')'));
    f->GenerateBody(CGContext::get_empty_context());

    // update global facts to merged facts at all possible function exits
    fm->global_facts = fm->map_facts_out[f->body];
    f->body->add_back_return_facts(fm, fm->global_facts);

    // collect info about global dangling pointers
    fm->find_dangling_global_ptrs(f);
    ++builtin_functions_cnt;
}