1# ===----------------------------------------------------------------------===## 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 9import os.path 10import sys 11 12from libcxx.header_information import module_headers 13from libcxx.header_information import header_restrictions 14from libcxx.header_information import headers_not_available 15 16 17def write_file(module): 18 libcxx_module_directory = os.path.join( 19 os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "modules" 20 ) 21 with open( 22 os.path.join(libcxx_module_directory, f"{module}.cppm.in"), "w" 23 ) as module_cpp_in: 24 module_cpp_in.write( 25 """\ 26// -*- C++ -*- 27//===----------------------------------------------------------------------===// 28// 29// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 30// See https://llvm.org/LICENSE.txt for license information. 31// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 32// 33//===----------------------------------------------------------------------===// 34 35// WARNING, this entire header is generated by 36// utils/generate_libcxx_cppm_in.py 37// DO NOT MODIFY! 38 39module; 40 41#include <__config> 42 43// The headers of Table 24: C++ library headers [tab:headers.cpp] 44// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c] 45""" 46 ) 47 for header in module_headers: 48 if header in header_restrictions: 49 module_cpp_in.write( 50 f"""\ 51#if {header_restrictions[header]} 52# include <{header}> 53#endif 54""" 55 ) 56 else: 57 module_cpp_in.write(f"#include <{header}>\n") 58 59 module_cpp_in.write("\n// *** Headers not yet available ***\n") 60 for header in sorted(headers_not_available): 61 module_cpp_in.write( 62 f"""\ 63#if __has_include(<{header}>) 64# error "please update the header information for <{header}> in headers_not_available in utils/libcxx/header_information.py" 65#endif // __has_include(<{header}>) 66""" 67 ) 68 69 module_cpp_in.write( 70 f""" 71export module {module}; 72 73@LIBCXX_MODULE_STD_INCLUDE_SOURCES@ 74{'@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@' if module == 'std.compat' else ''}""" 75 ) 76 77 78if __name__ == "__main__": 79 if len(sys.argv) != 2 or (sys.argv[1] != "std" and sys.argv[1] != "std.compat"): 80 sys.stderr.write( 81 f"""\ 82Usage: 83{os.path.basename(__file__)} (std|std.compat) 84""" 85 ) 86 sys.exit(1) 87 88 write_file(sys.argv[1]) 89