从GCC功能树节点中检索函数参数
Retrieve function arguments from gcc function tree node
这个问题的重点是GCC内部。我正在尝试使用GCC通用树。这个小型项目是为了教育目的编译硬编码的前端。我设法向外部调用printf,并能够编译能够打印测试消息的可执行文件。后者证明我设法为函数准备参数。问题的本质是调用我自己的功能/方法并检索其参数。
这是我准备电话的地方:
tree testFn;
tree testFndeclTypeParam[] = {
integer_type_node
};
tree testFndeclType = build_varargs_function_type_array(integer_type_node, 1, testFndeclTypeParam);
tree testFnDecl = build_fn_decl("testFunc", testFndeclType);
DECL_EXTERNAL(testFnDecl) = 1;
testFn = build1(ADDR_EXPR, build_pointer_type(testFndeclType), testFnDecl);
tree exprTest = build_int_cst_type(integer_type_node, 20);
tree testStmt = build_call_array_loc(UNKNOWN_LOCATION, integer_type_node, testFn, 1, testArgs);
append_to_statement_list(testStmt, &stackStmtList);
我可以确认肯定称为" testfunc"函数。
现在是另一侧,这是称为:
的功能 // Built type of main "int (int)"
tree mainFndeclTypeParam[] = {
integer_type_node, // int
};
tree mainFndeclType = build_function_type_array(integer_type_node, 1, mainFndeclTypeParam);
tree mainFndecl = build_fn_decl("testFunc", mainFndeclType);
tree stackStmtList = alloc_stmt_list();
tree parmList = build_decl(UNKNOWN_LOCATION, PARM_DECL, mainFndecl, integer_type_node);
我找不到一个明确的示例,显示如何检索参数,但期望它在parmlist中,参数树节点。
这是我对GCC编译器设计感兴趣的人解决问题的方法。感谢Google或曾经维护Java前端的人。
应该是:
tree typelist = TYPE_ARG_TYPES(TREE_TYPE(mainFndecl));
tree typeOfList = TREE_VALUE(typelist);
tree parmList = build_decl(UNKNOWN_LOCATION, PARM_DECL, NULL_TREE, typeOfList);
tree *ptr = &DECL_ARGUMENTS(mainFndecl);
*ptr = parmList;
可以使用tree_chain(如果有)来检索下一个参数。
相关文章:
- 如何检索指向在单独线程上运行的函数的移动指针?
- std::shared_ptr 使用别名构造函数,是否可以检索初始指针值?
- 有什么方法可以从不同函数的变量中检索值吗?c++
- Getter 函数,用于在 2d 数组是类的数据成员时检索 2d 数组元素
- 用于检索当前正在使用的应用程序的函数
- 如何在函数中检索指针结构
- 插入不从哈希函数中检索键
- 我如何从循环内部使用迭代器的函数内部的getter中检索特定的成员
- 如何在没有辅助函数模板的情况下检索可变参数模板参数
- 使用 getter 函数时,C++ 无法检索正确的值
- 通过空隙函数检索所有数据
- 从GCC功能树节点中检索函数参数
- 是否可以检索 C++11 中线程函数的返回值
- 从未知dll(c++)中检索函数(名称、返回类型、参数)
- 如何从另一个过程的Callstack地址检索函数名称
- 用于在C++代码库中检索函数和方法列表的工具
- 从容器中检索函数指针
- 数组列表和使用插入和检索函数的问题(段核心转储)
- Boost协程如何在coro_t完成后检索函数返回值
- 检索函数调用图