Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 24 | #ifndef COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H |
| 25 | #define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 26 | |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 27 | #include <stdexcept> |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 28 | #include <string> |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 29 | |
| 30 | namespace ckw |
| 31 | { |
| 32 | /** Creates the error message |
| 33 | * |
| 34 | * @param[in] file File in which the error occurred. |
| 35 | * @param[in] func Function in which the error occurred. |
| 36 | * @param[in] line Line in which the error occurred. |
| 37 | * @param[in] msg Message to display before abandoning. |
| 38 | * |
| 39 | * @return status containing the error |
| 40 | */ |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 41 | std::string |
| 42 | create_error_msg(const std::string &file, const std::string &func, const std::string &line, const std::string &msg); |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 43 | |
| 44 | /** Print the given message then throw an std::runtime_error. |
| 45 | * |
| 46 | * @param[in] msg Message to display. |
| 47 | */ |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 48 | #define COMPUTE_KERNEL_WRITER_ERROR_ON_MSG(msg) \ |
| 49 | do \ |
| 50 | { \ |
| 51 | const std::string arg0(__FILE__); \ |
| 52 | const std::string arg1(__func__); \ |
| 53 | const std::string arg2(std::to_string(__LINE__)); \ |
| 54 | const std::string arg3(msg); \ |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 55 | std::runtime_error(create_error_msg(arg0, arg1, arg2, arg3)); \ |
| 56 | } while(false) |
| 57 | |
| 58 | } // namespace ckw |
| 59 | |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 60 | #endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H */ |