Esempio n. 1
0
 function parseClusterWP($ast, $name, $header)
 {
     ob_start();
     LibraryManager::Push();
     $res = new GenerationInfo();
     /***************   PROCESS AST   ***************/
     $attr = lookupAttribute(ast_get($ast, NodeKey::PAYLOAD));
     $attrType = $attr->type();
     grokit_assert($attrType->is('clusterable'), 'Attempting to cluster on unclusterable attribute ' . $attr->name());
     /*************** END PROCESS AST ***************/
     // Get our headers
     $myHeaders = $header . PHP_EOL . ob_get_clean();
     $filename = $name . '.cc';
     $res->addFile($filename, $name);
     _startFile($filename);
     ClusterGenerate($name, $attr);
     _endFile($filename, $myHeaders);
     LibraryManager::Pop();
     return $res;
 }
Esempio n. 2
0
function generateMakefile(GenerationInfo $genInfo, $options)
{
    ob_start();
    // Set up directories to copy the sources to and copy them
    $sourcesBaseDir = realpath("../Sources");
    $filesPerJob = $genInfo->filesPerJob();
    foreach ($filesPerJob as $job => $files) {
        $cDir = $sourcesBaseDir . DIRECTORY_SEPARATOR . $job;
        if (!file_exists($cDir)) {
            mkdir($cDir, 0777, true);
        }
        foreach ($files as $file) {
            $cFile = $cDir . DIRECTORY_SEPARATOR . $file;
            copy($file, $cFile);
        }
    }
    // General options
    $generalOptions = getDefault($options, 'general', []);
    $debug = getDefault($generalOptions, 'debug', false);
    // Get C++ Compiler information from options
    $cxxOptions = getDefault($options, 'c++', []);
    $cxxCompiler = getDefault($cxxOptions, 'compiler', 'g++');
    $cxxStandard = getDefault($cxxOptions, 'standard', 'c++11');
    $cxxStdLib = getDefault($cxxOptions, 'stdlib', '');
    $cxxStdLib = \strlen($cxxStdLib) > 0 ? "-stdlib={$cxxStdLib}" : '';
    $flags = getDefault($cxxOptions, 'flags', ['-fPIC', '-g', '-D_FILE_OFFSET_BITS=64', '-DDEBUG']);
    $cxxFlags = implode(' ', $flags);
    $linkFlags = implode(' ', getDefault($cxxOptions, 'linkflags', []));
    $opts = getDefault($cxxOptions, 'optimizations', ['-O3', '-march=native', '-ffast-math']);
    $cxxOpts = $debug ? '-Wall' : implode(' ', $opts);
    $includePaths = explode(':', getenv('GROKIT_HEADER_PATH'));
    $cxxIncludeFlags = implode(' ', array_map(function ($val) {
        return '-I ' . $val;
    }, $includePaths));
    // Get needed information from genInfo
    $ccFiles = $genInfo->files();
    $oFiles = array_map(function ($val) {
        // Replace ending .cc with .o
        return replaceExtension($val, '.cc', '.o');
    }, $ccFiles);
    $libs = $genInfo->libs();
    $cxxLibs = implode(' ', array_map(function ($val) {
        return '-l' . $val;
    }, $libs));
    ?>
CXX             := <?php 
    echo $cxxCompiler;
    ?>

CXXOPTS         := <?php 
    echo $cxxOpts;
    ?>

CXXFLAGS        := -std=<?php 
    echo $cxxStandard;
    ?>
 <?php 
    echo $cxxStdLib;
    ?>
 <?php 
    echo $cxxFlags;
    ?>

CXXINCLUDE      := <?php 
    echo $cxxIncludeFlags;
    ?>

CXXLIBS         := <?php 
    echo $cxxLibs;
    ?>

CXXLINKFLAGS    := <?php 
    echo $linkFlags;
    ?>

# If CPUPROFILE set, link with gperftools CPU profiler
ifdef CPUPROFILE
CXXLIBS += -lprofiler
endif

Generated.so: <?php 
    echo implode(' ', $oFiles);
    ?>

	$(CXX) -rdynamic -shared -o Generated.so $(CXXFLAGS) $(CXXOPTS) <?php 
    echo implode(' ', $oFiles);
    ?>
 $(CXXLINKFLAGS) $(CXXLIBS)

clean:
	rm <?php 
    echo implode(' ', $oFiles);
    ?>

<?php 
    foreach ($ccFiles as $ccFile) {
        $oFile = replaceExtension($ccFile, '.cc', '.o');
        echo $oFile;
        ?>
 : <?php 
        echo $ccFile;
        ?>

	$(CXX) $(CXXFLAGS) $(CXXOPTS) $(CXXINCLUDE) -c <?php 
        echo $ccFile;
        ?>
 -o <?php 
        echo $oFile;
        ?>


<?php 
    }
    // end foreach ccFile
    file_put_contents('./Makefile', ob_get_clean());
}