[clang] [clang] Add basic support for #embed. (PR #76480)
https://github.com/juniorrantila created https://github.com/llvm/llvm-project/pull/76480 This patch takes the first steps toward C23 #embed support. We can include binary files, but embed-parameter-sequences are not implemented. Adding the embedded file to the -M dependency array is also not implemented. >From 00e9c665c18c1efafc15e293ea6dc35b1ed32e48 Mon Sep 17 00:00:00 2001 From: Junior Rantila Date: Wed, 27 Dec 2023 22:00:35 +0100 Subject: [PATCH] [clang] Add basic support for #embed. This patch takes the first steps toward C23 #embed support. We can include binary files, but embed-parameter-sequences are not implemented. Adding the embedded file to the -M dependency array is also not implemented. --- .../clang/Basic/DiagnosticParseKinds.td | 2 + clang/include/clang/Basic/TokenKinds.def | 3 + .../clang/Lex/DependencyDirectivesScanner.h | 1 + clang/include/clang/Lex/Preprocessor.h| 3 + clang/lib/Basic/IdentifierTable.cpp | 1 + clang/lib/Lex/DependencyDirectivesScanner.cpp | 12 + clang/lib/Lex/Lexer.cpp | 1 + clang/lib/Lex/PPDirectives.cpp| 221 +- 8 files changed, 240 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index e4b1069cde1850..56258df192f9ff 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -165,6 +165,8 @@ def ext_c99_feature : Extension< "'%0' is a C99 extension">, InGroup; def ext_c11_feature : Extension< "'%0' is a C11 extension">, InGroup; +def ext_c23_feature : Extension< + "'%0' is a C23 extension">, InGroup; def warn_c23_compat_keyword : Warning< "'%0' is incompatible with C standards before C23">, InGroup, DefaultIgnore; diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 3f0e1e1a7d45ad..591684c004f908 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -113,6 +113,9 @@ PPKEYWORD(defined) PPKEYWORD(include) PPKEYWORD(__include_macros) +// C23 6.10.2 - Binary resource inclusion +PPKEYWORD(embed) + // C99 6.10.3 - Macro Replacement. PPKEYWORD(define) PPKEYWORD(undef) diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h b/clang/include/clang/Lex/DependencyDirectivesScanner.h index 0e115906fbfe51..b00b9391d0074a 100644 --- a/clang/include/clang/Lex/DependencyDirectivesScanner.h +++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h @@ -70,6 +70,7 @@ enum DirectiveKind : uint8_t { pp_pragma_include_alias, pp_pragma_system_header, pp_include_next, + pp_embed, pp_if, pp_ifdef, pp_ifndef, diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 4ec21a8b6be2c8..4ff097eae78571 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2689,6 +2689,9 @@ class Preprocessor { void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok); void HandleImportDirective(SourceLocation HashLoc, Token &Tok); void HandleMicrosoftImportDirective(Token &Tok); + void HandleEmbedDirective(SourceLocation HashLoc, Token &Tok, +ConstSearchDirIterator LookupFrom = nullptr, +const FileEntry *LookupFromFile = nullptr); public: /// Check that the given module is available, producing a diagnostic if not. diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 5902c6dc3ce0b4..50cf1925acf49e 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -446,6 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const { CASE( 5, 'i', 'e', ident); CASE( 5, 'i', 'd', ifdef); CASE( 5, 'u', 'd', undef); + CASE( 5, 'e', 'b', embed); CASE( 6, 'a', 's', assert); CASE( 6, 'd', 'f', define); diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp index 980f865cf24c97..867614cdb27167 100644 --- a/clang/lib/Lex/DependencyDirectivesScanner.cpp +++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -91,6 +91,9 @@ struct Scanner { dependency_directives_scan::Token &lexIncludeFilename(const char *&First, const char *const End); + dependency_directives_scan::Token &lexEmbedFilename(const char *&First, + const char *const End); + void skipLine(const char *&First, const char *const End); void skipDirective(StringRef Name, const char *&First, const char *const End); @@ -541,6 +544,11 @@ Scanner::lexIncludeFilename(const char *&First, const char *const End) { return CurDirToks.back(); } +dependency_directives_scan::Token & +Scanner::lexEmbedFilename(const char *&Fir
[clang] [clang] Add basic support for #embed. (PR #76480)
https://github.com/juniorrantila updated https://github.com/llvm/llvm-project/pull/76480 >From a51561dcfb9877c0881651ecdc9de8928991506c Mon Sep 17 00:00:00 2001 From: Junior Rantila Date: Wed, 27 Dec 2023 22:00:35 +0100 Subject: [PATCH] [clang] Add basic support for #embed. This patch takes the first steps toward C23 #embed support. We can include binary files, but embed-parameter-sequences are not implemented. Adding the embedded file to the -M dependency array is also not implemented. --- .../clang/Basic/DiagnosticParseKinds.td | 2 + clang/include/clang/Basic/TokenKinds.def | 3 + .../clang/Lex/DependencyDirectivesScanner.h | 1 + clang/include/clang/Lex/Preprocessor.h| 3 + clang/lib/Basic/IdentifierTable.cpp | 1 + clang/lib/Lex/DependencyDirectivesScanner.cpp | 12 + clang/lib/Lex/Lexer.cpp | 1 + clang/lib/Lex/PPDirectives.cpp| 221 +- 8 files changed, 240 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index e4b1069cde1850..56258df192f9ff 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -165,6 +165,8 @@ def ext_c99_feature : Extension< "'%0' is a C99 extension">, InGroup; def ext_c11_feature : Extension< "'%0' is a C11 extension">, InGroup; +def ext_c23_feature : Extension< + "'%0' is a C23 extension">, InGroup; def warn_c23_compat_keyword : Warning< "'%0' is incompatible with C standards before C23">, InGroup, DefaultIgnore; diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 3f0e1e1a7d45ad..591684c004f908 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -113,6 +113,9 @@ PPKEYWORD(defined) PPKEYWORD(include) PPKEYWORD(__include_macros) +// C23 6.10.2 - Binary resource inclusion +PPKEYWORD(embed) + // C99 6.10.3 - Macro Replacement. PPKEYWORD(define) PPKEYWORD(undef) diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h b/clang/include/clang/Lex/DependencyDirectivesScanner.h index 0e115906fbfe51..b00b9391d0074a 100644 --- a/clang/include/clang/Lex/DependencyDirectivesScanner.h +++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h @@ -70,6 +70,7 @@ enum DirectiveKind : uint8_t { pp_pragma_include_alias, pp_pragma_system_header, pp_include_next, + pp_embed, pp_if, pp_ifdef, pp_ifndef, diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 4ec21a8b6be2c8..4ff097eae78571 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2689,6 +2689,9 @@ class Preprocessor { void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok); void HandleImportDirective(SourceLocation HashLoc, Token &Tok); void HandleMicrosoftImportDirective(Token &Tok); + void HandleEmbedDirective(SourceLocation HashLoc, Token &Tok, +ConstSearchDirIterator LookupFrom = nullptr, +const FileEntry *LookupFromFile = nullptr); public: /// Check that the given module is available, producing a diagnostic if not. diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 5902c6dc3ce0b4..459e03f337fa87 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -446,6 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const { CASE( 5, 'i', 'e', ident); CASE( 5, 'i', 'd', ifdef); CASE( 5, 'u', 'd', undef); + CASE(5, 'e', 'b', embed); CASE( 6, 'a', 's', assert); CASE( 6, 'd', 'f', define); diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp index 980f865cf24c97..867614cdb27167 100644 --- a/clang/lib/Lex/DependencyDirectivesScanner.cpp +++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -91,6 +91,9 @@ struct Scanner { dependency_directives_scan::Token &lexIncludeFilename(const char *&First, const char *const End); + dependency_directives_scan::Token &lexEmbedFilename(const char *&First, + const char *const End); + void skipLine(const char *&First, const char *const End); void skipDirective(StringRef Name, const char *&First, const char *const End); @@ -541,6 +544,11 @@ Scanner::lexIncludeFilename(const char *&First, const char *const End) { return CurDirToks.back(); } +dependency_directives_scan::Token & +Scanner::lexEmbedFilename(const char *&First, const char *const End) { + return lexIncludeFilename(First, End); +} + void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) { while (true) { const dependency_directives_scan::Token &To
[clang] [clang] Add basic support for #embed. (PR #76480)
https://github.com/juniorrantila updated https://github.com/llvm/llvm-project/pull/76480 >From 554b85be15f9ee9767d74db18ef6db75119b308a Mon Sep 17 00:00:00 2001 From: Junior Rantila Date: Wed, 27 Dec 2023 22:00:35 +0100 Subject: [PATCH] [clang] Add basic support for #embed This patch takes the first steps toward C23 #embed support. We can include binary files, but embed-parameter-sequences are not implemented. Adding the embedded file to the -M dependency array is also not implemented. --- .../clang/Basic/DiagnosticParseKinds.td | 2 + clang/include/clang/Basic/TokenKinds.def | 3 + .../clang/Lex/DependencyDirectivesScanner.h | 1 + clang/include/clang/Lex/Preprocessor.h| 3 + clang/lib/Basic/IdentifierTable.cpp | 1 + clang/lib/Lex/DependencyDirectivesScanner.cpp | 12 + clang/lib/Lex/Lexer.cpp | 1 + clang/lib/Lex/PPDirectives.cpp| 221 +- 8 files changed, 240 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index e4b1069cde1850..56258df192f9ff 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -165,6 +165,8 @@ def ext_c99_feature : Extension< "'%0' is a C99 extension">, InGroup; def ext_c11_feature : Extension< "'%0' is a C11 extension">, InGroup; +def ext_c23_feature : Extension< + "'%0' is a C23 extension">, InGroup; def warn_c23_compat_keyword : Warning< "'%0' is incompatible with C standards before C23">, InGroup, DefaultIgnore; diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 3f0e1e1a7d45ad..591684c004f908 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -113,6 +113,9 @@ PPKEYWORD(defined) PPKEYWORD(include) PPKEYWORD(__include_macros) +// C23 6.10.2 - Binary resource inclusion +PPKEYWORD(embed) + // C99 6.10.3 - Macro Replacement. PPKEYWORD(define) PPKEYWORD(undef) diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h b/clang/include/clang/Lex/DependencyDirectivesScanner.h index 0e115906fbfe51..b00b9391d0074a 100644 --- a/clang/include/clang/Lex/DependencyDirectivesScanner.h +++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h @@ -70,6 +70,7 @@ enum DirectiveKind : uint8_t { pp_pragma_include_alias, pp_pragma_system_header, pp_include_next, + pp_embed, pp_if, pp_ifdef, pp_ifndef, diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 4ec21a8b6be2c8..4ff097eae78571 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2689,6 +2689,9 @@ class Preprocessor { void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok); void HandleImportDirective(SourceLocation HashLoc, Token &Tok); void HandleMicrosoftImportDirective(Token &Tok); + void HandleEmbedDirective(SourceLocation HashLoc, Token &Tok, +ConstSearchDirIterator LookupFrom = nullptr, +const FileEntry *LookupFromFile = nullptr); public: /// Check that the given module is available, producing a diagnostic if not. diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 5902c6dc3ce0b4..459e03f337fa87 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -446,6 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const { CASE( 5, 'i', 'e', ident); CASE( 5, 'i', 'd', ifdef); CASE( 5, 'u', 'd', undef); + CASE(5, 'e', 'b', embed); CASE( 6, 'a', 's', assert); CASE( 6, 'd', 'f', define); diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp index 980f865cf24c97..867614cdb27167 100644 --- a/clang/lib/Lex/DependencyDirectivesScanner.cpp +++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -91,6 +91,9 @@ struct Scanner { dependency_directives_scan::Token &lexIncludeFilename(const char *&First, const char *const End); + dependency_directives_scan::Token &lexEmbedFilename(const char *&First, + const char *const End); + void skipLine(const char *&First, const char *const End); void skipDirective(StringRef Name, const char *&First, const char *const End); @@ -541,6 +544,11 @@ Scanner::lexIncludeFilename(const char *&First, const char *const End) { return CurDirToks.back(); } +dependency_directives_scan::Token & +Scanner::lexEmbedFilename(const char *&First, const char *const End) { + return lexIncludeFilename(First, End); +} + void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) { while (true) { const dependency_directives_scan::Token &Tok
[clang] [clang] Add basic support for #embed (PR #76480)
https://github.com/juniorrantila edited https://github.com/llvm/llvm-project/pull/76480 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add basic support for #embed (PR #76480)
juniorrantila wrote: Aah, my bad. https://github.com/llvm/llvm-project/pull/76480 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add basic support for #embed (PR #76480)
https://github.com/juniorrantila closed https://github.com/llvm/llvm-project/pull/76480 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits