OLD | NEW |
1 //===- subzero/src/main.cpp - Driver for bitcode translation --------------===// | 1 //===- subzero/src/main.cpp - Driver for bitcode translation --------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file defines a driver for translating PNaCl bitcode into native code. | 10 // This file defines a driver for translating PNaCl bitcode into native code. |
11 // It can either directly parse the binary bitcode file, or use LLVM routines to | 11 // It can either directly parse the binary bitcode file, or use LLVM routines to |
12 // parse a textual bitcode file into LLVM IR and then convert LLVM IR into ICE. | 12 // parse a textual bitcode file into LLVM IR and then convert LLVM IR into ICE. |
13 // In either case, the high-level ICE is then compiled down to native code, as | 13 // In either case, the high-level ICE is then compiled down to native code, as |
14 // either an ELF object file or a textual asm file. | 14 // either an ELF object file or a textual asm file. |
15 // | 15 // |
16 //===----------------------------------------------------------------------===// | 16 //===----------------------------------------------------------------------===// |
17 | 17 |
18 #include <fstream> | 18 #include <fstream> |
19 #include <iostream> | 19 #include <iostream> |
20 | 20 |
21 #include "llvm/ADT/STLExtras.h" | 21 #include "llvm/ADT/STLExtras.h" |
22 #include "llvm/IR/LLVMContext.h" | 22 #include "llvm/IR/LLVMContext.h" |
23 #include "llvm/IR/Module.h" | 23 #include "llvm/IR/Module.h" |
24 #include "llvm/IRReader/IRReader.h" | 24 #include "llvm/IRReader/IRReader.h" |
25 #include "llvm/Support/CommandLine.h" | 25 #include "llvm/Support/CommandLine.h" |
26 #include "llvm/Support/FileSystem.h" | 26 #include "llvm/Support/FileSystem.h" |
27 #include "llvm/Support/raw_os_ostream.h" | 27 #include "llvm/Support/raw_os_ostream.h" |
28 #include "llvm/Support/SourceMgr.h" | 28 #include "llvm/Support/SourceMgr.h" |
| 29 #include "llvm/Support/StreamingMemoryObject.h" |
29 | 30 |
30 #include "IceCfg.h" | 31 #include "IceCfg.h" |
31 #include "IceClFlags.h" | 32 #include "IceClFlags.h" |
32 #include "IceConverter.h" | 33 #include "IceConverter.h" |
33 #include "IceELFObjectWriter.h" | 34 #include "IceELFObjectWriter.h" |
34 #include "IceELFStreamer.h" | 35 #include "IceELFStreamer.h" |
35 #include "PNaClTranslator.h" | 36 #include "PNaClTranslator.h" |
36 | 37 |
37 using namespace llvm; | 38 using namespace llvm; |
38 | 39 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); | 373 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); |
373 Ctx.getObjectWriter()->writeInitialELFHeader(); | 374 Ctx.getObjectWriter()->writeInitialELFHeader(); |
374 } | 375 } |
375 | 376 |
376 Ctx.startWorkerThreads(); | 377 Ctx.startWorkerThreads(); |
377 | 378 |
378 std::unique_ptr<Ice::Translator> Translator; | 379 std::unique_ptr<Ice::Translator> Translator; |
379 if (BuildOnRead) { | 380 if (BuildOnRead) { |
380 std::unique_ptr<Ice::PNaClTranslator> PTranslator( | 381 std::unique_ptr<Ice::PNaClTranslator> PTranslator( |
381 new Ice::PNaClTranslator(&Ctx)); | 382 new Ice::PNaClTranslator(&Ctx)); |
382 PTranslator->translate(IRFilename); | 383 std::string StrError; |
| 384 std::unique_ptr<DataStreamer> FileStreamer( |
| 385 getDataFileStreamer(IRFilename, &StrError)); |
| 386 if (!StrError.empty() || !FileStreamer) { |
| 387 SMDiagnostic Err(IRFilename, SourceMgr::DK_Error, StrError); |
| 388 Err.print(argv[0], errs()); |
| 389 return GetReturnValue(Ice::EC_Bitcode); |
| 390 } |
| 391 std::unique_ptr<StreamingMemoryObject> MemObj( |
| 392 new StreamingMemoryObjectImpl(FileStreamer.release())); |
| 393 PTranslator->translate(IRFilename, std::move(MemObj)); |
383 Translator.reset(PTranslator.release()); | 394 Translator.reset(PTranslator.release()); |
384 } else if (ALLOW_LLVM_IR) { | 395 } else if (ALLOW_LLVM_IR) { |
385 // Parse the input LLVM IR file into a module. | 396 // Parse the input LLVM IR file into a module. |
386 SMDiagnostic Err; | 397 SMDiagnostic Err; |
387 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); | 398 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); |
388 raw_ostream *Verbose = LLVMVerboseErrors ? &errs() : nullptr; | 399 raw_ostream *Verbose = LLVMVerboseErrors ? &errs() : nullptr; |
389 std::unique_ptr<Module> Mod = NaClParseIRFile( | 400 std::unique_ptr<Module> Mod = NaClParseIRFile( |
390 IRFilename, InputFileFormat, Err, Verbose, getGlobalContext()); | 401 IRFilename, InputFileFormat, Err, Verbose, getGlobalContext()); |
391 if (!Mod) { | 402 if (!Mod) { |
392 Err.print(argv[0], errs()); | 403 Err.print(argv[0], errs()); |
(...skipping 22 matching lines...) Expand all Loading... |
415 if (SubzeroTimingEnabled) | 426 if (SubzeroTimingEnabled) |
416 Ctx.dumpTimers(); | 427 Ctx.dumpTimers(); |
417 if (TimeEachFunction) { | 428 if (TimeEachFunction) { |
418 const bool DumpCumulative = false; | 429 const bool DumpCumulative = false; |
419 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); | 430 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); |
420 } | 431 } |
421 const bool FinalStats = true; | 432 const bool FinalStats = true; |
422 Ctx.dumpStats("_FINAL_", FinalStats); | 433 Ctx.dumpStats("_FINAL_", FinalStats); |
423 return GetReturnValue(Ctx.getErrorStatus()->value()); | 434 return GetReturnValue(Ctx.getErrorStatus()->value()); |
424 } | 435 } |
OLD | NEW |