etc/services - sync with NetBSD-8
[minix.git] / minix / llvm / passes / WeakAliasModuleOverride / WeakAliasModuleOverride.cpp
blob0d3a15120b3bf993958df8610eec394447c851e8
2 #include "llvm/IR/GlobalVariable.h"
3 #include "llvm/IR/Module.h"
4 #include "llvm/Pass.h"
6 #include "llvm/Support/raw_ostream.h"
7 #include "llvm/Support/Regex.h"
9 using namespace llvm;
11 //#define passLog(M) (errs() << "WeakAliasModuleOverride: " << M << "\n")
12 #define passLog(M) /* nothing */
14 namespace {
15 class WeakAliasModuleOverride : public ModulePass {
17 public:
18 static char ID;
19 WeakAliasModuleOverride() : ModulePass(ID) {
22 virtual bool runOnModule(Module &M) {
23 const Module::FunctionListType &listFcts = M.getFunctionList();
24 const Module::GlobalListType &listGlobalVars = M.getGlobalList();
26 std::string Asm = M.getModuleInlineAsm();
28 passLog("ASM START\n"
29 << Asm
30 << "ASM END\n");
32 // Filter out Function symbols
33 for(Module::const_iterator it = listFcts.begin(), end=listFcts.end(); it!= end; ++it)
35 if (it->isDeclaration())
36 continue;
38 // Filter out the assembly weak symbol as well as its default value
39 std::string symbolName = it->getName();
40 std::string matchWeak = "(^.weak.* " + symbolName + "\n)";
41 std::string matchAssignement = "(^" + symbolName + " .*=.*\n)";
43 Regex filterWeak(matchWeak, Regex::Newline);
44 Regex filterAssignement(matchAssignement, Regex::Newline);
46 while(filterWeak.match(Asm))
47 Asm = filterWeak.sub("", Asm);
49 while(filterAssignement.match(Asm))
50 Asm = filterAssignement.sub("", Asm);
53 // Filter out GlobalVariable symbols
54 for(Module::const_global_iterator it = listGlobalVars.begin(), end=listGlobalVars.end(); it!= end; ++it)
56 if (! it->hasInitializer())
57 continue;
59 // Filter out the assembly weak symbol as well as its default value
60 std::string symbolName = it->getName();
61 std::string matchWeak = "(^.weak.* " + symbolName + "\n)";
62 std::string matchAssignement = "(^" + symbolName + " .*=.*\n)";
64 Regex filterWeak(matchWeak, Regex::Newline);
65 Regex filterAssignement(matchAssignement, Regex::Newline);
67 while(filterWeak.match(Asm))
68 Asm = filterWeak.sub("", Asm);
70 while(filterAssignement.match(Asm))
71 Asm = filterAssignement.sub("", Asm);
74 M.setModuleInlineAsm(Asm);
76 passLog("ASM START - registered\n"
77 << M.getModuleInlineAsm()
78 << "ASM END\n");
80 return true;
85 char WeakAliasModuleOverride::ID = 0;
86 RegisterPass<WeakAliasModuleOverride> WEAK_ALIAS_MODULE_OVERRIDE("weak-alias-module-override", "Fix Weak Alias overrides");