Skip to content

Commit 1f53dbf

Browse files
committed
Added Handling for InitListExprByte; updated the plugin registration to not have a dash '-' in the name; added test case of a std::array; Renamed StaticWritePlugin.cpp to StaticIOPlugin.cpp
1 parent ee1e59f commit 1f53dbf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

StaticWritePlugin.cpp renamed to StaticIOPlugin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class StaticFunctionVisitor : public RecursiveASTVisitor<StaticFunctionVisitor>
3838
// Handle string literals
3939
if (const StringLiteral *SL = dyn_cast<StringLiteral>(string_expr)) {
4040
llvm::StringRef Str = SL->getString();
41-
llvm::errs() << "Evaluated string literal: " << Str << "\n";
4241
// Convert the string to std::basic_string<uint8_t>
4342
return std::basic_string<uint8_t>(Str.bytes_begin(), Str.bytes_end());
4443
}
@@ -59,6 +58,8 @@ class StaticFunctionVisitor : public RecursiveASTVisitor<StaticFunctionVisitor>
5958
Result.push_back(static_cast<uint8_t>(num));
6059
} else if (const auto *CharLit = dyn_cast<CharacterLiteral>(E)) {
6160
Result.push_back(static_cast<uint8_t>(CharLit->getValue()));
61+
} else if(const auto *ListExpr = dyn_cast<InitListExpr>(E)) {
62+
return GetString(E);
6263
} else {
6364
llvm::errs() << "Unsupported array element type " << E->getStmtClassName();
6465
return {};
@@ -113,6 +114,7 @@ class StaticFunctionVisitor : public RecursiveASTVisitor<StaticFunctionVisitor>
113114
auto fname = EvaluateString(fnameExpr);
114115
if (fname.empty()) {
115116
llvm::errs() << "Filename is not valid or could not be resolved.\n";
117+
return;
116118
}
117119
const char * fname_c_str = reinterpret_cast<const char *>(fname.data());
118120
llvm::errs() << "Filename evaluated: " << fname_c_str << "\n";
@@ -174,4 +176,4 @@ class StaticWriteAction : public PluginASTAction {
174176

175177
// Register the plugin with Clang
176178
static FrontendPluginRegistry::Add<StaticWriteAction>
177-
X("static-write", "Evaluates constexpr byte array in static_write and writes to a file at compile time");
179+
X("staticio", "Evaluates constexpr byte array and writes/reads a file at compile time");

main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int main() {
2323
static_write("/dev/stdout", arr<data>()); // This will write the byte array to "output.bin"
2424
static_write("/dev/stdout", data);
2525
static_write("/dev/stdout", "this is a test\n"); // This will write the byte array to "output.bin"
26+
static_write("/dev/stdout", std_arr_data.data());
2627
static_write("/dev/stdout", arr2<data>());
2728
return 0;
2829
}

0 commit comments

Comments
 (0)