-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathCommon.cpp
More file actions
63 lines (51 loc) · 2.12 KB
/
Common.cpp
File metadata and controls
63 lines (51 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
***********************************************************************************************************************
* Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***********************************************************************************************************************
*/
#include "llvm-dialects/TableGen/Common.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include <regex>
#include <string>
using namespace llvm_dialects;
using namespace llvm;
namespace {
cl::opt<bool>
g_emitComments("emit-comments",
cl::desc("emit debug comments in generated source files"),
cl::Hidden, cl::init(false));
} // namespace
void llvm_dialects::emitHeader(raw_ostream& out) {
out << "// DO NOT EDIT! This file is automatically generated by llvm-dialects-tblgen.\n\n";
}
bool llvm_dialects::shouldEmitComments() { return g_emitComments; }
std::string llvm_dialects::replaceSubstring(const std::string &haystack,
const std::string &needle,
const std::string &replacement) {
return std::regex_replace(haystack, std::regex(needle), replacement);
}
std::string llvm_dialects::createCommentFromString(const std::string &input) {
const StringRef inRef{input};
if (inRef.trim().empty())
return input;
SmallVector<StringRef> lines;
inRef.split(lines, '\n');
std::string outStr;
for (auto line : lines)
outStr += "/// " + line.str() + '\n';
return outStr;
}