mageec  0.1.0
MAchine Guided Energy Efficient Compilation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
gcc-plugin.cpp
Go to the documentation of this file.
1 /* MAGEEC GCC Plugin
2  Copyright (C) 2013, 2014 Embecosm Limited and University of Bristol
3 
4  This file is part of MAGEEC.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 
20 /* We need to undefine these as gcc-plugin.h redefines them */
21 #undef PACKAGE_BUGREPORT
22 #undef PACKAGE_NAME
23 #undef PACKAGE_STRING
24 #undef PACKAGE_TARNAME
25 #undef PACKAGE_VERSION
26 
27 #include "gcc-plugin.h"
28 #include "tree-pass.h"
29 #include "mageec/mageec.h"
30 #include "mageec-plugin.h"
31 //#include <string>
32 
33 using namespace mageec;
34 
37 
39 static struct plugin_info mageec_plugin_version =
40 {
41  .version = "0.1.0",
42  .help = NULL
43 };
44 
45 std::map<std::string, int> mageec_config;
46 
47 static int print_plugin_info;
48 
49 
52 
55 
56 static void parse_arguments (int argc, struct plugin_argument *argv)
57 {
58  int i;
59  for (i = 0; i < argc; i++)
60  {
61  if (!strcmp (argv[i].key, "plugininfo"))
62  print_plugin_info = 1;
63  else if (!strcmp (argv[i].key, "dumppasses"))
64  mageec_config["print_pass_info"] = 1;
65  else if (!strcmp (argv[i].key, "nodecide"))
66  mageec_config["no_decision"] = 1;
67  else
68  fprintf (stderr, "MAGEEC Warning: Unknown option %s\n", argv[i].key);
69  }
70 }
71 
78 int plugin_init (struct plugin_name_args *plugin_info,
79  struct plugin_gcc_version *version)
80 {
81  /* Initilize options */
82  print_plugin_info = 0;
83  mageec_config["print_pass_info"] = 0;
84  mageec_config["no_decision"] = 0;
85 
86  /* Register our information, parse arguments. */
87  register_callback (plugin_info->base_name, PLUGIN_INFO, NULL,
88  &mageec_plugin_version);
89  mageec_gcc_plugin_name = plugin_info->base_name;
90  parse_arguments (plugin_info->argc, plugin_info->argv);
91  if (print_plugin_info)
92  mageec_gcc_plugin_info (plugin_info, version);
93 
94  /* Initialize MAGEEC Framework, returning error if failed. */
95  /* FIXME: Get real compiler version string and target. */
96  std::string compiler_version = "GCC-";
97  compiler_version += version->basever;
98  if (mageec_inst.init (compiler_version, "SOMETARGET"))
99  return 1;
100 
101  register_callback (plugin_info->base_name, PLUGIN_START_UNIT,
102  mageec_gcc_start_file, NULL);
103  register_callback (plugin_info->base_name, PLUGIN_FINISH_UNIT,
104  mageec_gcc_finish_file, NULL);
105  register_callback (plugin_info->base_name, PLUGIN_FINISH,
106  mageec_gcc_finish, NULL);
107  register_callback (plugin_info->base_name, PLUGIN_OVERRIDE_GATE,
108  mageec_pass_gate, NULL);
110 
111  return 0;
112 }