Created
March 20, 2018 11:39
-
-
Save aolo2/6e937aca5de1cf501198a94275a07468 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "gcc-plugin.h" | |
int plugin_is_GLP_complatinle = 1; | |
static struct plugin_info gimple_print_info = | |
{ | |
.version = "1", | |
.help = "Display the GIMPLE/IR in a readable manner", | |
}; | |
static sturct plugin_gcc_version gimple_print_ver = | |
{ | |
.basever = "8.0.1", | |
.datestamp = "20180316", | |
.devphase = "experimental", | |
.revision = "", | |
}; | |
static struct gimple_opt_pass gimple_print_pass = | |
{ | |
.pass.type = GIMPLE_PASS, | |
.pass.name = "gimple-print", | |
/* | |
* This pass and all sub-passes are executed only if the function returns | |
* true. The default implementation returns true. | |
*/ | |
.pass.gate = gimple_print_gate, | |
/* | |
* This is the code to run. If this is not overridden, then there should | |
* be sub-passes otherwise this pass does nothing. | |
* The return value contains TODOs to execute in addition to those in | |
* TODO_flags_finish. | |
*/ | |
.pass.execute = gimple_print_exec, | |
}; | |
/* Return 0 on success or error code on failure */ | |
int plugin_init(struct plugin_name_args *info, // Argument information */ | |
struct plugin_gcc_version *ver) // Version info of GCC | |
{ | |
/* | |
* Used to tell the plugin-framework about where we want to be called in the | |
* set of all passes. This is located in tree-pass.h | |
*/ | |
struct register_pass_info pass; | |
printf("GIMPLE-PRINT plugin initialized...\n"); | |
/* Check that the GCC version is in line with the plugin requirements */ | |
plugin_default_version_check(); | |
/* | |
* Setup the info to register with GCC telling when we want to be called and | |
* to what GCC should call, when it's time to be called. | |
*/ | |
pass.pass = &gimple_print_pass.pass; | |
/* | |
* Get called after GCC has produced the SSA representation of the program. | |
* After the first SSA pass. | |
*/ | |
pass.reference_pass_name = "ssa"; | |
pass.ref_pass_instance_number = 1; | |
pass.pos_op = PASS_POS_INSERT_AFTER; | |
/* Tell GCC we want to be called after the first SSA pass */ | |
register_callback("gimple-print", PLUGIN_PASS_MANAGER_SETUP, NULL, &pass); | |
/* Tell GCC some info about the plugin (used when --version or --help are called) */ | |
register_callback("gimple-print", PLUGIN_INFO, NULL, &gimple_print_info); | |
/* Success */ | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment