From ca5a8162eb764072b7b5972264d2b22f8752a1e1 Mon Sep 17 00:00:00 2001 From: Krystian Chmielewski Date: Wed, 26 Jan 2022 14:18:16 +0000 Subject: [PATCH] Printf zebin: accept string type pointer In zebin type POINTER and address of strings are written into print buffer. This change allows the type to be POINTER=7, before only STRING=5 type was accepted. Signed-off-by: Krystian Chmielewski --- .../unit_test/program/printf_helper_tests.cpp | 6 +++--- shared/source/program/print_formatter.cpp | 18 ++++++++---------- shared/source/program/print_formatter.h | 3 ++- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/opencl/test/unit_test/program/printf_helper_tests.cpp b/opencl/test/unit_test/program/printf_helper_tests.cpp index adfa6951bf..dec3f4e904 100644 --- a/opencl/test/unit_test/program/printf_helper_tests.cpp +++ b/opencl/test/unit_test/program/printf_helper_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -894,10 +894,10 @@ TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithFormatStringAnd2StringsT storeData(formatString); const char *string1 = "str1"; - storeData(PRINTF_DATA_TYPE::STRING); + storeData(PRINTF_DATA_TYPE::POINTER); storeData(string1); const char *string2 = "str2"; - storeData(PRINTF_DATA_TYPE::STRING); + storeData(PRINTF_DATA_TYPE::POINTER); storeData(string2); const char *expectedOutput = "str1 str2"; diff --git a/shared/source/program/print_formatter.cpp b/shared/source/program/print_formatter.cpp index e46fc170ff..0d595b956b 100644 --- a/shared/source/program/print_formatter.cpp +++ b/shared/source/program/print_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -149,7 +149,7 @@ size_t PrintFormatter::printToken(char *output, size_t size, const char *formatS } size_t PrintFormatter::printStringToken(char *output, size_t size, const char *formatString) { - int type = 0; + PRINTF_DATA_TYPE type = PRINTF_DATA_TYPE::INVALID; read(&type); const char *string = nullptr; @@ -158,18 +158,16 @@ size_t PrintFormatter::printStringToken(char *output, size_t size, const char *f read(&index); string = queryPrintfString(index); } else { - char *str = nullptr; - read(&str); - string = str; + read(&string); } - if (type == static_cast(PRINTF_DATA_TYPE::STRING)) { - return simple_sprintf(output, size, formatString, string); - } else { + switch (type) { + default: return simple_sprintf(output, size, formatString, 0); + case PRINTF_DATA_TYPE::STRING: + case PRINTF_DATA_TYPE::POINTER: + return simple_sprintf(output, size, formatString, string); } - - return 0; } size_t PrintFormatter::printPointerToken(char *output, size_t size, const char *formatString) { diff --git a/shared/source/program/print_formatter.h b/shared/source/program/print_formatter.h index 05d40d2727..e7c9dab187 100644 --- a/shared/source/program/print_formatter.h +++ b/shared/source/program/print_formatter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -41,6 +41,7 @@ enum class PRINTF_DATA_TYPE : int { VECTOR_FLOAT, VECTOR_DOUBLE }; +static_assert(sizeof(PRINTF_DATA_TYPE) == sizeof(int)); class PrintFormatter { public: