prepend CLANG_PROGRAM_HEADER in ClangCompiler.render instead of compile (#4063)

src header should be part of the rendered output, and DEBUG=4 includes the header this way
This commit is contained in:
chenyu
2024-04-03 23:17:56 -04:00
committed by GitHub
parent 7181ffd630
commit d219aba962

View File

@@ -7,12 +7,12 @@ CLANG_PROGRAM_HEADER = '#include <stdbool.h>\n#include <tgmath.h>\n#define max(x
class ClangCompiler(Compiler):
compiler_opts = CompilerOptions("CLANG", supports_float4=False, has_local=False)
def render(self, name:str, uops) -> str: return uops_to_cstyle(CStyleLanguage(buffer_suffix=" restrict"), name, uops)
def render(self, name:str, uops) -> str: return CLANG_PROGRAM_HEADER + uops_to_cstyle(CStyleLanguage(buffer_suffix=" restrict"), name, uops)
def compile(self, src:str) -> bytes:
# TODO: remove file write. sadly clang doesn't like the use of /dev/stdout here
with tempfile.NamedTemporaryFile(delete=True) as output_file:
subprocess.check_output(args=('clang -shared -march=native -O2 -Wall -Werror -x c -fPIC - -o '+ \
str(output_file.name)).split(), input=(CLANG_PROGRAM_HEADER+src).encode('utf-8'))
subprocess.check_output(args=('clang -shared -march=native -O2 -Wall -Werror -x c -fPIC - -o '+ str(output_file.name)).split(),
input=src.encode('utf-8'))
return pathlib.Path(output_file.name).read_bytes()
class ClangProgram: