示例#1
0
// Create a new file
File STORAGE::Filesystem::createNewFile(std::string fname) {
	logEvent(EVENT, "Creating file: " + fname);
	if (fname.size() > FileHeader::MAXNAMELEN) {
		fname = std::string(fname, FileHeader::MAXNAMELEN);
	}

	return insertHeader(fname.c_str());
}
AREXPORT ArNetPacket::ArNetPacket(ArTypes::UByte2 bufferSize) :
  ArBasePacket(bufferSize, ArNetPacket::HEADER_LENGTH, NULL, 
	       ArNetPacket::FOOTER_LENGTH),
  myPacketSource(TCP),
  myAddedFooter(false),
  myArbitraryString(),
  myCommand(0)
{
  insertHeader();
}  
AREXPORT void ArNetPacket::finalizePacket(void)
{

  insertHeader();

  int chkSum = calcCheckSum();
  byteToBuf((chkSum >> 8) & 0xff );
  byteToBuf(chkSum & 0xff );
  myAddedFooter = true;
  //log();
  //printf("%d %d %d\n", myLength ,myCommand, chkSum);
}
示例#4
0
文件: main.cpp 项目: ssrg-vt/aira
int main(int argc, char** argv)
{
	//Parse command-line args
	ProgramOptions po(argc, argv);

	//Initialize the AST
	SgProject* project = new SgProject(argc, argv);
	ROSE_ASSERT(project);
	AstTests::runAllTests(project); //TODO switch on/off with command-line args

	//Set the folder containing the features
	string featureFolder = "";
	bool defaultFeatures = po.getFeaturesFolder(featureFolder);
	if(!defaultFeatures)
		CallScheduler::setFeaturesFolder(featureFolder);

	//Loop through all partitioned kernels and add scheduling calls
	Rose_STL_Container<SgNode*> pragmas = querySubTree(project, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::const_iterator pragmaIt = pragmas.begin();
	SgPragmaDeclaration* pragma = NULL;
	SgFunctionDeclaration* funcDecl = NULL;
	SgStatement* stmt = NULL;
	for(pragmaIt = pragmas.begin(); pragmaIt != pragmas.end(); pragmaIt++)
	{
		pragma = isSgPragmaDeclaration(*pragmaIt);
		ROSE_ASSERT(pragma);

		PragmaParser pp(pragma);
		if(pp.isPopcornPragma() && pp.getPragmaType() == PARTITIONED)
		{
			stmt = getNextStatement(pragma);
			while(!isSgFunctionDeclaration(stmt))
				stmt = getNextStatement(pragma);
			funcDecl = isSgFunctionDeclaration(stmt);
			ROSE_ASSERT(funcDecl);
			Pragmas pragmas(funcDecl);

			//Add scheduling calls
			CallScheduler cs(funcDecl, pragmas);
			cs.addSchedulerCalls();

			//Insert the header
			//TODO this won't insert the header into files
			insertHeader(po.getSchedulerHeaderLocation(), PreprocessingInfo::after, false,
					getGlobalScope(funcDecl));
		}
	}

	return backend(project);
}
示例#5
0
int insertHeaders(char **png, sParameterStruct *sSO2Parameters, sConfigStruct *config, int png_length){
	char iso_date[25];
	dateStructToISO8601(sSO2Parameters->timestampBefore, iso_date);
	png_length = insertHeader(png, "Creation Time ",    iso_date, png_length);
	png_length = insertValue(png, "dBufferlength",      (float)config->dBufferlength,      png_length);
	png_length = insertValue(png, "dHistMinInterval",   (float)config->dHistMinInterval,   png_length);
	png_length = insertValue(png, "dHistPercentage",    (float)config->dHistPercentage,    png_length);
	png_length = insertValue(png, "dDarkCurrent",       (float)sSO2Parameters->dDarkCurrent,       png_length);
	png_length = insertValue(png, "dImageCounter",      (float)config->dImageCounter,      png_length);
	png_length = insertValue(png, "dInterFrameDelay",   (float)config->dInterFrameDelay,   png_length);
	png_length = insertValue(png, "dTriggerPulseWidth", (float)sSO2Parameters->dTriggerPulseWidth, png_length);
	png_length = insertValue(png, "dExposureTime",      (float)sSO2Parameters->dExposureTime,      png_length);
	png_length = insertValue(png, "dFixTime",           (float)config->dFixTime,           png_length);

	return png_length;
}
示例#6
0
std::string VertexProgramDecompiler::BuildCode()
{
	std::string main_body;
	for (uint i = 0, lvl = 1; i < m_instr_count; i++)
	{
		lvl -= m_instructions[i].close_scopes;
		if (lvl < 1) lvl = 1;
		//assert(lvl >= 1);
		for (int j = 0; j < m_instructions[i].put_close_scopes; ++j)
		{
			--lvl;
			if (lvl < 1) lvl = 1;
			main_body.append(lvl, '\t') += "}\n";
		}

		for (int j = 0; j < m_instructions[i].do_count; ++j)
		{
			main_body.append(lvl, '\t') += "do\n";
			main_body.append(lvl, '\t') += "{\n";
			lvl++;
		}

		for (uint j = 0; j < m_instructions[i].body.size(); ++j)
		{
			main_body.append(lvl, '\t') += m_instructions[i].body[j] + "\n";
		}

		lvl += m_instructions[i].open_scopes;
	}

	std::stringstream OS;
	insertHeader(OS);

	insertInputs(OS, m_parr.params[PF_PARAM_IN]);
	OS << std::endl;
	insertOutputs(OS, m_parr.params[PF_PARAM_NONE]);
	OS << std::endl;
	insertConstants(OS, m_parr.params[PF_PARAM_UNIFORM]);
	OS << std::endl;

	insertMainStart(OS);
	OS << main_body.c_str() << std::endl;
	insertMainEnd(OS);

	return OS.str();
}
void MakeSmartPtrCheck::checkReset(SourceManager &SM,
                                   const CXXMemberCallExpr *Reset,
                                   const CXXNewExpr *New) {
  const auto *Expr = cast<MemberExpr>(Reset->getCallee());
  SourceLocation OperatorLoc = Expr->getOperatorLoc();
  SourceLocation ResetCallStart = Reset->getExprLoc();
  SourceLocation ExprStart = Expr->getLocStart();
  SourceLocation ExprEnd =
      Lexer::getLocForEndOfToken(Expr->getLocEnd(), 0, SM, getLangOpts());

  bool InMacro = ExprStart.isMacroID();

  if (InMacro && IgnoreMacros) {
    return;
  }

  // There are some cases where we don't have operator ("." or "->") of the
  // "reset" expression, e.g. call "reset()" method directly in the subclass of
  // "std::unique_ptr<>". We skip these cases.
  if (OperatorLoc.isInvalid()) {
    return;
  }

  auto Diag = diag(ResetCallStart, "use %0 instead")
              << MakeSmartPtrFunctionName;

  // Disable the fix in macros.
  if (InMacro) {
    return;
  }

  if (!replaceNew(Diag, New, SM)) {
    return;
  }

  Diag << FixItHint::CreateReplacement(
      CharSourceRange::getCharRange(OperatorLoc, ExprEnd),
      (llvm::Twine(" = ") + MakeSmartPtrFunctionName + "<" +
       GetNewExprName(New, SM, getLangOpts()) + ">")
          .str());

  if (Expr->isArrow())
    Diag << FixItHint::CreateInsertion(ExprStart, "*");

  insertHeader(Diag, SM.getFileID(OperatorLoc));
}
std::string FragmentProgramDecompiler::BuildCode()
{
	//main += fmt::format("\tgl_FragColor = %c0;\n", m_ctrl & 0x40 ? 'r' : 'h');

	std::stringstream OS;
	insertHeader(OS);
	OS << std::endl;
	insertConstants(OS);
	OS << std::endl;
	insertIntputs(OS);
	OS << std::endl;
	insertOutputs(OS);
	OS << std::endl;
	insertMainStart(OS);
	OS << main << std::endl;
	insertMainEnd(OS);

	return OS.str();
}
/*
 * The visit function is reimplemented from AstSimpleProcessing, and is called for every node
 * in the the AST. We are only really interested in looking at function calls to op_par_loop_3.
 */
void OPSource::visit(SgNode *n)
{ 
  SgFile *file = isSgFile(n);
  if(file!=NULL)
  {
  file->set_unparse_includes(false);
  }

  // We need to put the global scope on the scope stack so that we can look
  // up the oplus datatypes later on (in generateSpecial).
  SgGlobal *globalScope = isSgGlobal(n);
  if(globalScope!=NULL)
  {
    pushScopeStack(globalScope);
    
    // Add the global kernel header
    insertHeader("kernels.h", PreprocessingInfo::after, false, globalScope);
  }

  fixParLoops(n);
  fixOpStructs(n);
  fixOpFunctions(n);
}
示例#10
0
文件: page.cpp 项目: JIM-DB/Server
        size_t Page::insert(const rapidjson::GenericValue<rapidjson::UTF8<>>& value)
        {
            tasking::RWLockGuard<> lock(m_rwLock, tasking::WRITE);
            //here we know this page has one chunk big enough to fitt the whole object
            //including its overhead! so start inserting it.

            //get the object name
            std::string name = value.MemberBegin()->name.GetString();

            //returns the pos of the first element needed for the headerdata

            auto firstElementPos = insertObject(value.MemberBegin()->value, nullptr).first;
            auto l_first = dist(m_body, firstElementPos);

            //insert the header
            HeaderMetaData* meta = insertHeader(m_objCount++, 0, common::FNVHash()(name), l_first);
            if (meta == nullptr)
                LOG_DEBUG << "wm";
            //push the obj to obj index
            index::ObjectIndex::getInstance().add(meta->getOID(), index::ObjectIndexValue(this->m_id, dist(m_header, meta)));

            //done!
            return meta->getOID();
        }
void MakeSmartPtrCheck::checkConstruct(SourceManager &SM,
                                       const CXXConstructExpr *Construct,
                                       const QualType *Type,
                                       const CXXNewExpr *New) {
  SourceLocation ConstructCallStart = Construct->getExprLoc();
  bool InMacro = ConstructCallStart.isMacroID();

  if (InMacro && IgnoreMacros) {
    return;
  }

  bool Invalid = false;
  StringRef ExprStr = Lexer::getSourceText(
      CharSourceRange::getCharRange(
          ConstructCallStart, Construct->getParenOrBraceRange().getBegin()),
      SM, getLangOpts(), &Invalid);
  if (Invalid)
    return;

  auto Diag = diag(ConstructCallStart, "use %0 instead")
              << MakeSmartPtrFunctionName;

  // Disable the fix in macros.
  if (InMacro) {
    return;
  }

  if (!replaceNew(Diag, New, SM)) {
    return;
  }

  // Find the location of the template's left angle.
  size_t LAngle = ExprStr.find("<");
  SourceLocation ConstructCallEnd;
  if (LAngle == StringRef::npos) {
    // If the template argument is missing (because it is part of the alias)
    // we have to add it back.
    ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
    Diag << FixItHint::CreateInsertion(
        ConstructCallEnd,
        "<" + GetNewExprName(New, SM, getLangOpts()) + ">");
  } else {
    ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
  }

  Diag << FixItHint::CreateReplacement(
      CharSourceRange::getCharRange(ConstructCallStart, ConstructCallEnd),
      MakeSmartPtrFunctionName);

  // If the smart_ptr is built with brace enclosed direct initialization, use
  // parenthesis instead.
  if (Construct->isListInitialization()) {
    SourceRange BraceRange = Construct->getParenOrBraceRange();
    Diag << FixItHint::CreateReplacement(
        CharSourceRange::getCharRange(
            BraceRange.getBegin(), BraceRange.getBegin().getLocWithOffset(1)),
        "(");
    Diag << FixItHint::CreateReplacement(
        CharSourceRange::getCharRange(BraceRange.getEnd(),
                                      BraceRange.getEnd().getLocWithOffset(1)),
        ")");
  }

  insertHeader(Diag, SM.getFileID(ConstructCallStart));
}
示例#12
0
文件: main.cpp 项目: ssrg-vt/aira
int main(int argc, char** argv)
{
	//Parse command-line options
	ProgramOptions po(argc, argv);

	//Initialize the AST
	SgProject* project = new SgProject(argc, argv);
	ROSE_ASSERT(project);
	AstTests::runAllTests(project); //TODO switch on/off with command-line args

	//Insert MM-wrapper header file
	string mmHeader = po.getMMWrapperHeaderLocation();
	insertHeader(mmHeader, PreprocessingInfo::after, false, getGlobalScope(findMain(project)));

	//Initialize set of system headers & compiler generated vars
	RegisterPointers::initialize();

	//Add calls to registers sizes of static variables
	RegisterVars rv(project, mmHeader);
	rv.registerStaticVars();

	//Used to accumulate all global variables
	set<SgInitializedName*> globalVars;

	//Add wrapper calls to each function/sub-function so that all pointers are registered
	Rose_STL_Container<SgNode*> pragmas = querySubTree(project, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::const_iterator pragmaIt;
	Rose_STL_Container<SgNode*> funcCalls = querySubTree(project, V_SgFunctionCallExp);
	SgPragmaDeclaration* pragma;
	SgStatement* stmt;
	SgFunctionDeclaration* funcDecl;
	for(pragmaIt = pragmas.begin(); pragmaIt != pragmas.end(); pragmaIt++)
	{
		pragma = isSgPragmaDeclaration(*pragmaIt);
		ROSE_ASSERT(pragma);

		PragmaParser pp(pragma);
		if(pp.isPopcornPragma() && pp.getPragmaType() == PARTITIONED)
		{
			//Get function declaration
			stmt = getNextStatement(pragma);
			while(!isSgFunctionDeclaration(stmt))
				stmt = getNextStatement(stmt);
			funcDecl = isSgFunctionDeclaration(stmt);
			ROSE_ASSERT(funcDecl);
			Pragmas pragmas(funcDecl);

			//Save global variables
			saveGlobalVariables(pragmas.getGlobalInputs(), globalVars,
					pragmas.getFunction()->get_scope());
			saveGlobalVariables(pragmas.getGlobalOutputs(), globalVars,
					pragmas.getFunction()->get_scope());

			//Update call sites
			//TODO I don't think we need this anymore, since all sizes are
			//handled through the mm_wrapper interface
			//FunctionCallUpdater fcu(funcDecl, funcCalls);
			//fcu.updateDeclaration();
			//fcu.updateSites();
		}
	}

	//Register/unregister global variables
	RegisterVars::registerGlobalVars(globalVars);

	//Add call to initialize wrapper
	SgFunctionDeclaration* main = findMain(project);
	ROSE_ASSERT(main);
	FunctionCallUpdater::insertInitWrapperCall(main);

	return backend(project);
}
bool CryptFileDevice::open(OpenMode mode)
{
    if (m_device == nullptr)
        return false;

    if (isOpen())
        return false;

    if (mode & WriteOnly)
        mode |= ReadOnly;

    if (mode & Append)
        mode |= ReadWrite;

    OpenMode deviceOpenMode;
    if (mode == ReadOnly)
        deviceOpenMode = ReadOnly;
    else
        deviceOpenMode = ReadWrite;

    if (mode & Truncate)
        deviceOpenMode |= Truncate;

    bool ok;
    if (m_device->isOpen())
        ok = (m_device->openMode() == deviceOpenMode);
    else
        ok = m_device->open(deviceOpenMode);

    if (!ok)
        return false;

    if (m_password.isEmpty())
    {
        setOpenMode(mode);
        return true;
    }

    if (!initCipher())
        return false;

    m_encrypted = true;
    setOpenMode(mode);

    qint64 size = m_device->size();
    if (size == 0 && mode != ReadOnly)
        insertHeader();

    if (size > 0)
    {
        if (!tryParseHeader())
        {
            m_encrypted = false;
            return false;
        }
    }

    if (mode & Append)
        seek(m_device->size() - kHeaderLength);

    return true;
}
示例#14
0
/** Ok push */
void KControlHeader::slotOk()
{
    insertHeader();
    configWrite();
    accept();
}
示例#15
0
int insertValue(char **png, char *name, float value, int png_length)
{
	char text[200];
	sprintf(text, "%s: %f", name, value);
	return insertHeader(png, "Comment ", text, png_length);
}