我如何将可变数量的参数传递给LLVM OPT PASS
How do I pass a variable number of arguments to a LLVM opt pass?
我想将可变数量的参数传递给我的llvm opt pass。
为此,我做了类似的事情:
static cl::list<std::string> Files(cl::Positional, cl::OneOrMore);
static cl::list<std::string> Libraries("l", cl::ZeroOrMore);
但是,如果我现在调用类似的选择:
foo@foo-Ubuntu:~/llvm-ir-obfuscation$ opt -load cmake-build-debug/water/libMapInstWMPass.so -mapiWM programs/ll/sum100.ll -S 2 3 4 -o foo.ll
opt: Too many positional arguments specified!
Can specify at most 2 positional arguments: See: opt -help
,然后我会得到OPT最多接受2个位置参数的错误。
我在做什么错?
我认为问题是opt
已经在解析其自己的参数,并且已经具有作为位置参数处理的比特码文件,因此拥有一个以上的位置参数会产生歧义。p>该文档将API解释,就好像它在独立应用程序中使用一样。因此,例如,如果您做这样的事情:
int main(int argc, char *argv[]) {
cl::list<std::string> Files(cl::Positional, cl::OneOrMore);
cl::list<std::string> Files2(cl::Positional, cl::OneOrMore);
cl::list<std::string> Libraries("l", cl::ZeroOrMore);
cl::ParseCommandLineOptions(argc, argv);
for(auto &e : Libraries) outs() << e << "n";
outs() << "....n";
for(auto &e : Files) outs() << e << "n";
outs() << "....n";
for(auto &e : Files2) outs() << e << "n";
outs() << "....n";
}
您得到这样的东西:
$ foo -l one two three four five six
one
....
two
three
four
five
....
six
....
现在,如果您围绕两个位置参数定义进行交换,或者甚至将Files2
的cl::OneOrMore
选项更改为cl::ZeroOrMore
,则将获得错误
$ option: error - option can never match, because another positional argument will match an unbounded number of values, and this option does not require a value!
个人,当我使用 opt
i放置位置参数选项时,请执行类似的操作:
cl::list<std::string> Lists("lists", cl::desc("Specify names"), cl::OneOrMore);
可以做到这一点:
opt -load ./fooPass.so -foo -o out.bc -lists one ./in.bc -lists two
和std::string
上的迭代列表以我获得的方式相同:
one
two
@compor建议,这可能与opt
和您自己的通过的交织论点有关。命令行库主要是为LLVM框架中的独立应用程序编写的。
但是,您可以做类似:
的事情static cl::list<std::string> Args1("args1", cl::Positional, cl::CommaSeparated);
static cl::list<std::string> Args2("args2", cl::ZeroOrMore);
这具有一个优势,您可以使用逗号,例如arg1,arg2,...
或使用标识符-args1 arg1 arg2 ...
在命令行上输入多个参数;这些被插入到Args1
列表中。如果您仅在命令行上提供单个位置参数arg
,则Args1
仅包含此参数。
另外,您可以在命令行上指定-args2 arg
(命名为非置位选项(。这些将进入Args2
列表。
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 使用指向成员的指针将成员函数作为参数传递
- 如何将参数传递给正在使用模板的类
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 修改函数中的指针(将另一个指针作为参数传递)
- 如何将部分流作为参数传递
- 我正在开发服务器,ip作为参数传递不起作用
- 将成员函数指针作为参数传递给模板方法
- 如何在C++中将迭代器作为函数参数传递
- 将附加参数传递给使用 beast::bind_front_handler 调用的函数
- 如何将一个类的函数作为另一个类的另一个函数的参数传递
- 将参数传递为"const"的奇怪效果
- 如何在 c++ 中将函数作为参数传递?
- 在 C++ 中将非指定类型作为参数传递的最佳方法?
- 使用引用与指针将数组作为参数传递
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 将参数打包的参数传递到 std::queue 中,以便稍后使用不同的函数调用
- 为什么我不能将引用作为 std::async 的函数参数传递
- 如何在不使用指针的情况下将派生类的对象作为参数传递给基类中的函数?
- LLVM 的 ExecutionEngine::runFunction 将错误的参数传递给函数。为什么?