Index: src/llvm2ice.cpp |
diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp |
index 774a8e6a88dd8ebfd443c8ebcf75b6cc91ac5cc9..1c524ebc5085e2cd920b4ac0cf82017e6def145d 100644 |
--- a/src/llvm2ice.cpp |
+++ b/src/llvm2ice.cpp |
@@ -173,6 +173,11 @@ static cl::opt<bool> |
static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), |
cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); |
+static cl::opt<bool> |
+ UseELFWriter("elf-writer", |
+ cl::desc("Use ELF writer with the integrated assembler"), |
+ cl::init(false)); |
+ |
static cl::opt<bool> AlwaysExitSuccess( |
"exit-success", cl::desc("Exit with success status, even if errors found"), |
cl::init(false)); |
@@ -242,18 +247,6 @@ int main(int argc, char **argv) { |
VMask |= VerboseList[i]; |
} |
- std::ofstream Ofs; |
- if (OutputFilename != "-") { |
- Ofs.open(OutputFilename.c_str(), std::ofstream::out); |
- } |
- raw_os_ostream *Os = |
- new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); |
- Os->SetUnbuffered(); |
- |
- ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Os : nullptr); |
- if (GenerateBuildAtts) |
- return GetReturnValue(0); |
- |
std::ofstream Lfs; |
if (LogFilename != "-") { |
Lfs.open(LogFilename.c_str(), std::ofstream::out); |
@@ -261,6 +254,10 @@ int main(int argc, char **argv) { |
raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
Ls->SetUnbuffered(); |
+ ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Ls : nullptr); |
+ if (GenerateBuildAtts) |
+ return GetReturnValue(0); |
+ |
if (!ALLOW_DISABLE_IR_GEN && DisableIRGeneration) { |
*Ls << "Error: Build doesn't allow --no-ir-gen when not " |
<< "ALLOW_DISABLE_IR_GEN!\n"; |
@@ -274,6 +271,7 @@ int main(int argc, char **argv) { |
Flags.FunctionSections = FunctionSections; |
Flags.DataSections = DataSections; |
Flags.UseIntegratedAssembler = UseIntegratedAssembler; |
+ Flags.UseELFWriter = UseELFWriter; |
Flags.UseSandboxing = UseSandboxing; |
Flags.PhiEdgeSplit = EnablePhiEdgeSplit; |
Flags.DecorateAsm = DecorateAsm; |
@@ -294,11 +292,39 @@ int main(int argc, char **argv) { |
LLSuffix.length(), LLSuffix) == 0) |
BuildOnRead = false; |
- Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, |
- Flags); |
+ // With the ELF writer, use a raw_fd_ostream to allow seeking. |
+ // Also don't buffer, otherwise it gets pretty slow. |
+ Ice::Ostream *Os; |
+ Ice::ELFStreamer *ELFStr = nullptr; |
+ std::ofstream Ofs; |
+ if (UseELFWriter) { |
+ std::string ErrorInfo; |
+ raw_fd_ostream *FdOs = |
+ new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo); |
Jim Stichnoth
2014/11/21 21:32:23
Should we disallow OutputFilename=="-" which is it
jvoung (off chromium)
2014/11/24 21:35:47
Done -- streaming to stdout will have problems bec
|
+ if (!ErrorInfo.empty()) { |
+ *Ls << "Failed to open output file: " << OutputFilename << ":\n" |
+ << ErrorInfo << "\n"; |
+ return GetReturnValue(1); |
+ } |
+ ELFStr = new Ice::ELFStreamer(*FdOs); |
+ Os = FdOs; |
+ } else { |
+ if (OutputFilename != "-") { |
+ Ofs.open(OutputFilename.c_str(), std::ofstream::out); |
+ } |
+ Os = new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); |
Jim Stichnoth
2014/11/21 21:32:23
I know this was just copy/paste, but can we struct
jvoung (off chromium)
2014/11/24 21:35:46
Done. Did something similar for the Ls stream.
|
+ Os->SetUnbuffered(); |
+ } |
+ |
+ Ice::GlobalContext Ctx(Ls, Os, ELFStr, VMask, TargetArch, OptLevel, |
+ TestPrefix, Flags); |
Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
+ if (UseELFWriter) { |
+ Ctx.getObjectWriter()->writeInitialELFHeader(); |
+ } |
+ |
int ErrorStatus = 0; |
if (BuildOnRead) { |
Ice::PNaClTranslator Translator(&Ctx, Flags); |
@@ -324,6 +350,9 @@ int main(int argc, char **argv) { |
<< "--build-on-read=0 not allowed\n"; |
return GetReturnValue(1); |
} |
+ if (UseELFWriter) { |
+ Ctx.getObjectWriter()->writeNonUserSections(); |
+ } |
if (SubzeroTimingEnabled) |
Ctx.dumpTimers(); |
if (TimeEachFunction) { |
@@ -332,5 +361,6 @@ int main(int argc, char **argv) { |
} |
const bool FinalStats = true; |
Ctx.dumpStats("_FINAL_", FinalStats); |
+ Os->flush(); |
Jim Stichnoth
2014/11/21 21:32:23
Is it enough to just flush Os? Should it be close
jvoung (off chromium)
2014/11/24 21:35:46
Switch Os and Ls to a unique_ptr, so it gets delet
|
return GetReturnValue(ErrorStatus); |
} |