• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ===- GPU HeaderFile Class for --export-decls version --------*- python -*--==#
2#
3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6#
7# ==-------------------------------------------------------------------------==#
8
9
10class GpuHeaderFile:
11    def __init__(self, name):
12        self.name = name
13        self.macros = []
14        self.types = []
15        self.enumerations = []
16        self.objects = []
17        self.functions = []
18
19    def add_macro(self, macro):
20        self.macros.append(macro)
21
22    def add_type(self, type_):
23        self.types.append(type_)
24
25    def add_enumeration(self, enumeration):
26        self.enumerations.append(enumeration)
27
28    def add_object(self, object):
29        self.objects.append(object)
30
31    def add_function(self, function):
32        self.functions.append(function)
33
34    def __str__(self):
35        content = []
36
37        content.append(
38            f"//===-- C standard declarations for {self.name} ------------------------------===//"
39        )
40        content.append("//")
41        content.append(
42            "// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions."
43        )
44        content.append("// See https://llvm.org/LICENSE.txt for license information.")
45        content.append("// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception")
46        content.append("//")
47        content.append(
48            "//===----------------------------------------------------------------------===//\n"
49        )
50
51        header_guard = f"__LLVM_LIBC_DECLARATIONS_{self.name.upper()[:-2]}_H"
52        content.append(f"#ifndef {header_guard}")
53        content.append(f"#define {header_guard}\n")
54
55        content.append("#ifndef __LIBC_ATTRS")
56        content.append("#define __LIBC_ATTRS")
57        content.append("#endif\n")
58
59        content.append("#ifdef __cplusplus")
60        content.append('extern "C" {')
61        content.append("#endif\n")
62
63        for function in self.functions:
64            content.append(f"{function} __LIBC_ATTRS;\n")
65
66        for object in self.objects:
67            content.append(f"{object} __LIBC_ATTRS;\n")
68
69        content.append("#ifdef __cplusplus")
70        content.append("}")
71        content.append("#endif\n")
72
73        content.append(f"#endif")
74
75        return "\n".join(content)
76