[clang] [Clang] Add BuiltinTemplates.td to generate code for builtin templates (PR #123736)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 23 08:03:31 PST 2025
================
@@ -0,0 +1,184 @@
+//=- ClangBuiltinsEmitter.cpp - Generate Clang builtin templates-*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This tablegen backend emits Clang's builtin templates.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+using namespace llvm;
+
+std::string TemplateNameList;
+std::string CreateBuiltinTemplateParameterList;
+
+namespace {
+struct ParserState {
+ size_t UniqueCounter = 0;
+ size_t CurrentDepth = 0;
+ bool EmittedSizeTInfo = false;
+};
+
+std::pair<std::string, std::string>
+ParseTemplateParameterList(ParserState &PS, StringRef &TemplateParmList) {
+ auto Alphabetic = [](char c) { return std::isalpha(c); };
+ auto BoolToStr = [](bool b) { return b ? "true" : "false"; };
+
+ std::string Generator;
+ std::vector<std::string> Params;
+ std::unordered_map<std::string, std::string> TemplateNameToParmName;
+ TemplateParmList = TemplateParmList.ltrim();
+ if (!TemplateParmList.consume_front("<"))
+ PrintFatalError("Expected '<' to start the parameter list");
+
+ size_t Position = 0;
+ while (true) {
+ std::string ParmName = "Parm" + std::to_string(PS.UniqueCounter++);
----------------
erichkeane wrote:
It would be lovely if we could use something like a string stream rather than string append through here to be more consistent with the rest of the clang tablegen.
https://github.com/llvm/llvm-project/pull/123736
More information about the cfe-commits
mailing list