================
@@ -47,3 +49,32 @@ Expected<PassPlugin> PassPlugin::Load(const std::string 
&Filename) {
 
   return P;
 }
+
+Error llvm::passPluginArguments(ArrayRef<PassPluginLibraryInfo> Infos,
+                                ArrayRef<std::string> Args) {
+  DenseMap<StringRef, unsigned> Index;
+  for (auto [I, Info] : enumerate(Infos))
+    Index[Info.PluginName] = I;
+  // The argument follows the first comma, so it is NUL-terminated.
+  SmallVector<SmallVector<const char *, 0>, 0> PluginArgs(Infos.size());
+  for (const std::string &Arg : Args) {
+    auto [Name, Rest] = StringRef(Arg).split(',');
+    if (!Rest.data())
+      return createStringError("expected <plugin>,<arg> in -plugin-arg=" + 
Arg);
+    auto It = Index.find(Name);
+    if (It == Index.end())
+      return createStringError("no pass plugin named '" + Name +
+                               "' is loaded, in -plugin-arg=" + Arg);
+    PluginArgs[It->second].push_back(Rest.data());
----------------
aengelke wrote:

Please add a comment explaining why Rest is null-terminated. This seems rather 
sketchy but is unfortunately necessary due to cl::ParseCommandLineOptions API 
limitations...

https://github.com/llvm/llvm-project/pull/226773
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to