Skip to content

Commit 9447e0d

Browse files
committed
Use string-to-int table
1 parent a446e06 commit 9447e0d

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

offload/include/Shared/Debug.h

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,26 @@ inline DebugOptionTy &getDebugOption() {
117117
OptVal.Level = std::atoi(EnvStr);
118118
if (OptVal.Level)
119119
return OptVal; // defined as numeric value
120+
struct DebugStrToBitTy {
121+
const char *Str;
122+
uint32_t Bit;
123+
} DebugStrToBit[] = {
124+
{"rtl", DEBUG_INFOTYPE_RTL}, {"device", DEBUG_INFOTYPE_DEVICE},
125+
{"module", DEBUG_INFOTYPE_MODULE}, {"kernel", DEBUG_INFOTYPE_KERNEL},
126+
{"memory", DEBUG_INFOTYPE_MEMORY}, {"map", DEBUG_INFOTYPE_MAP},
127+
{"copy", DEBUG_INFOTYPE_COPY}, {"interop", DEBUG_INFOTYPE_INTEROP},
128+
{"tool", DEBUG_INFOTYPE_TOOL}, {"api", DEBUG_INFOTYPE_API},
129+
{"all", DEBUG_INFOTYPE_ALL}, {nullptr, 0},
130+
};
120131
// Check string value of the option
121132
std::istringstream Tokens(EnvStr);
122133
for (std::string Token; std::getline(Tokens, Token, ',');) {
123-
if (Token == "rtl")
124-
OptVal.Type |= DEBUG_INFOTYPE_RTL;
125-
else if (Token == "device")
126-
OptVal.Type |= DEBUG_INFOTYPE_DEVICE;
127-
else if (Token == "module")
128-
OptVal.Type |= DEBUG_INFOTYPE_MODULE;
129-
else if (Token == "kernel")
130-
OptVal.Type |= DEBUG_INFOTYPE_KERNEL;
131-
else if (Token == "memory")
132-
OptVal.Type |= DEBUG_INFOTYPE_MEMORY;
133-
else if (Token == "map")
134-
OptVal.Type |= DEBUG_INFOTYPE_MAP;
135-
else if (Token == "copy")
136-
OptVal.Type |= DEBUG_INFOTYPE_COPY;
137-
else if (Token == "interop")
138-
OptVal.Type |= DEBUG_INFOTYPE_INTEROP;
139-
else if (Token == "tool")
140-
OptVal.Type |= DEBUG_INFOTYPE_TOOL;
141-
else if (Token == "api")
142-
OptVal.Type |= DEBUG_INFOTYPE_API;
143-
else if (Token == "all")
144-
OptVal.Type |= DEBUG_INFOTYPE_ALL;
134+
for (int I = 0; DebugStrToBit[I].Str; I++) {
135+
if (Token == DebugStrToBit[I].Str) {
136+
OptVal.Type |= DebugStrToBit[I].Bit;
137+
break;
138+
}
139+
}
145140
}
146141
return OptVal;
147142
}();

0 commit comments

Comments
 (0)