예제 #1
0
def rewrite_cl(src, id='anon'):
    # Rewriter can't read from stdin.
    with NamedTemporaryFile('w', suffix='.cl') as tmp:
        tmp.write(src)
        tmp.flush()
        cmd = ([cfg.rewriter(), tmp.name] +
               ['-extra-arg=' + x for x in clang_cl_args()] + ['--'])

        process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                        env=cfg.toolchain_env())
        stdout, stderr = process.communicate()

    # If there was nothing to rewrite, rewriter exits with error code:
    EUGLY_CODE = 204
    if process.returncode == EUGLY_CODE:
        # Propagate the error:
        raise RewriterException(src)
    # NOTE: the rewriter process can still fail because of some other
    # compilation problem, e.g. for some reason the 'enable 64bit
    # support' pragma which should be included in the shim isn't being
    # propogated correctly to the rewriter. However, the rewriter will
    # still correctly process the input, so we ignore all error codes
    # except the one we care about (EUGLY_CODE).
    rewritten = stdout.decode('utf-8')

    # Remove __attribute__ qualifiers
    stripped = clutil.strip_attributes(rewritten)

    return stripped
예제 #2
0
    def test_strip_attributes(self):
        self.assertEqual("", clutil.strip_attributes(
            "__attribute__((reqd_work_group_size(64,1,1)))"))

        out = "foobar"
        tin = "foo__attribute__((reqd_work_group_size(WG_SIZE,1,1)))bar"
        self.assertEqual(out, clutil.strip_attributes(tin))

        out = "typedef  unsigned char uchar8;"
        tin = "typedef __attribute__((ext_vector_type(8))) unsigned char uchar8;"
        self.assertEqual(out, clutil.strip_attributes(tin))

        out = ("typedef  unsigned char uchar8;\n"
               "typedef  unsigned char uchar8;")
        tin = ("typedef __attribute__  ((ext_vector_type(8))) unsigned char uchar8;\n"
               "typedef __attribute__((reqd_work_group_size(64,1,1))) unsigned char uchar8;")
        self.assertEqual(out, clutil.strip_attributes(tin))