@@ -40,12 +40,23 @@ static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
4040 " instantiated from multiclass" );
4141}
4242
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+
4350// Functions to print notes.
4451
4552void PrintNote (const Twine &Msg) {
4653 WithColor::note () << Msg << " \n " ;
4754}
4855
56+ void PrintNote (function_ref<void (raw_ostream &OS)> PrintMsg) {
57+ PrintMsg (WithColor::note ());
58+ }
59+
4960void PrintNote (ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
5061 PrintMessage (NoteLoc, SourceMgr::DK_Note, Msg);
5162}
@@ -54,34 +65,26 @@ void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
5465
5566void PrintFatalNote (const Twine &Msg) {
5667 PrintNote (Msg);
57- // The following call runs the file cleanup handlers.
58- sys::RunInterruptHandlers ();
59- std::exit (1 );
68+ fatal_exit ();
6069}
6170
6271void PrintFatalNote (ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
6372 PrintNote (NoteLoc, Msg);
64- // The following call runs the file cleanup handlers.
65- sys::RunInterruptHandlers ();
66- std::exit (1 );
73+ fatal_exit ();
6774}
6875
6976// This method takes a Record and uses the source location
7077// stored in it.
7178void PrintFatalNote (const Record *Rec, const Twine &Msg) {
7279 PrintNote (Rec->getLoc (), Msg);
73- // The following call runs the file cleanup handlers.
74- sys::RunInterruptHandlers ();
75- std::exit (1 );
80+ fatal_exit ();
7681}
7782
7883// This method takes a RecordVal and uses the source location
7984// stored in it.
8085void PrintFatalNote (const RecordVal *RecVal, const Twine &Msg) {
8186 PrintNote (RecVal->getLoc (), Msg);
82- // The following call runs the file cleanup handlers.
83- sys::RunInterruptHandlers ();
84- std::exit (1 );
87+ fatal_exit ();
8588}
8689
8790// Functions to print warnings.
@@ -100,6 +103,10 @@ void PrintWarning(const char *Loc, const Twine &Msg) {
100103
101104void PrintError (const Twine &Msg) { WithColor::error () << Msg << " \n " ; }
102105
106+ void PrintError (function_ref<void (raw_ostream &OS)> PrintMsg) {
107+ PrintMsg (WithColor::error ());
108+ }
109+
103110void PrintError (ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
104111 PrintMessage (ErrorLoc, SourceMgr::DK_Error, Msg);
105112}
@@ -124,34 +131,31 @@ void PrintError(const RecordVal *RecVal, const Twine &Msg) {
124131
125132void PrintFatalError (const Twine &Msg) {
126133 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 ();
130140}
131141
132142void PrintFatalError (ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
133143 PrintError (ErrorLoc, Msg);
134- // The following call runs the file cleanup handlers.
135- sys::RunInterruptHandlers ();
136- std::exit (1 );
144+ fatal_exit ();
137145}
138146
139147// This method takes a Record and uses the source location
140148// stored in it.
141149void PrintFatalError (const Record *Rec, const Twine &Msg) {
142150 PrintError (Rec->getLoc (), Msg);
143- // The following call runs the file cleanup handlers.
144- sys::RunInterruptHandlers ();
145- std::exit (1 );
151+ fatal_exit ();
146152}
147153
148154// This method takes a RecordVal and uses the source location
149155// stored in it.
150156void PrintFatalError (const RecordVal *RecVal, const Twine &Msg) {
151157 PrintError (RecVal->getLoc (), Msg);
152- // The following call runs the file cleanup handlers.
153- sys::RunInterruptHandlers ();
154- std::exit (1 );
158+ fatal_exit ();
155159}
156160
157161// Check an assertion: Obtain the condition value and be sure it is true.
0 commit comments