Path: blob/main/contrib/llvm-project/openmp/runtime/src/kmp_i18n.h
35258 views
/*1* kmp_i18n.h2*/34//===----------------------------------------------------------------------===//5//6// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.7// See https://llvm.org/LICENSE.txt for license information.8// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception9//10//===----------------------------------------------------------------------===//1112#ifndef KMP_I18N_H13#define KMP_I18N_H1415#include "kmp_str.h"1617#ifdef __cplusplus18extern "C" {19#endif // __cplusplus2021/* kmp_i18n_id.inc defines kmp_i18n_id_t type. It is an enumeration with22identifiers of all the messages in the catalog. There is one special23identifier: kmp_i18n_null, which denotes absence of message. */24#include "kmp_i18n_id.inc" // Generated file. Do not edit it manually.2526/* Low-level functions handling message catalog. __kmp_i18n_open() opens message27catalog, __kmp_i18n_closes() it. Explicit opening is not required: if message28catalog is not yet open, __kmp_i18n_catgets() will open it implicitly.29However, catalog should be explicitly closed, otherwise resources (mamory,30handles) may leak.3132__kmp_i18n_catgets() returns read-only string. It should not be freed.3334KMP_I18N_STR macro simplifies access to strings in message catalog a bit.35Following two lines are equivalent:3637__kmp_i18n_catgets( kmp_i18n_str_Warning )38KMP_I18N_STR( Warning )39*/4041void __kmp_i18n_catopen();42void __kmp_i18n_catclose();43char const *__kmp_i18n_catgets(kmp_i18n_id_t id);4445#define KMP_I18N_STR(id) __kmp_i18n_catgets(kmp_i18n_str_##id)4647/* High-level interface for printing strings targeted to the user.4849All the strings are divided into 3 types:50* messages,51* hints,52* system errors.5354There are 3 kind of message severities:55* informational messages,56* warnings (non-fatal errors),57* fatal errors.5859For example:60OMP: Warning #2: Cannot open message catalog "libguide.cat": (1)61OMP: System error #2: No such file or directory (2)62OMP: Hint: Please check NLSPATH environment variable. (3)63OMP: Info #3: Default messages will be used. (4)6465where66(1) is a message of warning severity,67(2) is a system error caused the previous warning,68(3) is a hint for the user how to fix the problem,69(4) is a message of informational severity.7071Usage in complex cases (message is accompanied with hints and system errors):7273int error = errno; // We need save errno immediately, because it may74// be changed.75__kmp_msg(76kmp_ms_warning, // Severity77KMP_MSG( CantOpenMessageCatalog, name ), // Primary message78KMP_ERR( error ), // System error79KMP_HNT( CheckNLSPATH ), // Hint80__kmp_msg_null // Variadic argument list finisher81);8283Usage in simple cases (just a message, no system errors or hints):84KMP_INFORM( WillUseDefaultMessages );85KMP_WARNING( CantOpenMessageCatalog, name );86KMP_FATAL( StackOverlap );87KMP_SYSFAIL( "pthread_create", status );88KMP_CHECK_SYSFAIL( "pthread_create", status );89KMP_CHECK_SYSFAIL_ERRNO( "gettimeofday", status );90*/9192enum kmp_msg_type {93kmp_mt_dummy = 0, // Special type for internal purposes.94kmp_mt_mesg =954, // Primary OpenMP message, could be information, warning, or fatal.96kmp_mt_hint = 5, // Hint to the user.97kmp_mt_syserr = -1 // System error message.98}; // enum kmp_msg_type99typedef enum kmp_msg_type kmp_msg_type_t;100101struct kmp_msg {102kmp_msg_type_t type;103int num;104char *str;105size_t len;106}; // struct kmp_message107typedef struct kmp_msg kmp_msg_t;108109// Special message to denote the end of variadic list of arguments.110extern kmp_msg_t __kmp_msg_null;111112// Helper functions. Creates messages either from message catalog or from113// system. Note: these functions allocate memory. You should pass created114// messages to __kmp_msg() function, it will print messages and destroy them.115kmp_msg_t __kmp_msg_format(unsigned id_arg, ...);116kmp_msg_t __kmp_msg_error_code(int code);117kmp_msg_t __kmp_msg_error_mesg(char const *mesg);118119// Helper macros to make calls shorter.120#define KMP_MSG(...) __kmp_msg_format(kmp_i18n_msg_##__VA_ARGS__)121#define KMP_HNT(...) __kmp_msg_format(kmp_i18n_hnt_##__VA_ARGS__)122#define KMP_SYSERRCODE(code) __kmp_msg_error_code(code)123#define KMP_SYSERRMESG(mesg) __kmp_msg_error_mesg(mesg)124#define KMP_ERR KMP_SYSERRCODE125126// Message severity.127enum kmp_msg_severity {128kmp_ms_inform, // Just information for the user.129kmp_ms_warning, // Non-fatal error, execution continues.130kmp_ms_fatal // Fatal error, program aborts.131}; // enum kmp_msg_severity132typedef enum kmp_msg_severity kmp_msg_severity_t;133134// Primary function for printing messages for the user. The first message is135// mandatory. Any number of system errors and hints may be specified. Argument136// list must be finished with __kmp_msg_null.137void __kmp_msg(kmp_msg_severity_t severity, kmp_msg_t message, ...);138KMP_NORETURN void __kmp_fatal(kmp_msg_t message, ...);139140// Helper macros to make calls shorter in simple cases.141#define KMP_INFORM(...) \142__kmp_msg(kmp_ms_inform, KMP_MSG(__VA_ARGS__), __kmp_msg_null)143#define KMP_WARNING(...) \144__kmp_msg(kmp_ms_warning, KMP_MSG(__VA_ARGS__), __kmp_msg_null)145#define KMP_FATAL(...) __kmp_fatal(KMP_MSG(__VA_ARGS__), __kmp_msg_null)146#define KMP_SYSFAIL(func, error) \147__kmp_fatal(KMP_MSG(FunctionError, func), KMP_SYSERRCODE(error), \148__kmp_msg_null)149150// Check error, if not zero, generate fatal error message.151#define KMP_CHECK_SYSFAIL(func, error) \152{ \153if (error) { \154KMP_SYSFAIL(func, error); \155} \156}157158// Check status, if not zero, generate fatal error message using errno.159#define KMP_CHECK_SYSFAIL_ERRNO(func, status) \160{ \161if (status != 0) { \162int error = errno; \163KMP_SYSFAIL(func, error); \164} \165}166167#ifdef KMP_DEBUG168void __kmp_i18n_dump_catalog(kmp_str_buf_t *buffer);169#endif // KMP_DEBUG170171#ifdef __cplusplus172} // extern "C"173#endif // __cplusplus174175#endif // KMP_I18N_H176177// end of file //178179180