@@ -40,12 +40,23 @@ static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
40
40
" instantiated from multiclass" );
41
41
}
42
42
43
+ // Run file cleanup handlers and then exit fatally (with non-zero exit code).
44
+ [[noreturn]] inline static void fatal_exit () {
45
+ // The following call runs the file cleanup handlers.
46
+ sys::RunInterruptHandlers ();
47
+ std::exit (1 );
48
+ }
49
+
43
50
// Functions to print notes.
44
51
45
52
void PrintNote (const Twine &Msg) {
46
53
WithColor::note () << Msg << " \n " ;
47
54
}
48
55
56
+ void PrintNote (function_ref<void (raw_ostream &OS)> PrintMsg) {
57
+ PrintMsg (WithColor::note ());
58
+ }
59
+
49
60
void PrintNote (ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
50
61
PrintMessage (NoteLoc, SourceMgr::DK_Note, Msg);
51
62
}
@@ -54,34 +65,26 @@ void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
54
65
55
66
void PrintFatalNote (const Twine &Msg) {
56
67
PrintNote (Msg);
57
- // The following call runs the file cleanup handlers.
58
- sys::RunInterruptHandlers ();
59
- std::exit (1 );
68
+ fatal_exit ();
60
69
}
61
70
62
71
void PrintFatalNote (ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
63
72
PrintNote (NoteLoc, Msg);
64
- // The following call runs the file cleanup handlers.
65
- sys::RunInterruptHandlers ();
66
- std::exit (1 );
73
+ fatal_exit ();
67
74
}
68
75
69
76
// This method takes a Record and uses the source location
70
77
// stored in it.
71
78
void PrintFatalNote (const Record *Rec, const Twine &Msg) {
72
79
PrintNote (Rec->getLoc (), Msg);
73
- // The following call runs the file cleanup handlers.
74
- sys::RunInterruptHandlers ();
75
- std::exit (1 );
80
+ fatal_exit ();
76
81
}
77
82
78
83
// This method takes a RecordVal and uses the source location
79
84
// stored in it.
80
85
void PrintFatalNote (const RecordVal *RecVal, const Twine &Msg) {
81
86
PrintNote (RecVal->getLoc (), Msg);
82
- // The following call runs the file cleanup handlers.
83
- sys::RunInterruptHandlers ();
84
- std::exit (1 );
87
+ fatal_exit ();
85
88
}
86
89
87
90
// Functions to print warnings.
@@ -100,6 +103,10 @@ void PrintWarning(const char *Loc, const Twine &Msg) {
100
103
101
104
void PrintError (const Twine &Msg) { WithColor::error () << Msg << " \n " ; }
102
105
106
+ void PrintError (function_ref<void (raw_ostream &OS)> PrintMsg) {
107
+ PrintMsg (WithColor::error ());
108
+ }
109
+
103
110
void PrintError (ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
104
111
PrintMessage (ErrorLoc, SourceMgr::DK_Error, Msg);
105
112
}
@@ -124,34 +131,31 @@ void PrintError(const RecordVal *RecVal, const Twine &Msg) {
124
131
125
132
void PrintFatalError (const Twine &Msg) {
126
133
PrintError (Msg);
127
- // The following call runs the file cleanup handlers.
128
- sys::RunInterruptHandlers ();
129
- std::exit (1 );
134
+ fatal_exit ();
135
+ }
136
+
137
+ void PrintFatalError (function_ref<void (raw_ostream &OS)> PrintMsg) {
138
+ PrintError (PrintMsg);
139
+ fatal_exit ();
130
140
}
131
141
132
142
void PrintFatalError (ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
133
143
PrintError (ErrorLoc, Msg);
134
- // The following call runs the file cleanup handlers.
135
- sys::RunInterruptHandlers ();
136
- std::exit (1 );
144
+ fatal_exit ();
137
145
}
138
146
139
147
// This method takes a Record and uses the source location
140
148
// stored in it.
141
149
void PrintFatalError (const Record *Rec, const Twine &Msg) {
142
150
PrintError (Rec->getLoc (), Msg);
143
- // The following call runs the file cleanup handlers.
144
- sys::RunInterruptHandlers ();
145
- std::exit (1 );
151
+ fatal_exit ();
146
152
}
147
153
148
154
// This method takes a RecordVal and uses the source location
149
155
// stored in it.
150
156
void PrintFatalError (const RecordVal *RecVal, const Twine &Msg) {
151
157
PrintError (RecVal->getLoc (), Msg);
152
- // The following call runs the file cleanup handlers.
153
- sys::RunInterruptHandlers ();
154
- std::exit (1 );
158
+ fatal_exit ();
155
159
}
156
160
157
161
// Check an assertion: Obtain the condition value and be sure it is true.
0 commit comments