Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: src/llvm2ice.cpp

Issue 897873004: Changes to rebase Subzero to LLVM 223109 APIs. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===//
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 that uses LLVM capabilities to parse a 10 // This file defines a driver that uses LLVM capabilities to parse a
11 // bitcode file and build the LLVM IR, and then convert the LLVM basic 11 // bitcode file and build the LLVM IR, and then convert the LLVM basic
12 // blocks, instructions, and operands into their Subzero equivalents. 12 // blocks, instructions, and operands into their Subzero equivalents.
13 // 13 //
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 15
16 #include <fstream> 16 #include <fstream>
17 #include <iostream> 17 #include <iostream>
18 18
19 #include "llvm/ADT/STLExtras.h" 19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/IR/LLVMContext.h" 20 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/IR/Module.h"
21 #include "llvm/IRReader/IRReader.h" 22 #include "llvm/IRReader/IRReader.h"
22 #include "llvm/Support/CommandLine.h" 23 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/FileSystem.h" 24 #include "llvm/Support/FileSystem.h"
24 #include "llvm/Support/raw_os_ostream.h" 25 #include "llvm/Support/raw_os_ostream.h"
25 #include "llvm/Support/SourceMgr.h" 26 #include "llvm/Support/SourceMgr.h"
26 27
27 #include "IceCfg.h" 28 #include "IceCfg.h"
28 #include "IceClFlags.h" 29 #include "IceClFlags.h"
29 #include "IceConverter.h" 30 #include "IceConverter.h"
30 #include "IceELFObjectWriter.h" 31 #include "IceELFObjectWriter.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // With the ELF writer, use a raw_fd_ostream to allow seeking. 325 // With the ELF writer, use a raw_fd_ostream to allow seeking.
325 // Also don't buffer, otherwise it gets pretty slow. 326 // Also don't buffer, otherwise it gets pretty slow.
326 std::unique_ptr<Ice::Ostream> Os; 327 std::unique_ptr<Ice::Ostream> Os;
327 std::unique_ptr<Ice::ELFStreamer> ELFStr; 328 std::unique_ptr<Ice::ELFStreamer> ELFStr;
328 std::ofstream Ofs; 329 std::ofstream Ofs;
329 if (UseELFWriter) { 330 if (UseELFWriter) {
330 if (OutputFilename == "-") { 331 if (OutputFilename == "-") {
331 *Ls << "Error: writing binary ELF to stdout is unsupported\n"; 332 *Ls << "Error: writing binary ELF to stdout is unsupported\n";
332 return GetReturnValue(Ice::EC_Args); 333 return GetReturnValue(Ice::EC_Args);
333 } 334 }
334 std::string ErrorInfo; 335 std::error_code EC;
335 raw_fd_ostream *FdOs = 336 raw_fd_ostream *FdOs =
336 new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None); 337 new raw_fd_ostream(OutputFilename, EC, sys::fs::F_None);
337 Os.reset(FdOs); 338 Os.reset(FdOs);
338 if (!ErrorInfo.empty()) { 339 if (EC) {
339 *Ls << "Failed to open output file: " << OutputFilename << ":\n" 340 *Ls << "Failed to open output file: " << OutputFilename << ":\n"
340 << ErrorInfo << "\n"; 341 << EC.message() << "\n";
341 return GetReturnValue(Ice::EC_Args); 342 return GetReturnValue(Ice::EC_Args);
342 } 343 }
343 ELFStr.reset(new Ice::ELFStreamer(*FdOs)); 344 ELFStr.reset(new Ice::ELFStreamer(*FdOs));
344 } else { 345 } else {
345 if (OutputFilename != "-") { 346 if (OutputFilename != "-") {
346 Ofs.open(OutputFilename.c_str(), std::ofstream::out); 347 Ofs.open(OutputFilename.c_str(), std::ofstream::out);
347 Os.reset(new raw_os_ostream(Ofs)); 348 Os.reset(new raw_os_ostream(Ofs));
348 } else { 349 } else {
349 Os.reset(new raw_os_ostream(std::cout)); 350 Os.reset(new raw_os_ostream(std::cout));
350 } 351 }
(...skipping 16 matching lines...) Expand all
367 if (BuildOnRead) { 368 if (BuildOnRead) {
368 std::unique_ptr<Ice::PNaClTranslator> PTranslator( 369 std::unique_ptr<Ice::PNaClTranslator> PTranslator(
369 new Ice::PNaClTranslator(&Ctx, Flags)); 370 new Ice::PNaClTranslator(&Ctx, Flags));
370 PTranslator->translate(IRFilename); 371 PTranslator->translate(IRFilename);
371 Translator.reset(PTranslator.release()); 372 Translator.reset(PTranslator.release());
372 } else if (ALLOW_LLVM_IR) { 373 } else if (ALLOW_LLVM_IR) {
373 // Parse the input LLVM IR file into a module. 374 // Parse the input LLVM IR file into a module.
374 SMDiagnostic Err; 375 SMDiagnostic Err;
375 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); 376 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx);
376 raw_ostream *Verbose = LLVMVerboseErrors ? &errs() : nullptr; 377 raw_ostream *Verbose = LLVMVerboseErrors ? &errs() : nullptr;
377 Module *Mod = NaClParseIRFile(IRFilename, InputFileFormat, Err, Verbose, 378 std::unique_ptr<Module> Mod =
378 getGlobalContext()); 379 NaClParseIRFile(IRFilename, InputFileFormat, Err, Verbose,
379 380 getGlobalContext());
380 if (!Mod) { 381 if (!Mod) {
381 Err.print(argv[0], errs()); 382 Err.print(argv[0], errs());
382 return GetReturnValue(Ice::EC_Bitcode); 383 return GetReturnValue(Ice::EC_Bitcode);
383 } 384 }
384 385
385 std::unique_ptr<Ice::Converter> Converter( 386 std::unique_ptr<Ice::Converter> Converter(
386 new Ice::Converter(Mod, &Ctx, Flags)); 387 new Ice::Converter(Mod.get(), &Ctx, Flags));
387 Converter->convertToIce(); 388 Converter->convertToIce();
388 Translator.reset(Converter.release()); 389 Translator.reset(Converter.release());
389 } else { 390 } else {
390 *Ls << "Error: Build doesn't allow LLVM IR, " 391 *Ls << "Error: Build doesn't allow LLVM IR, "
391 << "--build-on-read=0 not allowed\n"; 392 << "--build-on-read=0 not allowed\n";
392 return GetReturnValue(Ice::EC_Args); 393 return GetReturnValue(Ice::EC_Args);
393 } 394 }
394 395
395 Ctx.waitForWorkerThreads(); 396 Ctx.waitForWorkerThreads();
396 Translator->transferErrorCode(); 397 Translator->transferErrorCode();
397 Translator->emitConstants(); 398 Translator->emitConstants();
398 399
399 if (UseELFWriter) { 400 if (UseELFWriter) {
400 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); 401 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx);
401 Ctx.getObjectWriter()->setUndefinedSyms(Ctx.getConstantExternSyms()); 402 Ctx.getObjectWriter()->setUndefinedSyms(Ctx.getConstantExternSyms());
402 Ctx.getObjectWriter()->writeNonUserSections(); 403 Ctx.getObjectWriter()->writeNonUserSections();
403 } 404 }
404 if (SubzeroTimingEnabled) 405 if (SubzeroTimingEnabled)
405 Ctx.dumpTimers(); 406 Ctx.dumpTimers();
406 if (TimeEachFunction) { 407 if (TimeEachFunction) {
407 const bool DumpCumulative = false; 408 const bool DumpCumulative = false;
408 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); 409 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative);
409 } 410 }
410 const bool FinalStats = true; 411 const bool FinalStats = true;
411 Ctx.dumpStats("_FINAL_", FinalStats); 412 Ctx.dumpStats("_FINAL_", FinalStats);
412 return GetReturnValue(Ctx.getErrorStatus()->value()); 413 return GetReturnValue(Ctx.getErrorStatus()->value());
413 } 414 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698