Exemple #1
0
 def generate(self, path, sources, cppflags="", ldflags=""):
     """ create a Makefile with additional flags if given """
     mk="SOURCES="+" ".join(sources)+"\n"+\
         self.headers+"\n"+\
         "CPPFLAGS+="+cppflags+"\n"+\
         "LDFLAGS+="+ldflags+"\n"+\
         self.rules
     return os.path.basename(
         pypsutils.string2file(mk, os.path.join(path, self.makefile))), []
        def generate(self, path, sources, cppflags="", ldflags=""):
            newsources = []
            for fname in sources:
                #change the includes
                filestring = pypsutils.file2string(os.path.join(path, fname))
                filestring = re.sub('#include "' + simd_h + '"',
                                    '#include "' + driver.hfile + '"',
                                    filestring)
                newcfile = "sac_" + fname
                pypsutils.string2file(filestring, os.path.join(path, newcfile))
                newsources.append(newcfile)
            #create symlink .h file
            hpath = os.path.join(path, driver.hfile)
            if not os.path.exists(hpath):
                shutil.copy(pypsutils.get_runtimefile(driver.hfile, "sac"),
                            hpath)

            makefile, others = super(C, self).generate(path, newsources,
                                                       cppflags, ldflags)
            return makefile, others + newsources + [driver.hfile]
Exemple #3
0
 def _set_code(self, newcode):
     """set module content from a string"""
     if not self.compilation_unit_p():
         (code_rc, _) = self.__prepare_modification()
         pypsutils.string2file(newcode, code_rc)
    def save(self, rep=None):
        """Add $driver.h, which replaces general purpose SIMD instructions
        with machine-specific ones."""
        if rep == None:
            rep = self.tmpdirname

        (files, headers) = super(workspace, self).save(rep)

        #run gen_simd_zeros on every file
        for file in files:
            with open(file, 'r') as f:
                read_data = f.read()
            read_data = gen_simd_zeros(read_data)
            with open(file, 'w') as f:
                f.write(read_data)

        # Generate SIMD.h according to the register width
        # thanks to gcc -E and cproto (ugly, need something
        # better)
        simd_h_fname = os.path.abspath(rep + "/SIMD.h")
        simd_c_fname = os.path.abspath(rep + "/SIMD.c")
        p = subprocess.Popen("gcc -DRWBITS=%d -E %s |cproto" %
                             (self.driver.register_width, simd_c_fname),
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        (simd_cus_header, serr) = p.communicate()
        if p.returncode != 0:
            raise RuntimeError(
                "Error while creating SIMD.h: command returned %d.\nstdout:\n%s\nstderr:\n%s\n"
                % (p.returncode, simd_cus_header, serr))

        p = subprocess.Popen("gcc -DRWBITS=%d -E %s |cproto" %
                             (self.driver.register_width, self.simd_c),
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        (simdz_cus_header, serr) = p.communicate()
        if p.returncode != 0:
            raise RuntimeError(
                "Error while creating SIMD.h: command returned %d.\nstdout:\n%s\nstderr:\n%s\n"
                % (p.returncode, simd_cus_header, serr))

        pypsutils.string2file('#include "' + simd_h + '"\n' + simd_cus_header,
                              simd_h_fname)
        pypsutils.string2file(simd_h + "\n" + simdz_cus_header, simd_h_fname)

        for fname in files:
            if not fname.endswith("SIMD.c"):
                pypsutils.addBeginnning(fname, '#include "' + simd_h + '"')

        # Add the contents of patterns.h
        for fname in files:
            if not fname.endswith("patterns.c"):
                pypsutils.addBeginnning(fname,
                                        '#include "' + self.patterns_h + '"\n')

        # Add header to the save rep
        shutil.copy(pypsutils.get_runtimefile(simd_h, "sac"), rep)
        shutil.copy(pypsutils.get_runtimefile(self.patterns_h, "sac"), rep)
        return files, headers + [
            os.path.join(rep, simd_h),
            os.path.join(rep, self.patterns_h)
        ]
    def __init__(self, ws, *args, **kwargs):
        # defaults to false, as the user needs to invoke memalign
        self.memaligned = False
        self.ws = ws
        pypsutils.string2file(pattern_c, pattern_tmpfile)
	ws._sources.append(pattern_tmpfile)