この質問はgccの内部構造に焦点を当てています。私はgcc genericツリーを試しています。この小さなプロジェクトは、教育目的のためだけにハードコードされたフロントエンドをコンパイルすることです。私はprintfを外部から呼び出すことができ、テストメッセージを出力できる実行可能ファイルをコンパイルすることができました。後者は、私が関数の引数を用意することができるという証拠です。この問題の本質は、自分の関数/メソッドを呼び出して引数を取り出すことです。gcc関数ツリーノードから関数の引数を取得する
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、引数のツリーノードであることが予想できませんでした。
最小限で完全な自立型ソースコードの例を提供してください。コンソール用の適切なコンパイル/リンクコマンドは高く評価されます。 – Scheff
@Scheff自立的な例がこれには大きくなるだろうが、興味を持ってくれてありがとう。私はコマンドライン "gccsample main.exp testFunc.exp"を使います。 2つのファイルは、コンパイラを起動するための単なるダミーです。 – Tanyong