REPL: Don't call global_ctors before each entry.

The REPL was accreting global_ctors and rerunning all global initializers ever registered before every entry. Change it so that it only runs global initializers once and so that the ObjC initialization stuff that needs to happen on a per-entry basis just gets dropped directly into the main() for each entry.

Swift SVN r4154
This commit is contained in:
Joe Groff
2013-02-22 22:24:29 +00:00
parent 827cbfe0b0
commit 38a8b1f7e3
2 changed files with 43 additions and 38 deletions

View File

@@ -761,6 +761,7 @@ class REPLEnvironment {
TranslationUnit *TU;
llvm::SmallPtrSet<TranslationUnit*, 8> ImportedModules;
SmallVector<llvm::Function*, 8> InitFns;
bool RanGlobalInitializers;
llvm::LLVMContext LLVMContext;
llvm::Module Module;
llvm::Module DumpModule;
@@ -786,8 +787,8 @@ class REPLEnvironment {
// Parse the current line(s).
unsigned BufferOffset = 0;
bool ShouldRun =
swift::appendToMainTranslationUnit(TU, BufferID, CurTUElem,
BufferOffset, Line.size());
swift::appendToMainTranslationUnit(TU, BufferID, CurTUElem,
BufferOffset, Line.size());
if (Context.hadError()) {
Context.Diags.resetHadAnyError();
@@ -847,7 +848,10 @@ class REPLEnvironment {
// FIXME: The way we do this is really ugly... we should be able to
// improve this.
EE->runStaticConstructorsDestructors(&Module, false);
if (!RanGlobalInitializers) {
EE->runStaticConstructorsDestructors(&Module, false);
RanGlobalInitializers = true;
}
llvm::Function *EntryFn = Module.getFunction("main");
EE->runFunctionAsMain(EntryFn, std::vector<std::string>(), 0);
EE->freeMachineCodeForFunction(EntryFn);
@@ -866,6 +870,7 @@ public:
Comp, Context,
/*IsMainModule=*/true,
/*IsReplModule=*/true)),
RanGlobalInitializers(false),
Module("REPL", LLVMContext),
DumpModule("REPL", LLVMContext),
CurTUElem(0),