// file : odb/plugin.cxx // author : Boris Kolpackov // copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #include // Keep it first. #include // std::auto_ptr #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace semantics; int plugin_is_GPL_compatible; auto_ptr options_; extern "C" void gate_callback (void*, void*) { // If there were errors during compilation, let GCC handle the // exit. // if (errorcount || sorrycount) return; int r (0); try { parser p (*options_, loc_pragmas_, decl_pragmas_); path file (main_input_filename); auto_ptr u (p.parse (global_namespace, file)); // // validator v; if (!v.validate (*options_, *u, file)) r = 1; // // if (r == 0) { generator g; g.generate (*options_, *u, file); } } catch (parser::failed const&) { // Diagnostics has aready been issued. // r = 1; } catch (generator::failed const&) { // Diagnostics has aready been issued. // r = 1; } exit (r); } static char const* const odb_version = ODB_COMPILER_VERSION_STR; extern "C" int plugin_init (plugin_name_args* plugin_info, plugin_gcc_version*) { int r (0); plugin_info->version = odb_version; try { // Parse options. // { vector argv_str; vector argv; argv_str.push_back (plugin_info->base_name); argv.push_back (const_cast (argv_str.back ().c_str ())); for (int i (0); i < plugin_info->argc; ++i) { plugin_argument& a (plugin_info->argv[i]); string opt (strlen (a.key) > 1 ? "--" : "-"); opt += a.key; argv_str.push_back (opt); argv.push_back (const_cast (argv_str.back ().c_str ())); if (a.value != 0) { argv_str.push_back (a.value); argv.push_back (const_cast (argv_str.back ().c_str ())); } } int argc (static_cast (argv.size ())); cli::argv_file_scanner scan (argc, &argv[0], "--options-file"); options_.reset ( new options (scan, cli::unknown_mode::fail, cli::unknown_mode::fail)); } if (options_->trace ()) cerr << "starting plugin " << plugin_info->base_name << endl; // Disable assembly output. // asm_file_name = HOST_BIT_BUCKET; // Register callbacks. // register_callback (plugin_info->base_name, PLUGIN_PRAGMAS, register_odb_pragmas, 0); register_callback (plugin_info->base_name, PLUGIN_OVERRIDE_GATE, &gate_callback, 0); } catch (cli::exception const& ex) { cerr << ex << endl; r = 1; } if (r != 0) exit (r); return r; }