1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2017-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #pragma once
10
11 #include "ocl_igc_interface/ocl_translation_output.h"
12
13 #include "cif/builtins/memory/buffer/impl/buffer_impl.h"
14 #include "cif/export/muiltiversion.h"
15 #include "cif/export/pimpl_base.h"
16
17 #include "cif/macros/enable.h"
18
19 namespace IGC{
20
21 struct TranslationErrorType
22 {
23 using ErrorCode_t = uint64_t;
24 using ErrorCodeCoder = CIF::Coder<ErrorCode_t>;
25
26 static constexpr ErrorCode_t Success = ErrorCodeCoder::Enc("E_SUCCESS");
27 static constexpr ErrorCode_t Internal = ErrorCodeCoder::Enc("E_INTERNAL");
28 static constexpr ErrorCode_t Unused = ErrorCodeCoder::Enc("E_UNUSED");
29 static constexpr ErrorCode_t Unknown = ErrorCodeCoder::Enc("E_UNKNOWN");
30 static constexpr ErrorCode_t FailedCompilation = ErrorCodeCoder::Enc("E_FAIL_COMP");
31 static constexpr ErrorCode_t InvalidInput = ErrorCodeCoder::Enc("E_INV_INPUT");
32 static constexpr ErrorCode_t UnhandledInput = ErrorCodeCoder::Enc("E_UNH_INPUT");
33 };
34
CIF_DECLARE_INTERFACE_PIMPL(OclTranslationOutput)35 CIF_DECLARE_INTERFACE_PIMPL(OclTranslationOutput) : CIF::PimplBase
36 {
37 CIF_PIMPL_DECLARE_CONSTRUCTOR(CodeType::CodeType_t OutputType)
38 : OutputType(OutputType), Error(TranslationErrorType::Unused)
39 {
40 BuildLog.CreateImpl();
41 Output.CreateImpl();
42 DebugData.CreateImpl();
43 }
44
45 bool Successful() const
46 {
47 return Error == TranslationErrorType::Success;
48 }
49
50 bool HasWarnings() const
51 {
52 return false;
53 }
54
55 CIF::Builtins::BufferBase * GetBuildLog(CIF::Version_t bufferVersion)
56 {
57 return BuildLog.GetVersion(bufferVersion);
58 }
59
60 CIF::Builtins::BufferBase * GetOutput(CIF::Version_t bufferVersion)
61 {
62 return Output.GetVersion(bufferVersion);
63 }
64
65 CIF::Builtins::BufferBase * GetDebugData(CIF::Version_t bufferVersion)
66 {
67 return DebugData.GetVersion(bufferVersion);
68 }
69
70 CodeType::CodeType_t GetOutputType() const
71 {
72 return OutputType;
73 }
74
75 bool SetError(TranslationErrorType::ErrorCode_t e, const char * errString = nullptr)
76 {
77 this->Error = e;
78
79 if(errString == nullptr){
80 return true;
81 }
82
83 auto len = strlen(errString);
84 return BuildLog->PushBackRawBytes(errString, len + 1);
85 }
86
87 bool AddWarning(const std::string & warnString)
88 {
89 return AddWarning(warnString.c_str(), warnString.size());
90 }
91
92 bool AddWarning(const char * warn, size_t warnLength)
93 {
94 if((warn == nullptr) || (warnLength == 0)){
95 return true;
96 }
97
98 if(BuildLog->GetSizeRaw() > 0){
99 char * lastChar = reinterpret_cast<char*>(BuildLog->GetMemoryRawWriteable()) + BuildLog->GetSizeRaw() - 1;
100 if(*lastChar == '\0'){
101 *lastChar = '\n';
102 }else{
103 if(BuildLog->PushBackRawCopy('\n') == false){
104 return false;
105 }
106 }
107 }
108 if(BuildLog->PushBackRawBytes(warn, warnLength) == false){
109 return false;
110 }
111 char * lastChar = reinterpret_cast<char*>(BuildLog->GetMemoryRawWriteable()) + BuildLog->GetSizeRaw() - 1;
112 if(*lastChar != '\0'){
113 return BuildLog->PushBackRawCopy('\0');
114 }
115
116 return true;
117 }
118
119 template<typename T>
120 bool SetSuccessfulAndCloneOutput(const T * data, size_t size)
121 {
122 this->Error = TranslationErrorType::Success;
123 return Output->PushBackRawBytes(data, size);
124 }
125
126 bool CloneDebugData(const char * data, size_t size)
127 {
128 return DebugData->PushBackRawBytes(data, size);
129 }
130
131 protected:
132 CIF::Multiversion<CIF::Builtins::Buffer> BuildLog;
133 CIF::Multiversion<CIF::Builtins::Buffer> Output;
134 CIF::Multiversion<CIF::Builtins::Buffer> DebugData;
135 CodeType::CodeType_t OutputType;
136 TranslationErrorType::ErrorCode_t Error;
137 };
138
139 CIF_DEFINE_INTERFACE_TO_PIMPL_FORWARDING_CTOR_DTOR(OclTranslationOutput);
140
141 }
142
143 #include "cif/macros/disable.h"
144