Beispiel #1
0
// We want to check whether a uniform/varying is statically used
// because we only count the used ones in packing computing.
// Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count
// toward varying counting if they are statically used in a fragment
// shader.
void CollectVariables::visitSymbol(TIntermSymbol* symbol)
{
    ASSERT(symbol != NULL);
    TVariableInfo* var = NULL;
    switch (symbol->getQualifier())
    {
    case EvqVaryingOut:
    case EvqInvariantVaryingOut:
    case EvqVaryingIn:
    case EvqInvariantVaryingIn:
        var = findVariable(symbol->getType(), symbol->getSymbol(), mVaryings);
        break;
    case EvqUniform:
        var = findVariable(symbol->getType(), symbol->getSymbol(), mUniforms);
        break;
    case EvqFragCoord:
        if (!mFragCoordAdded) {
            TVariableInfo info;
            info.name = "gl_FragCoord";
            info.mappedName = "gl_FragCoord";
            info.type = SH_FLOAT_VEC4;
            info.size = 1;
            info.precision = EbpMedium;  // Use mediump as it doesn't really matter.
            info.staticUse = true;
	    mVaryings.push_back(info);
            mFragCoordAdded = true;
        }
        return;
    case EvqFrontFacing:
        if (!mFrontFacingAdded) {
            TVariableInfo info;
            info.name = "gl_FrontFacing";
            info.mappedName = "gl_FrontFacing";
            info.type = SH_BOOL;
            info.size = 1;
            info.precision = EbpUndefined;
            info.staticUse = true;
	    mVaryings.push_back(info);
            mFrontFacingAdded = true;
        }
        return;
    case EvqPointCoord:
        if (!mPointCoordAdded) {
            TVariableInfo info;
            info.name = "gl_PointCoord";
            info.mappedName = "gl_PointCoord";
            info.type = SH_FLOAT_VEC2;
            info.size = 1;
            info.precision = EbpMedium;  // Use mediump as it doesn't really matter.
            info.staticUse = true;
	    mVaryings.push_back(info);
            mPointCoordAdded = true;
        }
        return;
    default:
        break;
    }
    if (var)
        var->staticUse = true;
}
Beispiel #2
0
//
// findVariable
//	scp	- a BPatch_point that defines the scope of the current search
//	name	- name of the variable to find.
//
BPatch_variableExpr *BPatch_image::findVariableInScope(BPatch_point &scp,
        const char *name)
{
    // Get the function to search for it's local variables.
    // XXX - should really use more detailed scoping info here - jkh 6/30/99
    BPatch_function *func = const_cast<BPatch_function *> (scp.getFunction());
    if (!func) {
        pdstring msg = pdstring("point passed to findVariable lacks a function\n address point type passed?");
        showErrorCallback(100, msg);
        return NULL;
    }
    BPatch_localVar *lv = func->findLocalVar(name);

    if (!lv) {
        // look for it in the parameter scope now
        lv = func->findLocalParam(name);
    }
    if (lv) {
        // create a local expr with the correct frame offset or absolute
        //   address if that is what is needed
        return new BPatch_variableExpr(proc, (void *) lv->getFrameOffset(),
                                       lv->getRegister(), lv->getType(), lv->getStorageClass(), &scp);
    }

    // finally check the global scope.
    // return findVariable(name);

    /* If we have something else to try, don't report errors on this failure. */
    bool reportErrors = true;
    char mangledName[100];
    func->getName( mangledName, 100 );
    char * lastScoping = NULL;
    if( strrchr( mangledName, ':' ) != NULL ) {
        reportErrors = false;
    }
    BPatch_variableExpr * gsVar = findVariable( name, reportErrors );

    if( gsVar == NULL ) {
        /* Try finding it with the function's scope prefixed. */

        if( (lastScoping = strrchr( mangledName, ':' )) != NULL ) {
            * (lastScoping + sizeof(char)) = '\0';
            char scopedName[200];
            memmove( scopedName, mangledName, strlen( mangledName ) );
            memmove( scopedName + strlen( mangledName ), name, strlen( name ) );
            scopedName[ strlen( mangledName ) + strlen( name ) ] = '\0';
            bperr( "Searching for scoped name '%s'\n", scopedName );
            gsVar = findVariable( scopedName );
        }
    }
    return gsVar;
}
Beispiel #3
0
bool Sheeve::find(
        const bool recursive,
        const std::string &name,
        bool &isVariable,
        bool &isProcedure,
        Declaration::shared_ptr &decl)
{
    isVariable = false;
    isProcedure = false;
    DeclaredVariable::shared_ptr varDecl;
    if(findVariable(recursive, name, varDecl))
    {
        decl = boost::dynamic_pointer_cast<Declaration>(varDecl);
        isVariable = true;
        return true;
    }
    DeclaredProcedure::shared_ptr procDecl;
    if (findProcedure(recursive, name, procDecl))
    {
        decl = boost::dynamic_pointer_cast<Declaration>(procDecl);
        isProcedure = true;
        return true;
    }
    return false;
}
Beispiel #4
0
int
dimeHeaderSection::setVariable(const char * const variableName,
			      const int * const groupcodes,
			      const dimeParam * const params,
			      const int numparams,
			      dimeMemHandler * const memhandler)
{
  int i = findVariable(variableName);
  if (i < 0) {
    i = this->records.count();
    dimeStringRecord *sr = (dimeStringRecord*)dimeRecord::createRecord(9, memhandler);
    if (!sr) return false;
    sr->setString(variableName, memhandler);
    
    this->records.append(sr);
    for (int j = 0; j < numparams; j++) {
      this->records.append(dimeRecord::createRecord(groupcodes[j], memhandler));
    }
  }
  i++;
  int cnt = 0;
  for (int j = 0; j < numparams; j++) {
    int k = i;
    int n = this->records.count();
    while (k < n && this->records[k]->getGroupCode() != groupcodes[j] &&
	   this->records[k]->getGroupCode() != 9) {
      k++;
    }
    if (k < n && this->records[k]->getGroupCode() == groupcodes[j]) {
      cnt++;
      this->records[k]->setValue(params[j]);
    }
  }
  return cnt;
}
Beispiel #5
0
test_results_t test1_8_Mutator::executeTest() 
{
	// Find the entry point to the procedure "test1_8_func1"
	const char *funcName = "test1_8_func1";
	BPatch_Vector<BPatch_function *> found_funcs;

	if ((NULL == appImage->findFunction(funcName, found_funcs))
			|| !found_funcs.size()) 
	{
		logerror("    Unable to find function %s\n", funcName);
		return FAILED;
	}

	if (1 < found_funcs.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs.size(), funcName);
	}

	BPatch_Vector<BPatch_point *> *point8_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point8_1 || ((*point8_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet*> vect8_1;
	const char *globalVar = "test1_8_globalVariable1";
	BPatch_variableExpr *expr8_1 = findVariable(appImage, globalVar,
			point8_1);

	if (!expr8_1) 
	{
		logerror("**Failed** test #3 (passing variables)\n");
		logerror("    Unable to locate variable %s\n", globalVar);
		return FAILED;
	}

	BPatch_arithExpr arith8_1 (BPatch_assign, *expr8_1, 
			BPatch_arithExpr(BPatch_plus, 
				BPatch_arithExpr(BPatch_plus, 
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(81), 
						BPatch_constExpr(82)),
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(83), 
						BPatch_constExpr(84))),
				BPatch_arithExpr(BPatch_plus, 
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(85), 
						BPatch_constExpr(86)),
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(87), 
						BPatch_constExpr(88)))));
	vect8_1.push_back(&arith8_1);

	checkCost(BPatch_sequence(vect8_1));
	if(!appAddrSpace->insertSnippet( BPatch_sequence(vect8_1), *point8_1))
        return FAILED;

	return PASSED;
}
Beispiel #6
0
bool Module::addVariable(const Variable &value) {
	if (findVariable(value.name)) {
		return false;
	}
	variablesByName_.insert(fullNameKey(value.name), variables_.size());
	variables_.push_back(value);
	return true;
}
 inline RexxVariable *find(RexxString *name, size_t index)
 {
     RexxVariable *variable = get(index);
     if (variable == OREF_NULL)
     {
         variable = findVariable(name, index);
     }
     return variable;
 }
Beispiel #8
0
static int doesVariableExist(char* name) {
    struct scope_info * scopeNode=scope;
	while (scopeNode != NULL) {
		unsigned short id=findVariable(scopeNode->variables, name);
		if (id >= 1) return 1;
		scopeNode=scopeNode->next;
	}
	return 0;
}
void
XmlConfig::resolveVariables(std::string &val) const {
	std::smatch res;
	while (std::regex_search(val, res, regex_)) {
		if (2 == res.size()) {
			std::string key(res[1].first, res[1].second);
			val.replace(res.position(static_cast<std::smatch::size_type>(0)), res.length(0), findVariable(key));
		}
	}
}
Beispiel #10
0
bool Sheeve::findVariable(
        const bool recursive,
        const std::string &varName,
        DeclaredVariable::shared_ptr &varDecl)
{
    return findVariable(
                recursive,
                intrusive_ptr(this),
                varName,
                varDecl);
}
    //---------------------------------------------------------------------------------
    AST::INode* SymbolTable::getVariable( const String& name ) const
    {
        SymbolTable::VariableMap::const_iterator it = findVariable(name);
        if ( it != mVariables.end() )
        {
            return it->second;
		}
		
        //variable not found
		return 0;
    }
Beispiel #12
0
// Set new variable at last position of variables array
void CobolWriter::setVariables(int newLevelNumber, string newVariableName, string newDataType, int newNoPics, string newVariableValue)
{

	int position = findVariable(newVariableName);
	noVariables++;
	variables[position].variableName = newVariableName;
	variables[position].variableValue = newVariableValue;
	variables[position].whatDataType = newDataType;
	variables[position].noPics = newNoPics;
	variables[position].levelNumber = newLevelNumber;

}
    //---------------------------------------------------------------------------------
    void SymbolTable::setVariable( const String& name, AST::INode* value )
    {		
		VariableMap::iterator iter = findVariable(name);
		if (iter == mVariables.end())
		{
			mVariables[ name ] = value;
		}
		else
		{
			mVariables[iter->first] = value;
		}
    }
    //---------------------------------------------------------------------------------
    AST::INode* SymbolTable::removeVariable( const String& name )
    {
		SymbolTable::VariableMap::iterator it = findVariable(name);

        if ( it != mVariables.end() )
        {
            AST::INode* node = ( *it ).second;
            mVariables.erase( it );
            return node;
        }

        //variable not found
        return 0;
    }
Beispiel #15
0
/**
 * Retrieves the ID of a variable from the symbol table, with a flag whether we are to allow adding the variable in
 * if it can not be found
 */
static unsigned short getVariableId(char * name, int allowAdd) {
	struct scope_info * scopeNode=scope;
	while (scopeNode != NULL) {
		unsigned short id=findVariable(scopeNode->variables, name);
		if (id >= 1) return id;
		scopeNode=scopeNode->next;
	}

	if (allowAdd) {
		return addVariable(name);
	} else {
		fprintf(stderr, "Can not find variable name %s at line %d, you must declare this before use\n", name, line_num);
		exit(0);
	}
}
Beispiel #16
0
void
XmlConfig::XmlConfigData::resolveVariables(std::string &val) const {
    size_t pos_begin = std::string::npos;
    while(true) {
        pos_begin = val.rfind("${", pos_begin);
        if (pos_begin == std::string::npos) {
            return;
        }
        size_t pos_end = val.find('}', pos_begin);
        std::string name = val.substr(pos_begin + 2, pos_end - pos_begin - 2);
        if (checkVariableName(name)) {
            val.replace(pos_begin, pos_end - pos_begin + 1, findVariable(name));
        }
        else {
            throw std::runtime_error("incorrect variable name format: " + name);
        }
    }
}
Beispiel #17
0
static int genVRelTest(BPatch_image *appImage,
		BPatch_Vector<BPatch_snippet*> &vect7_1, 
		BPatch_relOp op, BPatch_variableExpr *r1, 
		BPatch_variableExpr *r2, const char *var1)
{
	const char *funcName = "test1_7_func2";
	BPatch_Vector<BPatch_function *> found_funcs;

	if ((NULL == appImage->findFunction(funcName, found_funcs)) || !found_funcs.size()) 
	{
		logerror("    Unable to find function %s\n", funcName);
		return -1;
	}

	if (1 < found_funcs.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs.size(), funcName);
	}

	BPatch_Vector<BPatch_point *> *point7_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point7_1 || ((*point7_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return -1;
	}

	BPatch_variableExpr *expr1_1 = findVariable(appImage, var1, point7_1);

	if (!expr1_1) 
	{
		logerror("**Failed** test #7 (relational operators)\n");
		logerror("    Unable to locate variable %s\n", var1);
		return -1;
	}

	BPatch_ifExpr *tempExpr1 = new BPatch_ifExpr(
			BPatch_boolExpr(op, *r1, *r2), 
			BPatch_arithExpr(BPatch_assign, *expr1_1, BPatch_constExpr(74)));
	vect7_1.push_back(tempExpr1);

	return 0;
}
Beispiel #18
0
static Value *idExprInterp(Node *node, void *parser)
{
#ifndef NDEBUG
	assert(node->type == NT_ID_EXPR);
#endif
	IdExpr *e = (IdExpr *)node;
#ifdef LOG_INTERP
	logInterpPrefix(parser);
	rawlog("idExprInterp %s\n", e->val.data);
#endif
	ValueFn fn;
	/* 搜索内置的变量 */
	fn = findVariable(e->val.data);
	if (fn)
		return fn(parser, 0, 0, 0);
	
	/* 搜索公式定义中的变量 */
	return parserFindVariable((Parser *)parser, e->val.data);
}
int CellMLModelDefinition::getInitialValueByIndex(const int type,const int index,double* value)
{
  int code = -1;
  iface::cellml_api::Model* model = static_cast<iface::cellml_api::Model*>(mModel);
  if (!model)
  {
    std::cerr << "CellMLModelDefinition::getInitialValueByIndex -- missing model?" << std::endl;
    return -2;
  }
  RETURN_INTO_OBJREF(var,iface::cellml_api::CellMLVariable,findVariable(model,mAnnotations,type,index));
  if (!var)
  {
    std::cerr << "CellMLModelDefinition::getInitialValueByIndex -- unable to find variable: " << index
        << "; of type: " << type << std::endl;
    return -3;
  }
  RETURN_INTO_WSTRING(iv,var->initialValue());
  if (iv != L"")
  {
    wchar_t* end;
    double v = wcstod(iv.c_str(),&end);
    if (end == NULL || *end != 0)
    {
      std::wcerr << "CellMLModelDefinition::getInitialValueByIndex -- variable: " << index << "; of type:"
          << type << "; has non-numeric initial value: " << iv.c_str() << std::endl;
      code = -5;
    }
    else
    {
      *value = v;
      code = 0;
    }
  }
  else
  {
    std::cerr << "CellMLModelDefinition::getInitialValueByIndex -- variable: " << index << "; of type:"
        << type << "; has no initial value." << std::endl;
    code = -4;
  }
  return code;
}
Beispiel #20
0
void
MSinitClientPrg(Client cntxt, str mod, str nme)
{
	InstrPtr p;
	MalBlkPtr mb;

	if (cntxt->curprg && idcmp(nme, cntxt->curprg->name) == 0) {
		MSresetClientPrg(cntxt);
		return;
	}
	cntxt->curprg = newFunction(putName("user", 4), putName(nme, strlen(nme)), FUNCTIONsymbol);
	mb = cntxt->curprg->def;
	p = getSignature(cntxt->curprg);
	if (mod)
		setModuleId(p, mod);
	else
		setModuleScope(p, cntxt->nspace);
	setVarType(mb, findVariable(mb, nme), TYPE_void);
	insertSymbol(cntxt->nspace, cntxt->curprg);
	cntxt->glb = 0;
	assert(cntxt->curprg->def != NULL);
}
Beispiel #21
0
bool Sheeve::findVariable(
        const bool recursive,
        const Sheeve::intrusive_ptr &sheeve,
        const std::string &varName,
        DeclaredVariable::shared_ptr &varDecl)
{
    DeclaredVariable::SheeveData::const_iterator it = sheeve->variables().find(varName);
    if (it != sheeve->variables().end())
    {
        varDecl = it->second;
        return true;
    }
    if(recursive)
    {
        Sheeve::intrusive_ptr p = sheeve->prev();
        if (p)
        {
            return findVariable(recursive, p, varName, varDecl);
        }
    }
    return false;
}
Beispiel #22
0
test_results_t test1_5_Mutator::executeTest() 
{
	// Find the entry point to the procedure "func5_2"
	const char *funcName = "test1_5_func2";

	BPatch_Vector<BPatch_function *> found_funcs;
	if ((NULL == appImage->findFunction(funcName, found_funcs))
			|| !found_funcs.size()) 
	{
		logerror("    Unable to find function %s\n", funcName);
		return FAILED;
	}

	if (1 < found_funcs.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs.size(), funcName);
	}

	BPatch_Vector<BPatch_point *> *point5_1 = found_funcs[0]->findPoint(BPatch_entry);  

	if (!point5_1 || ((*point5_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return FAILED;
	}

	const char *funcName2 = "test1_5_func1";
	BPatch_Vector<BPatch_function *> found_funcs2;

	if ((NULL == appImage->findFunction(funcName2, found_funcs2))
			|| !found_funcs2.size()) 
	{
		logerror("    Unable to find function %s\n", funcName2);
		return FAILED;
	}

	if (1 < found_funcs2.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs2.size(), funcName2);
	}

	BPatch_Vector<BPatch_point *> *point5_2 = found_funcs2[0]->findPoint(BPatch_subroutine);  

	if (!point5_2 || ((*point5_2).size() == 0)) 
	{
		logerror("Unable to find subroutine call points in \"%s\".\n", funcName2);
		return FAILED;
	}

	const char *globalVar1 = "test1_5_globalVariable5_1";
	const char *globalVar2 = "test1_5_globalVariable5_2";
	BPatch_variableExpr *expr5_1 = findVariable (appImage, globalVar1, point5_1);
	BPatch_variableExpr *expr5_2 = findVariable (appImage, globalVar2, point5_1);

	if (!expr5_1 || !expr5_2) 
	{
		logerror("**Failed** test #5 (1f w.o. else)\n");
		logerror("    Unable to locate variable %s or ", globalVar1);
		logerror("    variable %s\n", globalVar2);
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet*> vect5_1;

	// if (0 == 1) globalVariable5_1 = 52;
	BPatch_ifExpr expr5_3(BPatch_boolExpr(BPatch_eq, BPatch_constExpr(0),
				BPatch_constExpr(1)), 
			BPatch_arithExpr(BPatch_assign, *expr5_1,
				BPatch_constExpr(52)));

	// if (1 == 1) globalVariable5_2 = 53;
	BPatch_ifExpr expr5_4(BPatch_boolExpr(BPatch_eq, BPatch_constExpr(1),
				BPatch_constExpr(1)), 
			BPatch_arithExpr(BPatch_assign, *expr5_2,
				BPatch_constExpr(53)));

	vect5_1.push_back(&expr5_3);
	vect5_1.push_back(&expr5_4);

	BPatch_sequence expr5_5(vect5_1);
	checkCost(expr5_5);
	appAddrSpace->insertSnippet(expr5_5, *point5_1);

	return PASSED;
}
Beispiel #23
0
test_results_t test1_7_Mutator::executeTest() 
{
	// Find the entry point to the procedure "func7_2"
	const char *funcName = "test1_7_func2";
	BPatch_Vector<BPatch_function *> found_funcs;

	if ((NULL == appImage->findFunction(funcName, found_funcs))
			|| !found_funcs.size()) 
	{
		logerror("    Unable to find function %s\n", funcName);
		return FAILED;
	}

	if (1 < found_funcs.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs.size(), funcName);
	}

	BPatch_Vector<BPatch_point *> *point7_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point7_1 || ((*point7_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet*> vect7_1;

	if ( genRelTest(appImage, vect7_1, BPatch_lt, 0, 1,
				"test1_7_globalVariable1") < 0)
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_lt, 1, 0,
				"test1_7_globalVariable2") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_eq, 2, 2,
				"test1_7_globalVariable3") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_eq, 2, 3,
				"test1_7_globalVariable4") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_gt, 4, 3,
				"test1_7_globalVariable5") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_gt, 3, 4,
				"test1_7_globalVariable6") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_le, 3, 4,
				"test1_7_globalVariable7") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_le, 4, 3,
				"test1_7_globalVariable8") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ne, 5, 6,
				"test1_7_globalVariable9") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ne, 5, 5,
				"test1_7_globalVariable10") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ge, 9, 7,
				"test1_7_globalVariable11") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ge, 7, 9,
				"test1_7_globalVariable12") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_and, 1, 1,
				"test1_7_globalVariable13") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_and, 1, 0,
				"test1_7_globalVariable14") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_or, 1, 0,
				"test1_7_globalVariable15") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_or, 0, 0,
				"test1_7_globalVariable16") < 0 )
		return FAILED;

	const char *funcName2 = "test1_7_func2";
	BPatch_Vector<BPatch_function *> found_funcs2;

	if ((NULL == appImage->findFunction(funcName2, found_funcs2))
			|| !found_funcs2.size()) 
	{
		logerror("    Unable to find function %s\n", funcName2);
		return FAILED;
	}

	if (1 < found_funcs2.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs2.size(), funcName2);
	}

	BPatch_Vector<BPatch_point *> *func7_1 = found_funcs2[0]->findPoint(BPatch_entry);

	if (!func7_1 || ((*func7_1).size() == 0)) 
	{
		logerror("Unable to find entry points in \"%s\".\n", funcName2);
		return FAILED;
	}

	BPatch_variableExpr *constVar0, *constVar1, *constVar2, *constVar3, *constVar4, 
						*constVar5, *constVar6, *constVar7, *constVar9;

	constVar0 = findVariable(appImage, "test1_7_constVar0", func7_1);
	constVar1 = findVariable(appImage, "test1_7_constVar1", func7_1);
	constVar2 = findVariable(appImage, "test1_7_constVar2", func7_1);
	constVar3 = findVariable(appImage, "test1_7_constVar3", func7_1);
	constVar4 = findVariable(appImage, "test1_7_constVar4", func7_1);
	constVar5 = findVariable(appImage, "test1_7_constVar5", func7_1);
	constVar6 = findVariable(appImage, "test1_7_constVar6", func7_1);
	constVar7 = findVariable(appImage, "test1_7_constVar7", func7_1);
	constVar9 = findVariable(appImage, "test1_7_constVar9", func7_1);

	if (!constVar0 || !constVar1 || !constVar2 || !constVar3 || !constVar4 ||
			!constVar5 || !constVar6 || !constVar7 || !constVar9 ) 
	{
		logerror("**Failed** test #7 (relational operators)\n");
		logerror("    Unable to locate one of test1_7_constVar?\n");
		return FAILED;
	}

	if ( genVRelTest(appImage, vect7_1, BPatch_lt, constVar0, constVar1,
				"test1_7_globalVariable1a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_lt, constVar1, constVar0,
				"test1_7_globalVariable2a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_eq, constVar2, constVar2,
				"test1_7_globalVariable3a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_eq, constVar2, constVar3,
				"test1_7_globalVariable4a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_gt, constVar4, constVar3,
				"test1_7_globalVariable5a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_gt, constVar3, constVar4,
				"test1_7_globalVariable6a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_le, constVar3, constVar4,
				"test1_7_globalVariable7a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_le, constVar4, constVar3,
				"test1_7_globalVariable8a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ne, constVar5, constVar6,
				"test1_7_globalVariable9a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ne, constVar5, constVar5,
				"test1_7_globalVariable10a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ge, constVar9, constVar7,
				"test1_7_globalVariable11a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ge, constVar7, constVar9,
				"test1_7_globalVariable12a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_and, constVar1, constVar1,
				"test1_7_globalVariable13a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_and, constVar1, constVar0,
				"test1_7_globalVariable14a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_or, constVar1, constVar0,
				"test1_7_globalVariable15a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_or, constVar0, constVar0,
				"test1_7_globalVariable16a") < 0 )
		return FAILED;

	dprintf("relops test vector length is %d\n", vect7_1.size());

	checkCost(BPatch_sequence(vect7_1));
	if(!appAddrSpace->insertSnippet( BPatch_sequence(vect7_1), *point7_1))
        return FAILED;

	return PASSED;
}
Beispiel #24
0
LcnSymbol* IpeEnv::findLocal(const char* name) const
{
  return findVariable(name, true);
}
Beispiel #25
0
LcnSymbol* IpeEnv::findVariable(const char* name) const
{
  return findVariable(name, false);
}
Beispiel #26
0
test_results_t test1_36_Mutator::executeTest() 
{
	const char *funcName = "test1_36_func1";
	BPatch_Vector<BPatch_function *> found_funcs;

	if ((NULL == appImage->findFunction(funcName, found_funcs))
			|| !found_funcs.size()) 
	{
		logerror("    Unable to find function %s\n", funcName);
		return FAILED;
	}

	if (1 < found_funcs.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs.size(), funcName);
	}

	BPatch_Vector<BPatch_point *> *all_points36_1 =
		found_funcs[0]->findPoint(BPatch_subroutine);

	if (!all_points36_1 || (all_points36_1->size() < 1)) 
	{
		logerror("Unable to find point %s - subroutines.\n", funcName);
		return FAILED;
	}

	const char *funcName2 = "test1_36_call1";
	BPatch_point *point36_1 = NULL;

	for (unsigned i=0; i<(*all_points36_1).size(); i++) 
	{
		BPatch_point *cur_point = (*all_points36_1)[i];
		if (cur_point == NULL) 
			continue;

		BPatch_function *func = cur_point->getCalledFunction();
		char funcname[100];

		if (!func) 
			continue;

		if (func->getName(funcname, 99)) 
		{
			if (strstr(funcname, funcName2))
				point36_1 = cur_point;
		}
	}

	if (point36_1 == NULL) 
	{
		logerror("Unable to find callsite %s\n", funcName2);
		return FAILED;
	}

	BPatch_variableExpr *expr36_1 = findVariable(appImage,
			"test1_36_globalVariable1", 
			all_points36_1);
	BPatch_variableExpr *expr36_2 = findVariable(appImage,
			"test1_36_globalVariable2", 
			all_points36_1);
	BPatch_variableExpr *expr36_3 = findVariable(appImage,
			"test1_36_globalVariable3", 
			all_points36_1);
	BPatch_variableExpr *expr36_4 = findVariable(appImage,
			"test1_36_globalVariable4", 
			all_points36_1);
	BPatch_variableExpr *expr36_5 = findVariable(appImage,
			"test1_36_globalVariable5", 
			all_points36_1);
	BPatch_variableExpr *expr36_6 = findVariable(appImage,
			"test1_36_globalVariable6", 
			all_points36_1);
	BPatch_variableExpr *expr36_7 = findVariable(appImage,
			"test1_36_globalVariable7", 
			all_points36_1);
	BPatch_variableExpr *expr36_8 = findVariable(appImage,
			"test1_36_globalVariable8", 
			all_points36_1);
	BPatch_variableExpr *expr36_9 = findVariable(appImage,
			"test1_36_globalVariable9", 
			all_points36_1);
	BPatch_variableExpr *expr36_10 = findVariable(appImage,
			"test1_36_globalVariable10", 
			all_points36_1);

	if (expr36_1 == NULL || expr36_2 == NULL || expr36_3 == NULL ||
			expr36_4 == NULL || expr36_5 == NULL || expr36_6 == NULL ||
			expr36_7 == NULL || expr36_8 == NULL || expr36_9 == NULL ||
			expr36_10 == NULL)
	{
		logerror("**Failed** test #36 (callsite parameter referencing)\n");
		logerror("    Unable to locate at least one of "
				"test1_36_globalVariable{1...10}\n");
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet *> snippet_seq;
	snippet_seq.push_back(makeTest36paramExpr(expr36_1, 0));
	snippet_seq.push_back(makeTest36paramExpr(expr36_2, 1));
	snippet_seq.push_back(makeTest36paramExpr(expr36_3, 2));
	snippet_seq.push_back(makeTest36paramExpr(expr36_4, 3));
	snippet_seq.push_back(makeTest36paramExpr(expr36_5, 4));
	snippet_seq.push_back(makeTest36paramExpr(expr36_6, 5));
	snippet_seq.push_back(makeTest36paramExpr(expr36_7, 6));
	snippet_seq.push_back(makeTest36paramExpr(expr36_8, 7));
	snippet_seq.push_back(makeTest36paramExpr(expr36_9, 8));
	snippet_seq.push_back(makeTest36paramExpr(expr36_10, 9));
	
    BPatch_sequence seqExpr(snippet_seq);

	checkCost(seqExpr);
	appAddrSpace->insertSnippet(seqExpr, *point36_1);

	return PASSED;
}
Beispiel #27
0
test_results_t test1_25_Mutator::executeTest() 
{
	// Used as hack for Fortran to allow assignment of a pointer to an int
	BPatch::bpatch->setTypeChecking (false);

	// First verify that we can find a local variable in test1_25_call1
	const char *funcName = "test1_25_call1";
	BPatch_Vector<BPatch_function *> found_funcs;

	if ((NULL == appImage->findFunction(funcName, found_funcs))
			|| !found_funcs.size()) 
	{
		logerror("    Unable to find function %s\n", funcName);
		return FAILED;
	}

	if (1 < found_funcs.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs.size(), funcName);
	}

	BPatch_Vector<BPatch_point *> *point25_1 = found_funcs[0]->findPoint(BPatch_entry);

	assert(point25_1);
	//    assert(point25_1 && (point25_1->size() == 1));

	BPatch_variableExpr *gvar[8];

	for (int i=1; i <= 7; i++) 
	{
		char name[80];

		sprintf (name, "test1_25_globalVariable%d", i);
		gvar [i] = findVariable (appImage, name, point25_1);

		if (!gvar[i]) 
		{
			logerror("**Failed** test #25 (unary operaors)\n");
			logerror("  can't find variable %s\n", name);
			return FAILED;
		}
	}

	//     globalVariable25_2 = &globalVariable25_1
#if !defined(rs6000_ibm_aix4_1_test) \
	&& !defined(i386_unknown_linux2_0_test) \
	&& !defined(x86_64_unknown_linux2_4_test) /* Blind duplication - Ray */ \
	&& !defined(ppc64_linux_test) \
	&& !defined(i386_unknown_nt4_0_test) \
        && !defined(os_freebsd_test)

	// without type info need to inform
	BPatch_type *type = appImage->findType("void *");
	assert(type);
	gvar[2]->setType(type);
#endif

	BPatch_arithExpr assignment1(BPatch_assign, *gvar[2],
			BPatch_arithExpr(BPatch_addr, *gvar[1]));

	appAddrSpace->insertSnippet(assignment1, *point25_1);

	// 	   globalVariable25_3 = *globalVariable25_2
	//		Need to make sure this happens after the first one
	BPatch_arithExpr assignment2(BPatch_assign, *gvar[3],
			BPatch_arithExpr(BPatch_deref, *gvar[2]));
	appAddrSpace->insertSnippet(assignment2, *point25_1,  BPatch_callBefore,
			BPatch_lastSnippet);

	// 	   globalVariable25_5 = -globalVariable25_4
	BPatch_arithExpr assignment3(BPatch_assign, *gvar[5],
			BPatch_arithExpr(BPatch_negate, *gvar[4]));
	appAddrSpace->insertSnippet(assignment3, *point25_1);

	// 	   globalVariable25_7 = -globalVariable25_6
	BPatch_arithExpr assignment4(BPatch_assign, *gvar[7],
			BPatch_arithExpr(BPatch_negate, *gvar[6]));
	appAddrSpace->insertSnippet(assignment4, *point25_1);

	// Check removed because MIPS is no longer supported
	// #endif // !MIPS

	BPatch::bpatch->setTypeChecking (true);
	return PASSED;
}
Beispiel #28
0
test_results_t test1_3_Mutator::executeTest() 
{
	// Find the entry point to the procedure "func3_1"
	const char *funcName = "test1_3_func3_1";

	BPatch_Vector<BPatch_function *> found_funcs;
	if ((NULL == appImage->findFunction(funcName, found_funcs))
			|| !found_funcs.size()) 
	{
		logerror("    Unable to find function %s\n", funcName);
		return FAILED;
	}

	if (1 < found_funcs.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs.size(), funcName);
	}

	BPatch_Vector<BPatch_point *> *point3_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point3_1 || ((*point3_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s.\"\n", funcName);
		return FAILED;
	}

	BPatch_Vector<BPatch_function *> bpfv;
	const char *fn = "test1_3_call3_1";

	if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
			|| NULL == bpfv[0])
	{
		logerror("    Unable to find function %s\n", fn);
		return FAILED;
	}

	if (1 < bpfv.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, bpfv.size(), fn);
	}

	BPatch_function *call3_func = bpfv[0];

	BPatch_Vector<BPatch_snippet *> call3_args;

	BPatch_Vector<BPatch_point *> *call3_1 = call3_func->findPoint(BPatch_subroutine);

	if (!call3_1 || ((*call3_1).size() == 0)) 
	{
		logerror("    Unable to find subroutine calls in \"call3_1.\"\n");
		return FAILED;
	}

	const char *globalVar = "test1_3_globalVariable3_1";

	BPatch_variableExpr *expr3_1 = findVariable(appImage, globalVar, call3_1);

	if (!expr3_1) 
	{
		logerror("**Failed** test #3 (passing variables)\n");
		logerror("    Unable to locate variable %s\n", globalVar);
		return FAILED;
	}

	// see if we can find the address
	if (expr3_1->getBaseAddr() <= 0) 
	{
		logerror("*Error*: address %p for %s is not valid\n",
				expr3_1->getBaseAddr(), globalVar);
	}

	BPatch_variableExpr *expr3_2 = appAddrSpace->malloc(*appImage->findType("int"));

	if (!expr3_2) 
	{
		logerror("**Failed** test #3 (passing variables)\n");
		logerror("    Unable to create new int variable\n");
		return FAILED;
	}

	BPatch_constExpr expr3_3 (expr3_1->getBaseAddr ());
	BPatch_constExpr expr3_4 (expr3_2->getBaseAddr ());

	int mutateeFortran = isMutateeFortran(appImage);

	if (mutateeFortran) 
	{
		call3_args.push_back (&expr3_3);
		call3_args.push_back (&expr3_4);
	} 
	else 
	{
		call3_args.push_back(expr3_1);
		call3_args.push_back(expr3_2);
	}

	BPatch_funcCallExpr call3Expr(*call3_func, call3_args);
	checkCost(call3Expr);
	appAddrSpace->insertSnippet(call3Expr, *point3_1);

	BPatch_arithExpr expr3_5(BPatch_assign, *expr3_2, BPatch_constExpr(32));
	checkCost(expr3_5);
	appAddrSpace->insertSnippet(expr3_5, *point3_1);

	dprintf("Inserted snippet3\n");

	return PASSED;
}