1515#include < cctype>
1616#include < cstdint>
1717#include < functional>
18+ #include < string>
19+ #include < unordered_map>
1820
1921extern int memcpy_s (void *dst, size_t destSize, const void *src, size_t count);
2022
2123namespace NEO {
2224
25+ using StringMap = std::unordered_map<uint32_t , std::string>;
26+
2327enum class PRINTF_DATA_TYPE : int {
2428 INVALID,
2529 BYTE,
@@ -40,12 +44,14 @@ enum class PRINTF_DATA_TYPE : int {
4044
4145class PrintFormatter {
4246 public:
43- PrintFormatter (Kernel &kernelArg, GraphicsAllocation &dataArg);
47+ PrintFormatter (const uint8_t *printfOutputBuffer, uint32_t printfOutputBufferMaxSize,
48+ bool using32BitPointers, const StringMap &stringLiteralMap);
4449 void printKernelOutput (const std::function<void (char *)> &print = [](char *str) { printToSTDOUT (str); });
4550
4651 static const size_t maxPrintfOutputLength = 1024 ;
4752
4853 protected:
54+ const char *queryPrintfString (uint32_t index) const ;
4955 void printString (const char *formatString, const std::function<void (char *)> &print);
5056 size_t printToken (char *output, size_t size, const char *formatString);
5157 size_t printStringToken (char *output, size_t size, const char *formatString);
@@ -58,15 +64,15 @@ class PrintFormatter {
5864
5965 template <class T >
6066 bool read (T *value) {
61- if (offset + sizeof (T) <= bufferSize ) {
62- auto srcPtr = reinterpret_cast <T *>(buffer + offset );
67+ if (currentOffset + sizeof (T) <= printfOutputBufferSize ) {
68+ auto srcPtr = reinterpret_cast <const T *>(printfOutputBuffer + currentOffset );
6369
6470 if (isAligned (srcPtr)) {
6571 *value = *srcPtr;
6672 } else {
67- memcpy_s (value, bufferSize - offset , srcPtr, sizeof (T));
73+ memcpy_s (value, printfOutputBufferSize - currentOffset , srcPtr, sizeof (T));
6874 }
69- offset += sizeof (T);
75+ currentOffset += sizeof (T);
7076 return true ;
7177 } else {
7278 return false ;
@@ -101,17 +107,18 @@ class PrintFormatter {
101107 }
102108
103109 if (sizeof (T) < 4 ) {
104- offset += (4 - sizeof (T)) * valueCount;
110+ currentOffset += (4 - sizeof (T)) * valueCount;
105111 }
106112
107113 return charactersPrinted;
108114 }
109115
110- Kernel &kernel;
111- GraphicsAllocation &data;
116+ const uint8_t *printfOutputBuffer = nullptr ; // buffer extracted from the kernel, contains values to be printed
117+ uint32_t printfOutputBufferSize = 0 ; // size of the data contained in the buffer
118+
119+ const StringMap &stringLiteralMap;
120+ bool using32BitPointers = false ;
112121
113- uint8_t *buffer; // buffer extracted from the kernel, contains values to be printed
114- uint32_t bufferSize; // size of the data contained in the buffer
115- uint32_t offset; // current position in currently parsed buffer
122+ uint32_t currentOffset = 0 ; // current position in currently parsed buffer
116123};
117124}; // namespace NEO
0 commit comments