def compiler_preprocess_cl(src, id='anon'): cmd = [cfg.clang()] + clang_cl_args() + [ '-E', '-c', '-', '-o', '-' ] process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=cfg.toolchain_env()) stdout, stderr = process.communicate(src.encode('utf-8')) if process.returncode != 0: raise ClangException(stderr.decode('utf-8')) src = stdout.decode('utf-8') lines = src.split('\n') # Strip all the includes: for i, line in enumerate(lines): if line == '# 1 "<stdin>" 2': break src = '\n'.join(lines[i + 1:]).strip() # Strip lines beginning with '#' (that's preprocessor # stuff): src = '\n'.join([line for line in src.split('\n') if not line.startswith('#')]) return src
def compile_cl_bytecode(src, id='anon'): cmd = [cfg.clang()] + clang_cl_args() + [ '-emit-llvm', '-S', '-c', '-', '-o', '-' ] process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=cfg.toolchain_env()) stdout, stderr = process.communicate(src.encode('utf-8')) if process.returncode != 0: raise ClangException(stderr.decode('utf-8')) return stdout