2

次のような単純なプラグインの例を実行しようとしています。

#include "gcc-plugin.h"
#include "tree.h"
#include "gimple.h"
#include "tree-pass.h"
#include <stdio.h>

extern void
test(void*gcc_data, void*b) {
    printf("Hellow world\n");
}

extern int plugin_init (struct plugin_name_args *plugin_info,
                        struct plugin_gcc_version *version)
{
    const char * nombre = "Hello world";
    register_callback(nombre, GIMPLE_PASS, &test, NULL);

    return 0;
}

しかしGIMPLE_PASSは事前定義されたイベントではなく、とでgcc-plugin.h何かをしなければならないことはわかっていますが、正確な方法がわからず、例も見つかりませんでした。PLUGIN_PASS_MANAGER_SETUPstruct pass_datatree-pass.h

誰かが私に方法を教えてくれますか?ありがとう。

4

1 に答える 1

3

おそらくこれはもう必要ないことはわかっていますが、他の人にとっては役立つ可能性があります。私は最近これに取り組んでおり、これに関するドキュメントはほとんどありません...できることは、いくつかの例を見つけることだけです(いくつか)そして彼らが何をしようとしているのかを理解しようとします(それがよくコメントされている場合)、私はgimpleコードを解析するようなプラグインを書いています。plugin_init

int plugin_init (plugin_name_args* plugin_info,
             plugin_gcc_version* ver)
{
  // You can get the plugin name
  const char * const plugin_name = plugin_info->base_name;
  cerr << "starting ";
  // here you can get the plugin args and number of args, 
  // look at https://gcc.gnu.org/onlinedocs/gccint/Plugins-loading.html#Plugins-loading
  // for more information how to give your plugin some args
  const int argc = plugin_info->argc;   
  const struct plugin_argument * const argv = plugin_info->argv;
  struct register_pass_info calls_printer_info;

  // Here you say where you need to put your plugin, mine is called after ssa
  // This is my pass
  calls_printer_info.pass                         = new calls_printer_pass();
  calls_printer_info.reference_pass_name          = "ssa" ;
  calls_printer_info.ref_pass_instance_number     = 1;
  calls_printer_info.pos_op                       = PASS_POS_INSERT_AFTER;
  register_callback (plugin_name,
                     PLUGIN_PASS_MANAGER_SETUP,
                     NULL,
                     &calls_printer_info);
  return 0;
}

前にパスを作成する必要があります:

static const struct pass_data calls_printer_pass_data = {
                .type                   = GIMPLE_PASS,
                .name                   = "calls_printer",
                .optinfo_flags          = OPTGROUP_NONE,
                .has_gate               = false,
                .has_execute            = true,
                .tv_id                  = TV_NONE,
                .properties_required    = PROP_cfg,
                .properties_provided    = 0,
                .properties_destroyed   = 0,
                .todo_flags_start       = 0,
                .todo_flags_finish      = 0
};

class calls_printer_pass : public gimple_opt_pass {
public:
        calls_printer_pass() : gimple_opt_pass(calls_printer_pass_data, g) {}
        // put the function you want to execute when the pass is executed
        unsigned int execute() { return my_function(); }
};

ライセンスのためにこれを忘れないでください:

int plugin_is_GPL_compatible;
于 2015-04-01T13:40:53.050 に答える