void CppInliner::inlineCode(const vector<string>& cppFilePaths, const string& outputFilePath) const {
    const string concatStage{pathConcat(temporaryDirectory, "concat.cpp")};
    const string inlinedStage{pathConcat(temporaryDirectory, "inlined.cpp")};

    concatFiles(cppFilePaths, concatStage);

    internal::Inliner inliner{clangCompilationOptions};
    std::string inlinedCode{inliner.doInline(concatStage)};
    removePragmaOnce(inlinedCode, inlinedStage);

    internal::Optimizer optimizer{clangCompilationOptions, macrosToKeep};
    std::string onlyReachableCode{optimizer.doOptimize(inlinedStage)};
    removeEmptyLines(onlyReachableCode, maxConsequentEmptyLines, outputFilePath);
}
Beispiel #2
0
int joinFiles_Ext1 (const char *sourceDir, const char *sourceName,const char *extName)
{
	stJAndSHeader	*joinHdr = NULL;
    FILE	*fileHdl = NULL;
    char	destName[_MAX_DIR],tempName[_MAX_DIR];
    char 	outmode[] = "wb6 ";
    short	nErr;

    // Get memory for the join header structure
    joinHdr=pstrFileNameArr;
    if(joinHdr->numFilesJoined==0)
    {
    	return 1;
    }
    
	errno = EZERO;
	// Generate the destination name
	if (strlen(sourceDir))
		sprintf (destName, "%s\\%s%s", sourceDir, sourceName, extName);
	else
		sprintf (destName, ".\\%s%s", sourceName, extName);

	// Open the join file...
	if ((fileHdl = fopen (destName, "wb")) != NULL)
	{
		// ... and join in all the files.
		writeHeader ( joinHdr, fileHdl);
		concatFiles ( sourceDir, joinHdr, fileHdl);
		fclose (fileHdl);

		// Rename file as a temporary file
		if (strlen(sourceDir))
			sprintf (tempName, "%s\\%s%s", sourceDir, sourceName, ".CAT");
		else
			sprintf (tempName, ".\\%s%s", sourceName, ".CAT");

		rename (destName, tempName);

		// Compress the file @2              
		if ((nErr = file_compress (sourceDir, sourceName, ".CAT", extName,outmode)) != 0)
		{
			String msg = String("Failed to compress ") + sourceName;
            throw std::exception ( msg.c_str() );
			return nErr;
		}
	}
    return errno;
}
Beispiel #3
0
int joinDir(const char *sourceDir, const char *extName)
{
    stJAndSHeader *joinHdr = NULL;
    FILE *fileHdl = NULL;
    char
        destName[_MAX_DIR],
        tempName[_MAX_DIR];
    char outmode[] = "wb6 ";
    short  nErr;

    // Clear any outstanding errors
    errno = EZERO;

    // Get memory for the join header structure
    if ((joinHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL)
    {
        // Populate the header with all the match files
        if (genHeader (sourceDir, "", extName, joinHdr, 1)) //@3 directory
        {
            // Clear any outstanding errors
            errno = EZERO;

            // Generate the destination name
            sprintf (destName, "%s%s", sourceDir, extName);

            // Open the join file...
            if ((fileHdl = fopen (destName, "wb")) != NULL)
            {
                // ... and join in all the files.
                writeHeader ( joinHdr, fileHdl);
                concatFiles ( sourceDir, joinHdr, fileHdl);
                fclose (fileHdl);

                // Rename file as a temporary file
                sprintf (tempName, "%s%s", sourceDir, ".CAT");

                rename (destName, tempName);

                String strDir(sourceDir);
                size_t pos = strDir.find_last_of ( '\\' );
                if ( String::npos == pos )
                    pos = strDir.find_last_of ( '/' );
                String strFolderName = strDir.substr ( pos + 1 );
                String strParentDir = strDir.substr(0, pos);

                // Compress the file @2
                if ( ( nErr = file_compress ( strParentDir.c_str(), strFolderName.c_str(), ".CAT", extName, outmode ) ) != 0 )
                {                    
                    free(joinHdr);
                    String msg = String("Failed to compress ") + tempName;
                    throw std::exception ( msg.c_str() );
                    return nErr;
                }
            }
        }
        free(joinHdr);
        joinHdr = NULL;
    }
    else
        throw std::exception("Insufficient memory");

    // For debugging only
    #ifdef DEBUG_MODE
    printHeader (stdout,joinHdr);
    #endif

    return errno;
}
Beispiel #4
0
/* ========================================================================
PURPOSE :
*/
int joinFiles (const char *sourceDir, const char *sourceName, const char *extName)
{
    stJAndSHeader
        *joinHdr = NULL;
    FILE
        *fileHdl = NULL;
    char
        destName[_MAX_DIR],
        tempName[_MAX_DIR];
    char outmode[] = "wb6 ";
    short
        nErr;

    // Clear any outstanding errors
    errno = EZERO;

    // Get memory for the join header structure
    if ((joinHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL)
    {
        // Populate the header with all the match files
        if (genHeader (sourceDir, sourceName, extName, joinHdr, 0)) //@3 files
        {
            // Clear any outstanding errors
            errno = EZERO;
            // Generate the destination name
            if (strlen(sourceDir))
                sprintf (destName, "%s\\%s%s", sourceDir, sourceName, extName);
            else
                sprintf (destName, ".\\%s%s", sourceName, extName);

            // Open the join file...
            if ((fileHdl = fopen (destName, "wb")) != NULL)
            {
                // ... and join in all the files.
                writeHeader ( joinHdr, fileHdl);
                concatFiles ( sourceDir, joinHdr, fileHdl);
                fclose (fileHdl);

                // Rename file as a temporary file
                if (strlen(sourceDir))
                    sprintf (tempName, "%s\\%s%s", sourceDir, sourceName, ".CAT");
                else
                    sprintf (tempName, ".\\%s%s", sourceName, ".CAT");
                rename (destName, tempName);

                // Compress the file @2
                if ((nErr = file_compress (sourceDir, sourceName, ".CAT", extName, outmode)) != 0)
                {                    
                    free(joinHdr);
                    String msg = String("Failed to compress ") + sourceName;
                    throw std::exception ( msg.c_str() );
                    return nErr;
                }
            }
        }
        free(joinHdr);
        joinHdr = NULL;
    }
    else
        throw std::exception( "Insufficient memory" );

    // For debugging only
    #ifdef DEBUG_MODE
    printHeader (stdout,joinHdr);
    #endif

    return errno;
}