예제 #1
0
/* Constructor reads symbol table entries beginning at entry 'i'. We can't pass an array of COFFSymbolEntry_disk structs
 * because the disk size is 18 bytes, which is not properly aligned according to the C standard. Therefore we pass the actual
 * section and table index. The symbol occupies the specified table slot and st_num_aux_entries additional slots. */
void
SgAsmCoffSymbol::ctor(SgAsmPEFileHeader *fhdr, SgAsmGenericSection *symtab, SgAsmGenericSection *strtab, size_t idx)
{
    static const bool debug = false;
    COFFSymbol_disk disk;
    symtab->read_content_local(idx * COFFSymbol_disk_size, &disk, COFFSymbol_disk_size);
    if (disk.st_zero == 0) {
        p_st_name_offset = ByteOrder::le_to_host(disk.st_offset);
        if (p_st_name_offset < 4) throw FormatError("name collides with size field");
        std::string s = strtab->read_content_local_str(p_st_name_offset);
        set_name(new SgAsmBasicString(s));
    } else {
        char temp[9];
        memcpy(temp, disk.st_name, 8);
        temp[8] = '\0';
        set_name(new SgAsmBasicString(temp));
        p_st_name_offset = 0;
    }

    p_st_name            = get_name()->get_string();
    p_st_section_num     = ByteOrder::le_to_host(disk.st_section_num);
    p_st_type            = ByteOrder::le_to_host(disk.st_type);
    p_st_storage_class   = ByteOrder::le_to_host(disk.st_storage_class);
    p_st_num_aux_entries = ByteOrder::le_to_host(disk.st_num_aux_entries);

    /* Bind to section number. We can do this now because we've already parsed the PE Section Table */
    ROSE_ASSERT(fhdr->get_section_table()!=NULL);
    if (p_st_section_num > 0) {
        p_bound = fhdr->get_file()->get_section_by_id(p_st_section_num);
        ROSE_ASSERT(p_bound != NULL);
    }
    
    /* Make initial guesses for storage class, type, and definition state. We'll adjust them after reading aux entries. */
    p_value = ByteOrder::le_to_host(disk.st_value);
    p_def_state = SYM_DEFINED;
    switch (p_st_storage_class) {
      case 0:    p_binding = SYM_NO_BINDING; break; /*none*/
      case 1:    p_binding = SYM_LOCAL;      break; /*stack*/
      case 2:    p_binding = SYM_GLOBAL;     break; /*extern*/
      case 3:    p_binding = SYM_GLOBAL;     break; /*static*/
      case 4:    p_binding = SYM_LOCAL;      break; /*register*/
      case 5:    p_binding = SYM_GLOBAL;     break; /*extern def*/
      case 6:    p_binding = SYM_LOCAL;      break; /*label*/
      case 7:    p_binding = SYM_LOCAL;      break; /*label(undef)*/
      case 8:    p_binding = SYM_LOCAL;      break; /*struct member*/
      case 9:    p_binding = SYM_LOCAL;      break; /*formal arg*/
      case 10:   p_binding = SYM_LOCAL;      break; /*struct tag*/
      case 11:   p_binding = SYM_LOCAL;      break; /*union member*/
      case 12:   p_binding = SYM_GLOBAL;     break; /*union tag*/
      case 13:   p_binding = SYM_GLOBAL;     break; /*typedef*/
      case 14:   p_binding = SYM_GLOBAL;     break; /*static(undef)*/
      case 15:   p_binding = SYM_GLOBAL;     break; /*enum tag*/
      case 16:   p_binding = SYM_LOCAL;      break; /*enum member*/
      case 17:   p_binding = SYM_GLOBAL;     break; /*register param*/
      case 18:   p_binding = SYM_LOCAL;      break; /*bit field*/
      case 100:  p_binding = SYM_GLOBAL;     break; /*block(bb or eb)*/
      case 101:  p_binding = SYM_GLOBAL;     break; /*function*/
      case 102:  p_binding = SYM_LOCAL;      break; /*struct end*/
      case 103:  p_binding = SYM_GLOBAL;     break; /*file*/
      case 104:  p_binding = SYM_GLOBAL;     break; /*section*/
      case 105:  p_binding = SYM_WEAK;       break; /*weak extern*/
      case 107:  p_binding = SYM_LOCAL;      break; /*CLR token*/
      case 0xff: p_binding = SYM_GLOBAL;     break; /*end of function*/
    }
    switch (p_st_type & 0xf0) {
      case 0x00: p_type = SYM_NO_TYPE; break;     /*none*/
      case 0x10: p_type = SYM_DATA;    break;     /*ptr*/
      case 0x20: p_type = SYM_FUNC;    break;     /*function*/
      case 0x30: p_type = SYM_ARRAY;   break;     /*array*/
    }
    
    /* Read additional aux entries. We keep this as 'char' to avoid alignment problems. */
    if (p_st_num_aux_entries > 0) {
        p_aux_data = symtab->read_content_local_ucl((idx+1)*COFFSymbol_disk_size, p_st_num_aux_entries * COFFSymbol_disk_size);

        if (get_type() == SYM_FUNC && p_st_section_num > 0) {
            /* Function */
            unsigned bf_idx      = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[0]));
            unsigned size        = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[4]));
            unsigned lnum_ptr    = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[8]));
            unsigned next_fn_idx = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[12]));
            unsigned res1        = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[16]));
            set_size(size);
            if (debug) {
                fprintf(stderr, "COFF aux func %s: bf_idx=%u, size=%u, lnum_ptr=%u, next_fn_idx=%u, res1=%u\n", 
                        escapeString(p_st_name).c_str(), bf_idx, size, lnum_ptr, next_fn_idx, res1);
            }
            
        } else if (p_st_storage_class == 101 /*function*/ && (0 == p_st_name.compare(".bf") || 0 == p_st_name.compare(".ef"))) {
            /* Beginning/End of function */
            unsigned res1        = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[0]));
            unsigned lnum        = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[4])); /*line num within source file*/
            unsigned res2        = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[6]));
            unsigned res3        = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[8]));
            unsigned next_bf     = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[12])); /*only for .bf; reserved in .ef*/
            unsigned res4        = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[16]));
            if (debug) {
                fprintf(stderr, "COFF aux %s: res1=%u, lnum=%u, res2=%u, res3=%u, next_bf=%u, res4=%u\n", 
                        escapeString(p_st_name).c_str(), res1, lnum, res2, res3, next_bf, res4);
            }
            
        } else if (p_st_storage_class == 2/*external*/ && p_st_section_num == 0/*undef*/ && get_value()==0) {
            /* Weak External */
            unsigned sym2_idx    = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[0]));
            unsigned flags       = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[4]));
            unsigned res1        = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[8]));
            unsigned res2        = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[12]));
            unsigned res3        = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[16]));
            if (debug) {
                fprintf(stderr, "COFF aux weak %s: sym2_idx=%u, flags=%u, res1=%u, res2=%u, res3=%u\n",
                        escapeString(p_st_name).c_str(), sym2_idx, flags, res1, res2, res3);
            }
            
        } else if (p_st_storage_class == 103/*file*/ && 0 == p_st_name.compare(".file")) {
            /* This symbol is a file. The file name is stored in the aux data as either the name itself or an offset
             * into the string table. Replace the fake ".file" with the real file name. */
            const COFFSymbol_disk *d = (const COFFSymbol_disk*) &(p_aux_data[0]);
            if (0 == d->st_zero) {
                rose_addr_t fname_offset = ByteOrder::le_to_host(d->st_offset);
                if (fname_offset < 4) throw FormatError("name collides with size field");
                set_name(new SgAsmBasicString(strtab->read_content_local_str(fname_offset)));
                if (debug) {
                    fprintf(stderr, "COFF aux file: offset=%"PRIu64", name=\"%s\"\n",
                            fname_offset, get_name()->get_string(true).c_str());
                }
            } else {
                /* Aux data contains a NUL-padded name; the NULs (if any) are not part of the name. */
                ROSE_ASSERT(p_st_num_aux_entries == 1);
                char fname[COFFSymbol_disk_size+1];
                memcpy(fname, &(p_aux_data[0]), COFFSymbol_disk_size);
                fname[COFFSymbol_disk_size] = '\0';
                set_name(new SgAsmBasicString(fname));
                if (debug)
                    fprintf(stderr, "COFF aux file: inline-name=\"%s\"\n", get_name()->get_string(true).c_str());
            }
            set_type(SYM_FILE);

        } else if (p_st_storage_class == 3/*static*/ && NULL != fhdr->get_file()->get_section_by_name(p_st_name, '$')) {
            /* Section */
            unsigned size         = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[0])); /*same as section header SizeOfRawData */
            unsigned nrel         = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[4])); /*number of relocations*/
            unsigned nln_ents     = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[6])); /*number of line number entries */
            unsigned cksum        = ByteOrder::le_to_host(*(uint32_t*)&(p_aux_data[8]));
            unsigned sect_id      = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[12])); /*1-base index into section table*/
            unsigned comdat       = p_aux_data[14]; /*comdat selection number if section is a COMDAT section*/
            unsigned res1         = p_aux_data[15];
            unsigned res2         = ByteOrder::le_to_host(*(uint16_t*)&(p_aux_data[16]));
            set_size(size);
            set_type(SYM_SECTION);
            if (debug) {
                fprintf(stderr, 
                        "COFF aux section: size=%u, nrel=%u, nln_ents=%u, cksum=%u, sect_id=%u, comdat=%u, res1=%u, res2=%u\n", 
                        size, nrel, nln_ents, cksum, sect_id, comdat, res1, res2);
            }
            
        } else if (p_st_storage_class==3/*static*/ && (p_st_type & 0xf)==0/*null*/ &&
                   get_value()==0 && NULL!=fhdr->get_file()->get_section_by_name(p_st_name)) {
            /* COMDAT section */
            /*FIXME: not implemented yet*/
            fprintf(stderr, "COFF aux comdat %s: (FIXME) not implemented yet\n", escapeString(p_st_name).c_str());
            hexdump(stderr, (rose_addr_t) symtab->get_offset()+(idx+1)*COFFSymbol_disk_size, "    ", p_aux_data);

        } else {
            fprintf(stderr, "COFF aux unknown %s: (FIXME) st_storage_class=%u, st_type=0x%02x, st_section_num=%d\n", 
                    escapeString(p_st_name).c_str(), p_st_storage_class, p_st_type, p_st_section_num);
            hexdump(stderr, symtab->get_offset()+(idx+1)*COFFSymbol_disk_size, "    ", p_aux_data);
        }
    }

}
예제 #2
0
 SPRAY::TypeSize TypeSizeMapping::getTypeSize(BuiltInType bitype) {
   ROSE_ASSERT(bitype<_mapping.size());
   return _mapping[bitype];
 }
예제 #3
0
 std::size_t TypeSizeMapping::sizeOfOp(BuiltInType bitype) {
   ROSE_ASSERT(bitype<_mapping.size());
   return getTypeSize(bitype);
 }
예제 #4
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string getSgUnaryOp(SgUnaryOp* unaryOp) {
	std::string unaryOpString;
	VariantT var = unaryOp->variantT();
	switch (var) {
		case V_SgAddressOfOp:
			std::cout << "SgAddressOfOp not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgBitComplementOp:
			std::cout << "SgBitComplementOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgCastExp:
			{
			SgExpression* casted = unaryOp->get_operand();
			unaryOpString = getSgExpressionString(casted);
			break;
			}
		case V_SgConjugateOp:
			std::cout << "SgConjugateOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgExpressionRoot:
			std::cout << "SgExpressionRoot is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgImagPartOp:
			std::cout << "SgImagPartOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgMinusMinusOp:
			std::cout << "SgMinusMinusOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgMinusOp:
			{
			SgExpression* operand = unaryOp->get_operand();
			std::string toMinus = getSgExpressionString(operand);
			std::string minusedExp;
			minusedExp = "(- " + toMinus + ")";
			unaryOpString = minusedExp;
			break;
			}
		case V_SgNotOp:
			std::cout << "SgNotOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgPlusPlusOp:
			std::cout << "SgPlusPlusOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgPointerDerefExp:
			std::cout << "SgPointerDerefExp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgRealPartOp:
			std::cout << "SgRealPartOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgThrowOp:
			std::cout << "SgThrowOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgUnaryAddOp:
			std::cout << "SgUnaryAddOp is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		case V_SgUserDefinedUnaryOp:
			std::cout << "SgUserDefinedUnaryOp is not yet implemented";
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		default:
			std::cout << "Unknown unary op! " << unaryOp->class_name() << std::endl;
			ROSE_ASSERT(false);
			unaryOpString = "";
			break;
		}
	return unaryOpString;
} 
예제 #5
0
 void TypeSizeMapping::setTypeSize(BuiltInType bitype, SPRAY::TypeSize size) {
   ROSE_ASSERT(bitype<_mapping.size());
   _mapping[bitype]=size;
 }
예제 #6
0
//! Dump a CFG with only interesting nodes for a SgNode
void interestingCfgToDot (SgNode* start, const std::string& file_name)
{
  ROSE_ASSERT (start != NULL);
  ofstream ofile (file_name.c_str(), ios::out);
  cfgToDot(ofile, "defaultName", makeInterestingCfg(start));
}
예제 #7
0
  void instr(SgGlobal* global) {

    // Create the lock and key variables in global scope.
    // In main:
    // EnterScope();
    // lock = getTopLock();
    // key = getTopKey();
    // .... rest of main
    // ExitScope();
    // return;
    // FIXME: Add case where we handle arbitrary exits from main
    // This can be handled similar to the way returns are handled
    // for basic blocks.

    SgScopeStatement* scope = isSgScopeStatement(global);

    // Insert lock and key variables at the top of the global scope
    // lock variable
    std::cout << "VarCounter: " << Util::VarCounter << std::endl;
    SgName lock_name("lock_var" + boost::lexical_cast<std::string>(Util::VarCounter));
    SgVariableDeclaration* lock_var = Util::createLocalVariable(lock_name, getLockType(), NULL, scope);
    // Add declaration at the top of the scope
    scope->prepend_statement(lock_var);

    // key variable
    // **** IMPORTANT: Using same counter value for lock and key
    SgName key_name("key_var" + boost::lexical_cast<std::string>(Util::VarCounter));
    Util::VarCounter++;
    SgVariableDeclaration* key_var = Util::createLocalVariable(key_name, getKeyType(), NULL, scope);
    // Insert this key decl after the lock decl
    SI::insertStatementAfter(lock_var, key_var);


    // Now, find the main function and insert...
    // EnterScope();
    // lock = getTopLock();
    // key = getTopKey();
    // .... rest of main
    // ExitScope()
    // return; -- this already exists...
    // see FIXME above

    // find main function...
    SgFunctionDeclaration* MainFn = SI::findMain(global);
    if(!MainFn) {
#ifdef HANDLE_GLOBAL_SCOPE_DEBUG
      printf("Can't find Main function. Not inserting Global Enter and Exit Scopes\n");
#endif
      return;
    }

    SgBasicBlock *bb = Util::getBBForFn(MainFn);

    // insert EnterScope()
#if 0
    SgExpression* overload = buildOverloadFn("EnterScope", NULL, NULL, SgTypeVoid::createType(), scope,
        GEFD(bb));
#endif
    SgExpression* overload = buildMultArgOverloadFn("EnterScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope,
        GEFD(bb));

    SgStatement* enter_scope = SB::buildExprStatement(overload);
    Util::insertAtTopOfBB(bb, enter_scope);

    // insert lock = getTopLock();
    //overload = buildOverloadFn("getTopLock", NULL, NULL, getLockType(), scope, GEFD(bb));
    overload = buildMultArgOverloadFn("getTopLock", SB::buildExprListExp(), getLockType(), scope, GEFD(bb));
    //SgStatement* lock_assign = SB::buildExprStatement(SB::buildAssignOp(SB::buildVarRefExp(lock_var), overload));
    //SI::insertStatementAfter(enter_scope, lock_assign); //RMM COMMENTED OUT

    // insert key = getTopKey();
    // overload = buildOverloadFn("getTopKey", NULL, NULL, getKeyType(), scope, GEFD(bb));
    overload = buildMultArgOverloadFn("getTopKey", SB::buildExprListExp(), getKeyType(), scope, GEFD(bb));
    //SgStatement* key_assign = SB::buildExprStatement(SB::buildAssignOp(SB::buildVarRefExp(key_var), overload));
    //SI::insertStatementAfter(lock_assign, key_assign); //RMM COMMENTED OUT

    // add to scope -> lock and key map... SLKM
    LockKeyPair lock_key = std::make_pair(lock_var, key_var);
    scopeLockMap[scope] = lock_key;

    ROSE_ASSERT(existsInSLKM(scope));

    // Insert ExitScope if last stmt is not return.
    SgStatementPtrList& stmts = bb->get_statements();
    SgStatementPtrList::iterator it = stmts.begin();
    it += (stmts.size() - 1);

    // A little iffy on the scope part here... lets check that.
    if(!isSgReturnStmt(*it)) {
      // Last statement is not return. So, add exit scope...
      // If its a break/continue statement, insert statement before,
      // otherwise, add exit_scope afterwards.
      //SgExpression* overload = buildOverloadFn("ExitScope", NULL, NULL, SgTypeVoid::createType(), scope, GEFD(bb));
      SgExpression* overload = buildMultArgOverloadFn("ExitScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope, GEFD(bb));

      // check if its break/continue
      if(isSgBreakStmt(*it) || isSgContinueStmt(*it)) {
        SI::insertStatementBefore(*it, SB::buildExprStatement(overload));
      }
      else {
        SI::insertStatementAfter(*it, SB::buildExprStatement(overload));
      }
    }

  }
예제 #8
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
void getSgScopeStatement(SgScopeStatement* scopeStat) {
	VariantT var = scopeStat->variantT();
	std::string scopeStatStr = "";
	switch (var) {
		case V_SgBasicBlock:
			{
			getSgBasicBlock(isSgBasicBlock(scopeStat));
			break;
			}

		case V_SgCatchOptionStmt:
			{
			std::cout << "SgCatchOptionStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgDoWhileStmt:
			{
			std::cout << "SgDoWhileStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgForStatement:
			{
		//	std::cout << "SgForStatement is not yet implemented" << std::endl;
			#ifdef FORLOOPONCETHROUGH
			forOnceThrough(isSgForStatement(scopeStat));
				
			
			#else
			std::cout << "SgForStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			#endif
			break;
			}

		case V_SgGlobal:
			{
			std::cout << "SgGlobal is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgIfStmt:
			{
			getSgIfStmt(isSgIfStmt(scopeStat));
			break;
			}

		case V_SgSwitchStatement:
			{
			std::cout << "SgSwitchStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgWhileStmt:
			{
			std::cout << "SgWhileStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgForAllStatement:

			{
			std::cout << "SgForAllStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAssociateStatement:

			{
			std::cout << "SgAssociateStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgBlockDataStatement:

			{
			std::cout << "SgBlockDataStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNamespaceDefinitionStatement:

			{
			std::cout << "SgNamespaceDefinitionStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgClassDefinition:
			{
			std::cout << "SgClassDefinition should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFunctionDefinition:
			{
			getSgFunctionDefinition(isSgFunctionDefinition(scopeStat));
			break;
			}

		case V_SgCAFWithTeamStatement:
			{
			std::cout << "SgCAFWithTeamStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFortranDo:
			{
			std::cout << "SgFortranDo should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFortranNonblockedDo:
			{
			std::cout << "SgFortranNonblockedDo should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgJavaForEachStatement:
			{
			std::cout << "SgJavaForEachStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgJavaLabelStatement:
			{
			std::cout << "SgJavaLabelStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgUpcForAllStatement:
			{
			std::cout << "SgUpcForAllStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		default:
			{
			std::cout << " Unknown node type!: " << scopeStat->class_name() << std::endl;
			ROSE_ASSERT(false);
			}
	}
	return;
}
예제 #9
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
void getSgDeclarationStatement(SgDeclarationStatement* declStat) {
	VariantT var = declStat->variantT();
	std::string declStatStr = "";
	switch (var) {
		case V_SgEnumDeclaration:
			{
			SgEnumDeclaration* enum_decl = isSgEnumDeclaration(declStat);
			std::string enum_str_name = enum_decl->get_name().getString();
                        std::cout << ";enum_str_name = " << enum_str_name << std::endl;
                        if (enums_defined.find(enum_str_name) == enums_defined.end()) {
                                std::cout << ";enum not yet defined" << std::endl;
                                std::string enum_name = enum_decl->get_name().getString();
                                std::stringstream enum_z3;
                                enum_z3 << "(declare-datatypes () ((" << enum_name;
                                SgInitializedNamePtrList enumerated_values = enum_decl->get_enumerators();
                                for (SgInitializedNamePtrList::iterator j = enumerated_values.begin(); j != enumerated_values.end(); j++) {
                                        SgName enum_value_name = (*j)->get_name();
                                        enum_z3 << " " << enum_value_name.getString();
                                }
                                enum_z3 << ")))";
                                std::cout << enum_z3.str() << std::endl;
                                enums_defined[enum_str_name] = enum_z3.str();
                        }
			break;
			}

		case V_SgFunctionParameterList:
			{
			std::cout << "SgFunctionParameterList is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgTypedefDeclaration:
			{
			std::cout << "SgTypedefDeclaration is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgVariableDeclaration:
			{
			SgVariableDeclaration* varDecl = isSgVariableDeclaration(declStat);
			SgInitializedName* nam = SageInterface::getFirstInitializedName(varDecl);
		/*	SgInitializedNamePtrList list = varDecl->get_variables();
			std::stringstream declStatStrStream;
			int checkOne = 0;
			for (SgInitializedNamePtrList::iterator i = list.begin(); i != list.end(); i++) {
				if (checkOne == 1) {
					std::cout << "InitializedNamePtrList should have only one InitializedName" << std::endl;
					ROSE_ASSERT(false);
				}
				SgInitializedName* ithName = isSgInitializedName(*i);
				declStatStrStream << getSgInitializedName(*i) << "\n";
				checkOne++;
			}
		*/
			declStatStr = getSgInitializedName(nam) + "\n";

			break;
			}

		case V_SgVariableDefinition:
			{
			std::cout << "SgVariableDefinition is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAttributeSpecificationStatement:

			{
			std::cout << "SgAttributeSpecificationStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgCommonBlock:

			{
			std::cout << "SgCommonBlock is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgEquivalenceStatement:

			{
			std::cout << "SgEquivalenceStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgImplicitStatement:

			{
			std::cout << "SgImplicitStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNamelistStatement:

			{
			std::cout << "SgNamelistStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNamespaceDeclarationStatement:

			{
			std::cout << "SgNamespaceDeclarationStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgTemplateInstantiationDirectiveStatement:

			{
			std::cout << "SgTemplateInstantiationDirectiveStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgUsingDeclarationStatement:

			{
			std::cout << "SgUsingDeclarationStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgUsingDirectiveStatement:

			{
			std::cout << "SgUsingDirectiveStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgClassDeclaration:
			{
			std::cout << "SgClassDeclaration should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgContainsStatement:
			{
			std::cout << "SgContainsStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFunctionDeclaration:
			{
			std::cout << "SgFunctionDeclaration should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgTemplateDeclaration:
			{
			std::cout << "SgTemplateDeclaration should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAsmStmt:
			{
			std::cout << "SgAsmStmt should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgC_PreprocessorDirectiveStatement:
			{
			std::cout << "SgC_PreprocessorDirectiveStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgClinkageDeclarationStatement:
			{
			std::cout << "SgClinkageDeclarationStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgCtorInitializerList:
			{
			std::cout << "SgCtorInitializerList should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFormatStatement:
			{
			std::cout << "SgFormatStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFortranIncludeLine:
			{
			std::cout << "SgFortranIncludeLine should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgImportStatement:
			{
			std::cout << "SgImportStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgInterfaceStatement:
			{
			std::cout << "SgInterfaceStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgJavaImportStatement:
			{
			std::cout << "SgJavaImportStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNamespaceAliasDeclarationStatement:
			{
			std::cout << "SgNamespaceAliasDeclarationStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgStmtDeclarationStatement:
			{
			std::cout << "SgStmtDeclarationStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgUseStatement:
			{
			std::cout << "SgUseStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgPragmaDeclaration:
			{
					
			//std::cout << "pragmas skipped" << std::endl;
		//	declStatStr=";;pragma\n";
			break;
			}	
		default:
			{
			std::cout << " Unknown node type!: " << declStat->class_name() << std::endl;
			ROSE_ASSERT(false);
			}
	}
	declarations.push_back(declStatStr);
	return;
}
예제 #10
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string writeSgBinaryOpZ3(SgBinaryOp* op, SgExpression* lhs, SgExpression* rhs) {
	
	std::stringstream ss;
	std::string opStr;
	bool compAssign = false;
	if (isSgCompoundAssignOp(op)) {
		compAssign = true;
		opStr = getSgCompoundAssignOp(isSgCompoundAssignOp(op));
	
	}
	else {
		opStr = getSgBinaryOp(op);
	}
	ROSE_ASSERT(opStr != "unknown");
	std::string rhsstring;
	std::string lhsstring;
	lhsstring = getSgExpressionString(lhs);
	SgType* lhstyp;
	SgType* rhstyp;
	if (isSgArrayType(lhs->get_type())) {
	lhstyp = isSgArrayType(lhs->get_type())->get_base_type();	
	}
	else {
	lhstyp = lhs->get_type();
	}
	if (isSgArrayType(rhs->get_type())) {
	rhstyp = isSgArrayType(rhs->get_type())->get_base_type();
	}
	else {
	rhstyp = rhs->get_type();
	}
	if (isSgEnumType(lhs->get_type())) {
	}
	else {	
	ROSE_ASSERT(lhstyp == rhstyp);
	}	
	if (isSgValueExp(rhs)) {
		rhsstring = getSgValueExp(isSgValueExp(rhs));
	}
	else if (isSgUnaryOp(rhs)) {	
		rhsstring = getSgUnaryOp(isSgUnaryOp(rhs));
	}
		
	else {
		rhsstring = getSgExpressionString(rhs);
	}
	if (opStr == "/" && lhstyp->isIntegerType()) {
		opStr = "cdiv";
	} 
	if (opStr == "assign" || compAssign) {
		if (isSgVarRefExp(lhs)) {
		SgVarRefExp* lhsSgVarRefExp = isSgVarRefExp(lhs);
		int instances = SymbolToInstances[lhsSgVarRefExp->get_symbol()];
		std::stringstream instanceName;
		SymbolToInstances[lhsSgVarRefExp->get_symbol()] = instances + 1;
		std::string lhsname = SymbolToZ3[lhsSgVarRefExp->get_symbol()];
		instanceName << lhsname << "_" << (instances+1);
		SgType* varType = lhsSgVarRefExp->get_type();
		std::string typeZ3;
		if (varType->isFloatType()) {
			typeZ3 = "Real";
		}
		else if (varType->isIntegerType()) {
			typeZ3 = "Int";
		}
		else if (isSgEnumType(varType)) {
			typeZ3 = isSgEnumType(varType)->get_name().getString();
		}
		else {
			typeZ3 = "Unknown";
		}
		ss << "(declare-fun " << instanceName.str() << " () " << typeZ3 << ")\n";
		if (!compAssign) {  		
			ss << "(assert (= " << instanceName.str() << " " << rhsstring << "))";
		}
		else {
			std::stringstream oldInstanceName;
			oldInstanceName << lhsname << "_" << instances;
			ss << "(assert (= " << instanceName.str() << " (" << opStr << " " << oldInstanceName.str() << " " << rhsstring << ")))"; 
		}
		}
		
		else {
			ROSE_ASSERT(isSgPntrArrRefExp(lhs));
			std::string u_type;
			SgPntrArrRefExp* lhspntr = isSgPntrArrRefExp(lhs);
			SgVarRefExp* varlhspntr = isSgVarRefExp(lhspntr->get_lhs_operand());
			SgArrayType* arrTy = isSgArrayType(varlhspntr->get_type());
			if (arrTy->get_base_type()->isIntegerType()) {
				u_type = "Int";
			}
			else if (arrTy->get_base_type()->isFloatType()) {
				u_type = "Real";
			}
			else {
				std::cout << "unknown base type for array" << std::endl;
				ROSE_ASSERT(false);
			}
			std::stringstream oldInstanceName;
			SgVarRefExp* varexp = isSgVarRefExp((isSgPntrArrRefExp(lhs))->get_lhs_operand());
			oldInstanceName << SymbolToZ3[varexp->get_symbol()] << "_" << SymbolToInstances[varexp->get_symbol()];	
			int instances = SymbolToInstances[varexp->get_symbol()];
                	std::stringstream instanceName;
                	SymbolToInstances[varexp->get_symbol()] = instances + 1;
                	std::string lhsname = SymbolToZ3[varexp->get_symbol()];
                	instanceName << lhsname << "_" << instances+1;
			ss << "(declare-const " << instanceName.str() << " (Array Int " << u_type << "))\n ";	
			std::string indexstring = getSgExpressionString(isSgPntrArrRefExp(lhs)->get_rhs_operand());	
			ss << "(assert (= (store " << oldInstanceName.str() << " " << indexstring << " " << rhsstring << ") " << instanceName.str() << "))";
		}
	}	
	else if (opStr == "neq") {
	ss << "(not (= " << lhsstring << " " << rhsstring << "))";
	}
	else if (opStr == "or" || opStr == "and") {
		std::stringstream val_stream;	
		if (pathNodeTruthValue.find(op) != pathNodeTruthValue.end()) {
		bool logic_val = pathNodeTruthValue[op];
		//std::cout << ";and/or lhsstring " << lhsstring << "\n";
		//std::cout << ";and/or rhsstring " << rhsstring << "\n";
		if (opStr == "and") {
				
			if (logic_val) {
			
				std::string p_decl = "(assert (= " + lhsstring + " true))";
				declarations.push_back(p_decl);
				ss << rhsstring;
				//ss << "(and " << lhsstring << " " << rhsstring << ")";

			}
			else {
				std::string p_decl = "(assert (= " + lhsstring + " false))";
				declarations.push_back(p_decl);
				ss << "false";	
			}
		}
		else {
			if (logic_val) {
				std::string p_decl = "(assert (= " + lhsstring + " true))";
				declarations.push_back(p_decl);
				ss << "true"; 
			}
			else {
				std::string p_decl = "(assert (= " + lhsstring + " false))";
				declarations.push_back(p_decl);
				ss << rhsstring;
			}
		}
	}
	else {
		ss << "";
	}
	}
	else {	
	ss << "(" << opStr << " " << lhsstring << " " << rhsstring << ")";
	}
	return ss.str();
}
예제 #11
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string getSgInitializedName(SgInitializedName* initName) {
	std::string exprStr;
	SgSymbol* initNameSym = initName->search_for_symbol_from_symbol_table();
	std::string varInit = initializeVariable(initName);
	std::string retString;
	if (initName->get_initptr() != NULL) {
		SgInitializer* nameInitializer = initName->get_initializer();

	        VariantT var = nameInitializer->variantT();
        
		switch (var) {
                	case V_SgAggregateInitializer:
			{
				SgAggregateInitializer* aggInit = isSgAggregateInitializer(nameInitializer);
				if (!isSgArrayType(aggInit->get_type())) {
					std::cout << "currently only arrays use aggregate initializers, you are using " << aggInit->class_name() << std::endl;
					ROSE_ASSERT(false);
				}
				SgExprListExp* members = aggInit->get_initializers();
				SgExpressionPtrList member_expressions = members->get_expressions();
				std::string symName = SymbolToZ3[initNameSym];
				ROSE_ASSERT(SymbolToInstances[initNameSym] == 0);
				int arrmem = 0;
				std::stringstream exprStream;
				for (SgExpressionPtrList::iterator i = member_expressions.begin(); i != member_expressions.end(); i++) {
			
			exprStream << "\n(assert (= (select " << symName << "_0 "  << arrmem << ") " << getSgExpressionString((isSgAssignInitializer((*i))->get_operand())) << ")";
				arrmem = arrmem+1;
				}
                       		retString = varInit + "\n" + exprStream.str(); 
				#ifdef ARRAY_TEST
				std::cout << "retString: " << retString << std::endl;
				#endif
			
			break;
			}
			case V_SgCompoundInitializer:
			{	
			std::cout << "SgCompoundInitializer not yet supported" << std::endl;
			ROSE_ASSERT(false);
			break;
			}
			case V_SgConstructorInitializer:
			{
			std::cout << "SgConstructorInitializer is not yet supported" << std::endl;
			ROSE_ASSERT(false);
			break;
			}
			case V_SgDesignatedInitializer:
			{
			std::cout << "SgDesignatedInitializer is not yet supported" << std::endl;
			ROSE_ASSERT(false);
			break;
			}
			case V_SgAssignInitializer:
			{
			SgAssignInitializer* assignInit = isSgAssignInitializer(nameInitializer);
			std::string symName = SymbolToZ3[initNameSym];
			ROSE_ASSERT(SymbolToInstances[initNameSym] == 0);
			exprStr = "(assert (= " + symName + "_0 " + getSgExpressionString(assignInit->get_operand()) + "))";
			retString = varInit + "\n" + exprStr;
			break;
			}
			default:
			{
			std::cout << "unknown initializer of type: " << nameInitializer->class_name() << std::endl;
			ROSE_ASSERT(false);
			break;
			}
	}
			
		
	}		
	else {
		retString = varInit;
	}
	
	return retString;
}
예제 #12
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string getSgExpressionString(SgExpression* expNode) {
	//bool returnString = false;
	std::string expString;
	bool set_to_expression_val = false;
	VariantT var = expNode->variantT();
	if (isSgBinaryOp(expNode)) {
		SgBinaryOp* binOp = isSgBinaryOp(expNode);
		SgExpression* lhs_exp = binOp->get_lhs_operand();
		SgExpression* rhs_exp = binOp->get_rhs_operand();
		expString = writeSgBinaryOpZ3(binOp, lhs_exp, rhs_exp);
		if (isSgAssignOp(binOp) || isSgCompoundAssignOp(binOp)) {
			declarations.push_back(expString);
			expString = "";
		}
		else if (isSgEqualityOp(binOp) || isSgGreaterThanOp(binOp) || isSgGreaterOrEqualOp(binOp) || isSgLessThanOp(binOp) || isSgLessOrEqualOp(binOp) || isSgNotEqualOp(binOp) || isSgAndOp(binOp) || isSgOrOp(binOp)) {
		
		//set_to_expression_val = true;
		
		}
	}
	else if (isSgUnaryOp(expNode)) {
		expString = getSgUnaryOp(isSgUnaryOp(expNode));
	}
	else if (isSgValueExp(expNode)) {
		expString = getSgValueExp(isSgValueExp(expNode));
	}
	else {
	switch (var) {
		case V_SgCallExpression:
			std::cout << "SgCallExpression not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgClassNameRefExp:
			std::cout << "SgClassNameRefExp not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgConditionalExp:
			std::cout << "SgConditionalExp (trinary A ? B : C) not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;		
		case V_SgExprListExp:
			std::cout << "SgExprListExp is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgFunctionRefExp:
			std::cout << "SgFunctionRefExp is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgDeleteExp:
			std::cout << "SgDeleteExp is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgInitializer:
			std::cout << "SgInitializer is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgNaryOp:
			std::cout << "SgNaryOp is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgNewExp:
			std::cout << "SgNewExp is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgNullExpression:
		
			expString = "; null expression";
			break;
		case V_SgRefExp:
			std::cout << "SgRefExp is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgSizeOfOp:
			std::cout << "SgSizeOfOp is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgStatementExpression:
			std::cout << "SgStatementExpression is not yet implemented" << std::endl;
			expString = "";
			ROSE_ASSERT(false);
			break;
		case V_SgValueExp:
			std::cout << "V_SgValueExp should never be encountered" << std::endl;
			ROSE_ASSERT(false);
			expString = "";
			break;
			
		case V_SgVarRefExp:
			expString = getSgVarRefExp(isSgVarRefExp(expNode));
			break;
		default:
			std::cout << expNode->class_name() << " is not being considered for implementation";
			expString = "";
			#ifndef VERBOSE_COMPLETE
			ROSE_ASSERT(false);
			#endif
		}
		}
			
		/*if (set_to_expression_val) {
		std::stringstream exp_var;
		exp_var << "e_" << expression_count;
		expression_count++;
		
		std::string exp_var_decl = "(declare-const " + exp_var.str() + " Bool)";
		variables.push_back(exp_var_decl);
		std::string exp_var_val = "(assert (= " + exp_var.str() + " " + expString + "))";	
		expressions.push_back(exp_var_val);	
return exp_var.str();
		}
		else {
			return expString;
		}*/
		return expString;
	}
예제 #13
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string initializeVariable(SgInitializedName* initName) {
	//if array type we need to get the index expression
	std::string index_expression_string;
	std::stringstream nameStringStream;
	SgName initNameName = initName->get_qualified_name();
	SgSymbol* initNameSym = initName->search_for_symbol_from_symbol_table();
	if (variablesOfNameX.find(initNameName.getString()) == variablesOfNameX.end()) {
		nameStringStream << initNameName.getString() << "_0";
		variablesOfNameX[initNameName.getString()] = 1;
	}
	else {
		int occurrence = variablesOfNameX[initNameName.getString()];
		nameStringStream << initNameName.getString() << "_" << occurrence;
		variablesOfNameX[initNameName.getString()] = occurrence+1;
	}
	SymbolToZ3[initNameSym] = nameStringStream.str();
	SymbolToInstances[initNameSym] = 0;
	SgType* initNameType = initName->get_type();
	std::string typeZ3;
	if (initNameType->isIntegerType()) {
		typeZ3 = "Int";
	}
	else if (initNameType->isFloatType()) {
		typeZ3 = "Real";
	}
	else if (isSgArrayType(initNameType)) {
		SgArrayType* arrTyp = isSgArrayType(initNameType);
		ROSE_ASSERT(arrTyp != NULL);
		SgType* underlying_type = arrTyp->get_base_type();
		std::string array_typeZ3;
		if (underlying_type->isIntegerType()) {
			array_typeZ3 = "Int";
		}
		else if (underlying_type->isFloatType()) {
			array_typeZ3 = "Real";
		}
		else {
			std::cout << "unknown underlying type of array!" << std::endl;
			std::cout << underlying_type->class_name() << std::endl;
			ROSE_ASSERT(false);
		}
		SgExpression* ind = arrTyp->get_index();
		std::stringstream arrStr;
		index_expression_string = getSgExpressionString(ind);
		typeZ3 = "(Array Int " + array_typeZ3 + ")";
	}
	else if (isSgClassType(initNameType)) {
		
		std::cout << "structs are not yet implemented" << std::endl;
		ROSE_ASSERT(false);
	}
	else if (isSgPointerType(initNameType)) {
		std::cout << "pointers are not yet implemented" << std::endl;
		ROSE_ASSERT(false);
	}
	else if (isSgEnumType(initNameType)) {
		SgEnumType* et = isSgEnumType(initNameType);
		SgEnumDeclaration* enum_d = isSgEnumDeclaration(et->getAssociatedDeclaration());
		getSgDeclarationStatement(enum_d);	
		typeZ3 = et->get_name().getString(); 
	}
	else {
		std::cout << "unknown type: " << initNameType->class_name() << std::endl;
		ROSE_ASSERT(false);
	}		
	std::string name = nameStringStream.str() + "_0";
	std::stringstream streamZ3;
	if (isSgArrayType(initNameType)) {
	streamZ3 << "(declare-const " << name << " " << typeZ3 << ")";
	streamZ3 << "\n(declare-fun " << name << "_len () Int)";
	streamZ3 << "\n(assert (= " << name << "_len " << index_expression_string << "))"; 	
	#ifdef ARRAY_TEST
	std::cout << "arrStream: " << streamZ3.str() << std::endl;
	#endif

	}
	else if (isSgEnumType(initNameType)) {
		streamZ3 << "(declare-const " << name << " " << typeZ3 << ")";
	}
	else {
	streamZ3 << "(declare-fun " << name << " () " << typeZ3 << ")";
	}
	return streamZ3.str();
}
예제 #14
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string getSgCompoundAssignOp(SgCompoundAssignOp* node) {
        VariantT var = node->variantT();
        std::string opStr = "";
        switch (var) {
                case V_SgAndAssignOp:
                        {
                        std::cout << "SgAndAssignOp is not yet implemented" << std::endl;
                        ROSE_ASSERT(false);
                        break;
                        }
                
                case V_SgDivAssignOp:
                        {
			opStr = "/";
                        //std::cout << "SgDivAssignOp is not yet implemented" << std::endl;
                        //ROSE_ASSERT(false);
                        break;
                        }
                
                case V_SgIntegerDivideAssignOp:
                        {
			opStr = "cdiv";
                        break;
                        }
                
                case V_SgMinusAssignOp:
                        {
			opStr = "-";
                        break;
                        }
                
                case V_SgModAssignOp:
                        {
			opStr = "cmod";
                        break;
                        }
                
                case V_SgMultAssignOp:
                        {
			opStr = "*";
                        break;
                        }
                
                case V_SgPlusAssignOp:
                        {
			opStr = "+";
                        break;
                        }
                
                case V_SgExponentiationAssignOp:
                        
                        {
                        std::cout << "SgExponentiationAssignOp is not yet implemented" << std::endl; ;
                        ROSE_ASSERT(false);
                        break;
                        }
                
                case V_SgIorAssignOp:
                        
                        {
                        std::cout << "SgIorAssignOp is not yet implemented" << std::endl; ;
                        ROSE_ASSERT(false);
                        break;
                        }

                case V_SgLshiftAssignOp:

                        {
                        std::cout << "SgLshiftAssignOp is not yet implemented" << std::endl; ;
                        ROSE_ASSERT(false);
                        break;
                        }

                case V_SgRshiftAssignOp:

                        {
                        std::cout << "SgRshiftAssignOp is not yet implemented" << std::endl; ;
                        ROSE_ASSERT(false);
                        break;
                        }

                case V_SgXorAssignOp:

                        {
                        std::cout << "SgXorAssignOp is not yet implemented" << std::endl; ;
                        ROSE_ASSERT(false);
                        break;
                        }

                case V_SgJavaUnsignedRshiftAssignOp:
                        {
                        std::cout << "SgJavaUnsignedRshiftAssignOp should not be found here! " << std::endl;
                        ROSE_ASSERT(false);
                        break;
                        }

                default:
                        {
                        std::cout << " Unknown node type!: " << node->class_name() << std::endl;
                        ROSE_ASSERT(false);
                        }
        }
        return(opStr);
}
예제 #15
0
/* Helper for unparsePowerpcExpression(SgAsmExpression*) */
static std::string unparsePowerpcExpression(SgAsmExpression* expr, const AsmUnparser::LabelMap *labels,
                                            const RegisterDictionary *registers, bool useHex) {
    std::string result = "";
    if (expr == NULL) return "BOGUS:NULL";
    switch (expr->variantT()) {
        case V_SgAsmBinaryAdd:
            result = unparsePowerpcExpression(isSgAsmBinaryExpression(expr)->get_lhs(), labels, registers, false) + " + " +
                     unparsePowerpcExpression(isSgAsmBinaryExpression(expr)->get_rhs(), labels, registers, false);
            break;
        case V_SgAsmMemoryReferenceExpression: {
            SgAsmMemoryReferenceExpression* mr = isSgAsmMemoryReferenceExpression(expr);
            SgAsmExpression* addr = mr->get_address();
            switch (addr->variantT()) {
                case V_SgAsmBinaryAdd: {
                    SgAsmBinaryAdd* a = isSgAsmBinaryAdd(addr);
                    std::string lhs = unparsePowerpcExpression(a->get_lhs(), labels, registers, false);
                    if (isSgAsmValueExpression(a->get_rhs())) {
                        // Sign-extend from 16 bits
                        SgAsmValueExpression *ve = isSgAsmValueExpression(a->get_rhs());
                        assert(ve!=NULL);
                        result = boost::lexical_cast<std::string>(
                                   (int64_t)IntegerOps::signExtend<16, 64>(SageInterface::getAsmConstant(ve)));
                        result += "(" + lhs + ")";
                    } else {
                        result = lhs + ", " + unparsePowerpcExpression(a->get_rhs(), labels, registers, false);
                    }
                    break;
                }
                default:
                    result = "(" + unparsePowerpcExpression(addr, labels, registers, false) + ")";
                    break;
            }
            break;
        }
        case V_SgAsmPowerpcRegisterReferenceExpression: {
            SgAsmPowerpcRegisterReferenceExpression* rr = isSgAsmPowerpcRegisterReferenceExpression(expr);
            result = unparsePowerpcRegister(rr->get_descriptor(), registers);
            break;
        }
        case V_SgAsmIntegerValueExpression: {
            uint64_t v = isSgAsmIntegerValueExpression(expr)->get_absolute_value();
            if (useHex) {
                result = StringUtility::intToHex(v);
            } else {
                result = StringUtility::numberToString(v);
            }
            if (labels) {
                AsmUnparser::LabelMap::const_iterator li = labels->find(v);
                if (li!=labels->end())
                    result = StringUtility::appendAsmComment(result, li->second);
            }
            break;
        }
        default: {
            std::cerr << "Unhandled expression kind " << expr->class_name() << std::endl;
            ROSE_ASSERT (false);
        }
    }
    result = StringUtility::appendAsmComment(result, expr->get_replacement());
    return result;
}
예제 #16
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string getSgIOStatement(SgIOStatement* ioStat) {
	std::cout << "io statements are not implemented yet" << std::endl;
	ROSE_ASSERT(false);
	return "";
}
예제 #17
0
/** Returns a string for the part of the assembly instruction before the first operand. */
std::string unparsePowerpcMnemonic(SgAsmPowerpcInstruction *insn) {
    ROSE_ASSERT(insn!=NULL);
    return insn->get_mnemonic();
}
예제 #18
0
파일: smtQueryLib.cpp 프로젝트: 8l/rose
std::string getSgStatement(SgStatement* stat) {
	VariantT var = stat->variantT();
	std::string statStr = "";
	if (isSgDeclarationStatement(stat)) {
		getSgDeclarationStatement(isSgDeclarationStatement(stat));
	}
	else if (isSgScopeStatement(stat)) {
		getSgScopeStatement(isSgScopeStatement(stat));
	}
	else if (isSgIOStatement(stat)) {
		statStr = getSgIOStatement(isSgIOStatement(stat));
	}
	else {
	switch (var) {
		case V_SgAllocateStatement:
			{
			std::cout << "SgAllocateStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgArithmeticIfStatement:
			{
			std::cout << "SgArithmeticIfStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAssertStmt:
			{
			std::cout << "SgAssertStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAssignedGotoStatement:
			{
			std::cout << "SgAssignedGotoStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAssignStatement:
			{
			std::cout << "SgAssignStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgBreakStmt:
			{
			std::cout << "SgBreakStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgCaseOptionStmt:
			{
			std::cout << "SgCaseOptionStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgCatchStatementSeq:
			{
			std::cout << "SgCatchStatementSeq is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgComputedGotoStatement:
			{
			std::cout << "SgComputedGotoStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgContinueStmt:
			{
			std::cout << "SgContinueStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgDeallocateStatement:
			{
			std::cout << "SgDeallocateStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgDefaultOptionStmt:
			{
			std::cout << "SgDefaultOptionStmt is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgExprStatement:
			{
			statStr = getSgExprStatement(isSgExprStatement(stat));
			break;
			}

		case V_SgForInitStatement:
			{
			std::cout << "SgForInitStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFunctionTypeTable:
			{
			std::cout << "SgFunctionTypeTable is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgGotoStatement:
			{
			std::cout << "SgGotoStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgLabelStatement:
			{
			std::cout << "SgLabelStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgReturnStmt:
			{
			SgReturnStmt* ret = isSgReturnStmt(stat);
			SgExpression* retExp = ret->get_expression();
			std::string retExpStr = getSgExpressionString(retExp);
			statStr = "; return statement not yet linked to function\n ;" + retExpStr + "\n";	
			break;
			}

		case V_SgSequenceStatement:

			{
			std::cout << "SgSequenceStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgPassStatement:

			{
			std::cout << "SgPassStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNullStatement:

			{
			std::cout << "SgNullStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNullifyStatement:

			{
			std::cout << "SgNullifyStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgExecStatement:

			{
			std::cout << "SgExecStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgElseWhereStatement:

			{
			std::cout << "SgElseWhereStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgScopeStatement:
			{
			std::cout << "SgScopeStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgDeclarationStatement:
			{
			std::cout << "SgDeclarationStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgIOStatement:
			{
			std::cout << "SgIOStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgJavaThrowStatement:
			{
			std::cout << "SgJavaThrowStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgJavaSynchronizedStatement:
			{
			std::cout << "SgJavaSynchronizedStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgOmpBarrierStatement:
			{
			std::cout << "SgOmpBarrierStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgOmpBodyStatement:
			{
			std::cout << "SgOmpBodyStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgOmpFlushStatement:
			{
			std::cout << "SgOmpFlushStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgOmpTaskwaitStatement:
			{
			std::cout << "SgOmpTaskwaitStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		default:
			std::cout << "unknown SgStatement type!: " << stat->class_name() << std::endl;
			ROSE_ASSERT(false);		
	}
	}
	return statStr;
}
예제 #19
0
 //dump the full dot graph of a virtual control flow graph starting from SgNode (start)
 void cfgToDotForDebugging(SgNode* start, const std::string& file_name)
 {
   ROSE_ASSERT (start != NULL);
   ofstream ofile (file_name.c_str(), ios::out);
   cfgToDotForDebugging(ofile, "defaultName", start->cfgForBeginning());
 }  
예제 #20
0
int
main( int argc, char* argv[] )
   {
  // Initialize and check compatibility. See rose::initialize
     ROSE_INITIALIZE;

     SgProject* project = frontend(argc,argv);
     AstTests::runAllTests(project);

#if 0
  // Output the graph so that we can see the whole AST graph, for debugging.
     generateAstGraph(project, 4000);
#endif
#if 1
     printf ("Generate the dot output of the SAGE III AST \n");
     generateDOT ( *project );
     printf ("DONE: Generate the dot output of the SAGE III AST \n");
#endif

  // There are lots of way to write this, this is one simple approach; get all the function calls.
     std::vector<SgNode*> functionCalls = NodeQuery::querySubTree (project,V_SgFunctionCallExp);

  // Find the SgFunctionSymbol for snprintf so that we can reset references to "sprintf" to "snprintf" instead.
  // SgGlobal* globalScope = (*project)[0]->get_globalScope();
     SgSourceFile* sourceFile = isSgSourceFile(project->get_fileList()[0]);
     ROSE_ASSERT(sourceFile != NULL);
     SgGlobal* globalScope = sourceFile->get_globalScope();
     SgFunctionSymbol* snprintf_functionSymbol = globalScope->lookup_function_symbol("snprintf");
     ROSE_ASSERT(snprintf_functionSymbol != NULL);

  // Iterate over the function calls to find the calls to "sprintf"
     for (unsigned long i = 0; i < functionCalls.size(); i++)
        {
          SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(functionCalls[i]);
          ROSE_ASSERT(functionCallExp != NULL);

          SgFunctionRefExp* functionRefExp = isSgFunctionRefExp(functionCallExp->get_function());
          if (functionRefExp != NULL)
             {
               SgFunctionSymbol* functionSymbol = functionRefExp->get_symbol();
               if (functionSymbol != NULL)
                  {
                    SgName functionName = functionSymbol->get_name();
                 // printf ("Function being called: %s \n",functionName.str());
                    if (functionName == "sprintf")
                       {
                      // Now we have something to do!
                         functionRefExp->set_symbol(snprintf_functionSymbol);

                      // Now add the "n" argument
                         SgExprListExp* functionArguments = functionCallExp->get_args();
                         SgExpressionPtrList & functionArgumentList = functionArguments->get_expressions();

                      // "sprintf" shuld have exactly 2 arguments (I guess the "..." don't count)
                         printf ("functionArgumentList.size() = %zu \n",functionArgumentList.size());
                      // ROSE_ASSERT(functionArgumentList.size() == 2);
                         SgExpressionPtrList::iterator i = functionArgumentList.begin();

                      // printf ("(*i) = %p = %s = %s \n",*i,(*i)->class_name().c_str(),SageInterface::get_name(*i).c_str());
                         SgVarRefExp* variableRefExp = isSgVarRefExp(*i);
                         ROSE_ASSERT(variableRefExp != NULL);

                      // printf ("variableRefExp->get_type() = %p = %s = %s \n",variableRefExp->get_type(),variableRefExp->get_type()->class_name().c_str(),SageInterface::get_name(variableRefExp->get_type()).c_str());

                         SgType* bufferType = variableRefExp->get_type();
                         SgExpression* bufferLengthExpression = NULL;
                         switch(bufferType->variantT())
                            {
                              case V_SgArrayType:
                                 {
                                   SgArrayType* arrayType = isSgArrayType(bufferType);
                                   bufferLengthExpression = arrayType->get_index();
                                   break;
                                 }

                              case V_SgPointerType:
                                 {
                                // SgPointerType* pointerType = isSgPointerType(bufferType);
                                   SgInitializedName* variableDeclaration = variableRefExp->get_symbol()->get_declaration();
                                   ROSE_ASSERT(variableDeclaration != NULL);
                                   SgExpression* initializer = variableDeclaration->get_initializer();
                                   if (initializer != NULL)
                                      {
                                        SgAssignInitializer* assignmentInitializer = isSgAssignInitializer(initializer);
                                        ROSE_ASSERT(assignmentInitializer != NULL);

                                     // This is the rhs of the initialization of the pointer (likely a malloc through a cast).
                                     // This assumes: buffer = (char*) malloc(bufferLengthExpression);
                                        SgExpression* initializationExpression = assignmentInitializer->get_operand();
                                        ROSE_ASSERT(initializationExpression != NULL);
                                        SgCastExp* castExp = isSgCastExp(initializationExpression);
                                        ROSE_ASSERT(castExp != NULL);
                                        SgFunctionCallExp* functionCall = isSgFunctionCallExp(castExp->get_operand());
                                        ROSE_ASSERT(functionCall != NULL);
                                        SgExprListExp* functionArguments = isSgExprListExp(functionCall->get_args());
                                        bufferLengthExpression = functionArguments->get_expressions()[0];
                                        ROSE_ASSERT(bufferLengthExpression != NULL);
                                      }
                                     else
                                      {
                                        printf ("Initializer not found, so no value for n in snprintf can be computed currently \n");
                                      }
                                   break;
                                 }

                              default:
                                 {
                                   printf ("Error: default reached in evaluation of buffer type = %p = %s \n",bufferType,bufferType->class_name().c_str());
                                   ROSE_ASSERT(false);
                                 }
                            }

                         ROSE_ASSERT(bufferLengthExpression != NULL);

                      // printf ("bufferLengthExpression = %p = %s = %s \n",bufferLengthExpression,bufferLengthExpression->class_name().c_str(),SageInterface::get_name(bufferLengthExpression).c_str());

                      // Jump over the first argument, the "n" is defined to be the 2nd argument (the rest are shifted one position).
                         i++;

                      // Build a deep copy of the expression used to define the static buffer (could be any complex expression).
                         SgTreeCopy copy_help;
                         SgExpression* bufferLengthExpression_copy = isSgExpression(bufferLengthExpression->copy(copy_help));

                      // Insert the "n" for the parameter list to work with "snprintf" instead of "sprintf"
                         functionArgumentList.insert(i,bufferLengthExpression_copy);
                       }
                  }
             }
        }

     return backend(project);
   }