mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-21 03:32:21 +00:00
Use the new getMainFunction() method to efficiently locate main
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4630 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a9a93f3777
commit
93fbd733e7
@ -17,21 +17,16 @@ namespace {
|
|||||||
|
|
||||||
class InternalizePass : public Pass {
|
class InternalizePass : public Pass {
|
||||||
virtual bool run(Module &M) {
|
virtual bool run(Module &M) {
|
||||||
bool FoundMain = false; // Look for a function named main...
|
Function *MainFunc = M.getMainFunction();
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
|
||||||
if (I->getName() == "main" && !I->isExternal() &&
|
if (MainFunc == 0 || MainFunc->isExternal())
|
||||||
I->hasExternalLinkage()) {
|
return false; // No main found, must be a library...
|
||||||
FoundMain = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!FoundMain) return false; // No main found, must be a library...
|
|
||||||
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
|
||||||
// Found a main function, mark all functions not named main as internal.
|
// Found a main function, mark all functions not named main as internal.
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
if (I->getName() != "main" && // Leave the main function external
|
if (&*I != MainFunc && // Leave the main function external
|
||||||
!I->isExternal() && // Function must be defined here
|
!I->isExternal() && // Function must be defined here
|
||||||
!I->hasInternalLinkage()) { // Can't already have internal linkage
|
!I->hasInternalLinkage()) { // Can't already have internal linkage
|
||||||
I->setInternalLinkage(true);
|
I->setInternalLinkage(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user