llvm.org GIT mirror llvm / ca88cee
Add -alias and -ralias options to match what we have for functions and globals. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166909 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
2 changed file(s) with 56 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: llvm-extract -func foo -S < %s | FileCheck %s
11 ; RUN: llvm-extract -delete -func foo -S < %s | FileCheck --check-prefix=DELETE %s
2 ; RUN: llvm-extract -alias zeda0 -S < %s | FileCheck --check-prefix=ALIAS %s
3 ; RUN: llvm-extract -ralias .*bar -S < %s | FileCheck --check-prefix=ALIASRE %s
24
35 ; Both aliases should be converted to declarations
46 ; CHECK: @zeda0 = external global i32
1921 ; DELETE-NEXT: ret void
2022 ; DELETE-NEXT: }
2123
24 ; ALIAS: @zed = external global i32
25 ; ALIAS: @zeda0 = alias i32* @zed
26
27 ; ALIASRE: @a0a0bar = alias void ()* @a0bar
28 ; ALIASRE: @a0bar = alias void ()* @bar
29 ; ALIASRE: declare void @bar()
30
2231 @zed = global i32 0
2332 @zeda0 = alias i32* @zed
2433
5858 "regular expression"),
5959 cl::ZeroOrMore, cl::value_desc("rfunction"));
6060
61 // ExtractAlias - The alias to extract from the module.
62 static cl::list
63 ExtractAliases("alias", cl::desc("Specify alias to extract"),
64 cl::ZeroOrMore, cl::value_desc("alias"));
65
66
67 // ExtractRegExpAliases - The aliases, matched via regular expression, to
68 // extract from the module.
69 static cl::list
70 ExtractRegExpAliases("ralias", cl::desc("Specify alias(es) to extract using a "
71 "regular expression"),
72 cl::ZeroOrMore, cl::value_desc("ralias"));
73
6174 // ExtractGlobals - The globals to extract from the module.
6275 static cl::list
6376 ExtractGlobals("glob", cl::desc("Specify global to extract"),
95108
96109 // Use SetVector to avoid duplicates.
97110 SetVector GVs;
111
112 // Figure out which aliases we should extract.
113 for (size_t i = 0, e = ExtractAliases.size(); i != e; ++i) {
114 GlobalAlias *GA = M->getNamedAlias(ExtractAliases[i]);
115 if (!GA) {
116 errs() << argv[0] << ": program doesn't contain alias named '"
117 << ExtractAliases[i] << "'!\n";
118 return 1;
119 }
120 GVs.insert(GA);
121 }
122
123 // Extract aliases via regular expression matching.
124 for (size_t i = 0, e = ExtractRegExpAliases.size(); i != e; ++i) {
125 std::string Error;
126 Regex RegEx(ExtractRegExpAliases[i]);
127 if (!RegEx.isValid(Error)) {
128 errs() << argv[0] << ": '" << ExtractRegExpAliases[i] << "' "
129 "invalid regex: " << Error;
130 }
131 bool match = false;
132 for (Module::alias_iterator GA = M->alias_begin(), E = M->alias_end();
133 GA != E; GA++) {
134 if (RegEx.match(GA->getName())) {
135 GVs.insert(&*GA);
136 match = true;
137 }
138 }
139 if (!match) {
140 errs() << argv[0] << ": program doesn't contain global named '"
141 << ExtractRegExpAliases[i] << "'!\n";
142 return 1;
143 }
144 }
98145
99146 // Figure out which globals we should extract.
100147 for (size_t i = 0, e = ExtractGlobals.size(); i != e; ++i) {