Skip to content

Commit 9ed2e68

Browse files
committed
[clang-format] Parse Verilog if statements
This patch mainly handles treating `begin` as block openers. While and for statements will be handled in another patch. Reviewed By: HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D123450
1 parent 370bee4 commit 9ed2e68

File tree

9 files changed

+508
-8
lines changed

9 files changed

+508
-8
lines changed

clang/docs/ClangFormat.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
4343
--assume-filename=<string> - Override filename used to determine the language.
4444
When reading from stdin, clang-format assumes this
4545
filename to determine the language.
46+
Unrecognized filenames are treated as C++.
47+
supported:
48+
CSharp: .cs
49+
Java: .java
50+
JavaScript: .mjs .js .ts
51+
Json: .json
52+
Objective-C: .m .mm
53+
Proto: .proto .protodevel
54+
TableGen: .td
55+
TextProto: .textpb .pb.txt .textproto .asciipb
56+
Verilog: .sv .svh .v .vh
4657
--cursor=<uint> - The position of the cursor when invoking
4758
clang-format from an editor integration
4859
--dry-run - If set, do not actually make the formatting changes

clang/include/clang/Format/Format.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2589,12 +2589,17 @@ struct FormatStyle {
25892589
LK_TableGen,
25902590
/// Should be used for Protocol Buffer messages in text format
25912591
/// (https://developers.google.com/protocol-buffers/).
2592-
LK_TextProto
2592+
LK_TextProto,
2593+
/// Should be used for Verilog and SystemVerilog.
2594+
/// https://standards.ieee.org/ieee/1800/6700/
2595+
/// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
2596+
LK_Verilog
25932597
};
25942598
bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
25952599
bool isCSharp() const { return Language == LK_CSharp; }
25962600
bool isJson() const { return Language == LK_Json; }
25972601
bool isJavaScript() const { return Language == LK_JavaScript; }
2602+
bool isVerilog() const { return Language == LK_Verilog; }
25982603

25992604
/// Language, this format style is targeted at.
26002605
/// \version 3.5
@@ -4285,6 +4290,8 @@ inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
42854290
return "TableGen";
42864291
case FormatStyle::LK_TextProto:
42874292
return "TextProto";
4293+
case FormatStyle::LK_Verilog:
4294+
return "Verilog";
42884295
default:
42894296
return "Unknown";
42904297
}

clang/lib/Format/Format.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,6 +3471,12 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
34713471
return FormatStyle::LK_CSharp;
34723472
if (FileName.endswith_insensitive(".json"))
34733473
return FormatStyle::LK_Json;
3474+
if (FileName.endswith_insensitive(".sv") ||
3475+
FileName.endswith_insensitive(".svh") ||
3476+
FileName.endswith_insensitive(".v") ||
3477+
FileName.endswith_insensitive(".vh")) {
3478+
return FormatStyle::LK_Verilog;
3479+
}
34743480
return FormatStyle::LK_Cpp;
34753481
}
34763482

0 commit comments

Comments
 (0)