~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/tools/llvm-as/llvm-as.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===--- llvm-as.cpp - The low-level LLVM assembler -----------------------===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
//  This utility may be invoked in the following manner:
 
11
//   llvm-as --help         - Output information about command line switches
 
12
//   llvm-as [options]      - Read LLVM asm from stdin, write bitcode to stdout
 
13
//   llvm-as [options] x.ll - Read LLVM asm from the x.ll file, write bitcode
 
14
//                            to the x.bc file.
 
15
//
 
16
//===----------------------------------------------------------------------===//
 
17
 
 
18
#include "llvm/LLVMContext.h"
 
19
#include "llvm/Module.h"
 
20
#include "llvm/Assembly/Parser.h"
 
21
#include "llvm/Analysis/Verifier.h"
 
22
#include "llvm/Bitcode/ReaderWriter.h"
 
23
#include "llvm/Support/CommandLine.h"
 
24
#include "llvm/Support/ManagedStatic.h"
 
25
#include "llvm/Support/PrettyStackTrace.h"
 
26
#include "llvm/Support/SourceMgr.h"
 
27
#include "llvm/Support/SystemUtils.h"
 
28
#include "llvm/Support/raw_ostream.h"
 
29
#include "llvm/System/Signals.h"
 
30
#include <memory>
 
31
using namespace llvm;
 
32
 
 
33
static cl::opt<std::string>
 
34
InputFilename(cl::Positional, cl::desc("<input .llvm file>"), cl::init("-"));
 
35
 
 
36
static cl::opt<std::string>
 
37
OutputFilename("o", cl::desc("Override output filename"),
 
38
               cl::value_desc("filename"));
 
39
 
 
40
static cl::opt<bool>
 
41
Force("f", cl::desc("Enable binary output on terminals"));
 
42
 
 
43
static cl::opt<bool>
 
44
DisableOutput("disable-output", cl::desc("Disable output"), cl::init(false));
 
45
 
 
46
static cl::opt<bool>
 
47
DumpAsm("d", cl::desc("Print assembly as parsed"), cl::Hidden);
 
48
 
 
49
static cl::opt<bool>
 
50
DisableVerify("disable-verify", cl::Hidden,
 
51
              cl::desc("Do not run verifier on input LLVM (dangerous!)"));
 
52
 
 
53
static void WriteOutputFile(const Module *M) {
 
54
  // Infer the output filename if needed.
 
55
  if (OutputFilename.empty()) {
 
56
    if (InputFilename == "-") {
 
57
      OutputFilename = "-";
 
58
    } else {
 
59
      std::string IFN = InputFilename;
 
60
      int Len = IFN.length();
 
61
      if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
 
62
        // Source ends in .ll
 
63
        OutputFilename = std::string(IFN.begin(), IFN.end()-3);
 
64
      } else {
 
65
        OutputFilename = IFN;   // Append a .bc to it
 
66
      }
 
67
      OutputFilename += ".bc";
 
68
    }
 
69
  }
 
70
 
 
71
  // Make sure that the Out file gets unlinked from the disk if we get a
 
72
  // SIGINT.
 
73
  if (OutputFilename != "-")
 
74
    sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
75
 
 
76
  std::string ErrorInfo;
 
77
  std::auto_ptr<raw_ostream> Out
 
78
  (new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
 
79
                      raw_fd_ostream::F_Binary));
 
80
  if (!ErrorInfo.empty()) {
 
81
    errs() << ErrorInfo << '\n';
 
82
    exit(1);
 
83
  }
 
84
 
 
85
  if (Force || !CheckBitcodeOutputToConsole(*Out, true))
 
86
    WriteBitcodeToFile(M, *Out);
 
87
}
 
88
 
 
89
int main(int argc, char **argv) {
 
90
  // Print a stack trace if we signal out.
 
91
  sys::PrintStackTraceOnErrorSignal();
 
92
  PrettyStackTraceProgram X(argc, argv);
 
93
  LLVMContext &Context = getGlobalContext();
 
94
  llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 
95
  cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
 
96
 
 
97
  // Parse the file now...
 
98
  SMDiagnostic Err;
 
99
  std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context));
 
100
  if (M.get() == 0) {
 
101
    Err.Print(argv[0], errs());
 
102
    return 1;
 
103
  }
 
104
 
 
105
  if (!DisableVerify) {
 
106
    std::string Err;
 
107
    if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
 
108
      errs() << argv[0]
 
109
             << ": assembly parsed, but does not verify as correct!\n";
 
110
      errs() << Err;
 
111
      return 1;
 
112
    }
 
113
  }
 
114
 
 
115
  if (DumpAsm) errs() << "Here's the assembly:\n" << *M.get();
 
116
 
 
117
  if (!DisableOutput)
 
118
    WriteOutputFile(M.get());
 
119
 
 
120
  return 0;
 
121
}