Mikhail Glushenkov | c82ce4a | 2008-09-22 20:49:34 +0000 | [diff] [blame] | 1 | //===--- Plugin.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open |
| 6 | // Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Plugin support for llvmc2. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Mikhail Glushenkov | 4a1a77c | 2008-09-22 20:50:40 +0000 | [diff] [blame] | 14 | #include "llvm/CompilerDriver/Plugin.h" |
Mikhail Glushenkov | c82ce4a | 2008-09-22 20:49:34 +0000 | [diff] [blame] | 15 | |
| 16 | #include <vector> |
| 17 | |
| 18 | namespace { |
Mikhail Glushenkov | 14ef059 | 2008-09-22 20:51:19 +0000 | [diff] [blame^] | 19 | |
| 20 | // Registry::Add<> does not do lifetime management (probably issues |
| 21 | // with static constructor/destructor ordering), so we have to |
| 22 | // implement it here. |
| 23 | // |
| 24 | // All this static registration/life-before-main model seems |
| 25 | // unnecessary convoluted to me. |
| 26 | |
| 27 | static bool pluginListInitialized = false; |
| 28 | typedef std::vector<const llvmc::BasePlugin*> PluginList; |
| 29 | static PluginList Plugins; |
Mikhail Glushenkov | c82ce4a | 2008-09-22 20:49:34 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | namespace llvmc { |
| 33 | |
Mikhail Glushenkov | 14ef059 | 2008-09-22 20:51:19 +0000 | [diff] [blame^] | 34 | PluginLoader::PluginLoader() { |
| 35 | if (!pluginListInitialized) { |
| 36 | for (PluginRegistry::iterator B = PluginRegistry::begin(), |
| 37 | E = PluginRegistry::end(); B != E; ++B) |
| 38 | Plugins.push_back(B->instantiate()); |
| 39 | } |
| 40 | pluginListInitialized = true; |
Mikhail Glushenkov | c82ce4a | 2008-09-22 20:49:34 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Mikhail Glushenkov | 14ef059 | 2008-09-22 20:51:19 +0000 | [diff] [blame^] | 43 | PluginLoader::~PluginLoader() { |
| 44 | if (pluginListInitialized) { |
| 45 | for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); |
| 46 | B != E; ++B) |
| 47 | delete (*B); |
| 48 | } |
| 49 | pluginListInitialized = false; |
| 50 | } |
| 51 | |
| 52 | void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) { |
| 53 | for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); |
| 54 | B != E; ++B) |
Mikhail Glushenkov | c82ce4a | 2008-09-22 20:49:34 +0000 | [diff] [blame] | 55 | (*B)->PopulateLanguageMap(langMap); |
| 56 | } |
| 57 | |
Mikhail Glushenkov | 14ef059 | 2008-09-22 20:51:19 +0000 | [diff] [blame^] | 58 | void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) { |
| 59 | for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); |
| 60 | B != E; ++B) |
Mikhail Glushenkov | c82ce4a | 2008-09-22 20:49:34 +0000 | [diff] [blame] | 61 | (*B)->PopulateCompilationGraph(graph); |
| 62 | } |
| 63 | |
| 64 | } |