llvm.org GIT mirror llvm / 57f4539
Added new functionality to LLVM C API to use DiagnosticInfo to handle errors Patch by: Darren Powell git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206407 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 5 years ago
3 changed file(s) with 85 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1414 #ifndef LLVM_SUPPORT_DIAGNOSTICINFO_H
1515 #define LLVM_SUPPORT_DIAGNOSTICINFO_H
1616
17 #include "llvm-c/Core.h"
1718 #include "llvm/ADT/ArrayRef.h"
1819 #include "llvm/Support/Casting.h"
1920
293294 const Twine &Msg;
294295 };
295296
297 // Create wrappers for C Binding types (see CBindingWrapping.h).
298 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef)
299
296300 } // End namespace llvm
297301
298302 #endif
122122 *
123123 * @see llvm::Use */
124124 typedef struct LLVMOpaqueUse *LLVMUseRef;
125
126
127 /**
128 * @see llvm::DiagnosticInfo
129 */
130 typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
125131
126132 typedef enum {
127133 LLVMZExtAttribute = 1<<0,
399405 the old one */
400406 } LLVMAtomicRMWBinOp;
401407
408 typedef enum {
409 LLVMDSError,
410 LLVMDSWarning,
411 LLVMDSRemark,
412 LLVMDSNote
413 } LLVMDiagnosticSeverity;
414
402415 /**
403416 * @}
404417 */
452465 * @{
453466 */
454467
468 typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
469
455470 /**
456471 * Create a new context.
457472 *
466481 LLVMContextRef LLVMGetGlobalContext(void);
467482
468483 /**
484 * Set the diagnostic handler for this context.
485 */
486 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
487 LLVMDiagnosticHandler Handler,
488 void *DiagnosticContext);
489
490 /**
469491 * Destroy a context instance.
470492 *
471493 * This should be called for every call to LLVMContextCreate() or memory
472494 * will be leaked.
473495 */
474496 void LLVMContextDispose(LLVMContextRef C);
497
498 /**
499 * Return a string representation of the DiagnosticInfo. Use
500 * LLVMDisposeMessage to free the string.
501 *
502 * @see DiagnosticInfo::print()
503 */
504 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
505
506 /**
507 * Return an enum LLVMDiagnosticSeverity.
508 *
509 * @see DiagnosticInfo::getSeverity()
510 */
511 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
475512
476513 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
477514 unsigned SLen);
1616 #include "llvm/IR/Attributes.h"
1717 #include "llvm/IR/CallSite.h"
1818 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include "llvm/IR/DiagnosticPrinter.h"
1921 #include "llvm/IR/DerivedTypes.h"
2022 #include "llvm/IR/GlobalAlias.h"
2123 #include "llvm/IR/GlobalVariable.h"
7577 return wrap(&getGlobalContext());
7678 }
7779
80 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
81 LLVMDiagnosticHandler Handler,
82 void *DiagnosticContext) {
83 unwrap(C)->setDiagnosticHandler(
84 LLVM_EXTENSION reinterpret_cast(Handler),
85 DiagnosticContext);
86 }
87
7888 void LLVMContextDispose(LLVMContextRef C) {
7989 delete unwrap(C);
8090 }
8797 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) {
8898 return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
8999 }
100
101 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
102 std::string MsgStorage;
103 raw_string_ostream Stream(MsgStorage);
104 DiagnosticPrinterRawOStream DP(Stream);
105
106 unwrap(DI)->print(DP);
107 Stream.flush();
108
109 return LLVMCreateMessage(MsgStorage.c_str());
110 }
111
112 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
113 LLVMDiagnosticSeverity severity;
114
115 switch(unwrap(DI)->getSeverity()) {
116 default:
117 severity = LLVMDSError;
118 break;
119 case DS_Warning:
120 severity = LLVMDSWarning;
121 break;
122 case DS_Remark:
123 severity = LLVMDSRemark;
124 break;
125 case DS_Note:
126 severity = LLVMDSNote;
127 break;
128 }
129
130 return severity;
131 }
132
133
90134
91135
92136 /*===-- Operations on modules ---------------------------------------------===*/