Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | //===- SymbolStripping.cpp - Code to string symbols for methods and modules -=// |
| 2 | // |
| 3 | // This file implements stripping symbols out of symbol tables. |
| 4 | // |
| 5 | // Specifically, this allows you to strip all of the symbols out of: |
| 6 | // * A method |
| 7 | // * All methods in a module |
| 8 | // * All symbols in a module (all method symbols + all module scope symbols) |
| 9 | // |
| 10 | // Notice that: |
| 11 | // * This pass makes code much less readable, so it should only be used in |
| 12 | // situations where the 'strip' utility would be used (such as reducing |
| 13 | // code size, and making it harder to reverse engineer code). |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Chris Lattner | 7e02b7e | 2001-06-30 04:36:40 +0000 | [diff] [blame] | 17 | #include "llvm/Optimizations/AllOpts.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/Method.h" |
| 20 | #include "llvm/SymbolTable.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 21 | |
| 22 | static bool StripSymbolTable(SymbolTable *SymTab) { |
| 23 | if (SymTab == 0) return false; // No symbol table? No problem. |
| 24 | bool RemovedSymbol = false; |
| 25 | |
Chris Lattner | 7fc9fe3 | 2001-06-27 23:41:11 +0000 | [diff] [blame] | 26 | for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); ++I) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 27 | map<const string, Value *> &Plane = I->second; |
| 28 | |
| 29 | map<const string, Value *>::iterator B; |
| 30 | while ((B = Plane.begin()) != Plane.end()) { // Found nonempty type plane! |
| 31 | B->second->setName(""); // Set name to "", removing from symbol table! |
| 32 | RemovedSymbol = true; |
| 33 | assert(Plane.begin() != B); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return RemovedSymbol; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | // DoSymbolStripping - Remove all symbolic information from a method |
| 42 | // |
Chris Lattner | 7e02b7e | 2001-06-30 04:36:40 +0000 | [diff] [blame] | 43 | bool opt::DoSymbolStripping(Method *M) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 44 | return StripSymbolTable(M->getSymbolTable()); |
| 45 | } |
| 46 | |
| 47 | // DoFullSymbolStripping - Remove all symbolic information from all methods |
| 48 | // in a module, and all module level symbols. (method names, etc...) |
| 49 | // |
Chris Lattner | 7e02b7e | 2001-06-30 04:36:40 +0000 | [diff] [blame] | 50 | bool opt::DoFullSymbolStripping(Module *M) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 51 | // Remove all symbols from methods in this module... and then strip all of the |
| 52 | // symbols in this module... |
| 53 | // |
| 54 | return DoSymbolStripping(M) | StripSymbolTable(M->getSymbolTable()); |
| 55 | } |