Skip to content

Commit ca5a816

Browse files
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 <[email protected]>
1 parent 6f62a78 commit ca5a816

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

opencl/test/unit_test/program/printf_helper_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -894,10 +894,10 @@ TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithFormatStringAnd2StringsT
894894
storeData(formatString);
895895

896896
const char *string1 = "str1";
897-
storeData(PRINTF_DATA_TYPE::STRING);
897+
storeData(PRINTF_DATA_TYPE::POINTER);
898898
storeData(string1);
899899
const char *string2 = "str2";
900-
storeData(PRINTF_DATA_TYPE::STRING);
900+
storeData(PRINTF_DATA_TYPE::POINTER);
901901
storeData(string2);
902902

903903
const char *expectedOutput = "str1 str2";

shared/source/program/print_formatter.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -149,7 +149,7 @@ size_t PrintFormatter::printToken(char *output, size_t size, const char *formatS
149149
}
150150

151151
size_t PrintFormatter::printStringToken(char *output, size_t size, const char *formatString) {
152-
int type = 0;
152+
PRINTF_DATA_TYPE type = PRINTF_DATA_TYPE::INVALID;
153153
read(&type);
154154

155155
const char *string = nullptr;
@@ -158,18 +158,16 @@ size_t PrintFormatter::printStringToken(char *output, size_t size, const char *f
158158
read(&index);
159159
string = queryPrintfString(index);
160160
} else {
161-
char *str = nullptr;
162-
read(&str);
163-
string = str;
161+
read(&string);
164162
}
165163

166-
if (type == static_cast<int>(PRINTF_DATA_TYPE::STRING)) {
167-
return simple_sprintf(output, size, formatString, string);
168-
} else {
164+
switch (type) {
165+
default:
169166
return simple_sprintf(output, size, formatString, 0);
167+
case PRINTF_DATA_TYPE::STRING:
168+
case PRINTF_DATA_TYPE::POINTER:
169+
return simple_sprintf(output, size, formatString, string);
170170
}
171-
172-
return 0;
173171
}
174172

175173
size_t PrintFormatter::printPointerToken(char *output, size_t size, const char *formatString) {

shared/source/program/print_formatter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -41,6 +41,7 @@ enum class PRINTF_DATA_TYPE : int {
4141
VECTOR_FLOAT,
4242
VECTOR_DOUBLE
4343
};
44+
static_assert(sizeof(PRINTF_DATA_TYPE) == sizeof(int));
4445

4546
class PrintFormatter {
4647
public:

0 commit comments

Comments
 (0)