blob: c9b3960c1e75c2fbbdc0e227e047ff5c9420ae58 [file] [log] [blame]
Mikhail Glushenkovc82ce4a2008-09-22 20:49:34 +00001//===--- 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 Glushenkov4a1a77c2008-09-22 20:50:40 +000014#include "llvm/CompilerDriver/Plugin.h"
Mikhail Glushenkovc82ce4a2008-09-22 20:49:34 +000015
16#include <vector>
17
18namespace {
Mikhail Glushenkov14ef0592008-09-22 20:51:19 +000019
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 Glushenkovc82ce4a2008-09-22 20:49:34 +000030}
31
32namespace llvmc {
33
Mikhail Glushenkov14ef0592008-09-22 20:51:19 +000034 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 Glushenkovc82ce4a2008-09-22 20:49:34 +000041 }
42
Mikhail Glushenkov14ef0592008-09-22 20:51:19 +000043 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 Glushenkovc82ce4a2008-09-22 20:49:34 +000055 (*B)->PopulateLanguageMap(langMap);
56 }
57
Mikhail Glushenkov14ef0592008-09-22 20:51:19 +000058 void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) {
59 for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
60 B != E; ++B)
Mikhail Glushenkovc82ce4a2008-09-22 20:49:34 +000061 (*B)->PopulateCompilationGraph(graph);
62 }
63
64}