LLVM  4.0.0
SymbolicFile.cpp
Go to the documentation of this file.
1 //===- SymbolicFile.cpp - Interface that only provides symbols --*- C++ -*-===//
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 file defines a file format independent SymbolicFile class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/Object/COFF.h"
17 #include "llvm/Object/ObjectFile.h"
20 
21 using namespace llvm;
22 using namespace object;
23 
25  : Binary(Type, Source) {}
26 
28 
31  StringRef Data = Object.getBuffer();
32  if (Type == sys::fs::file_magic::unknown)
33  Type = sys::fs::identify_magic(Data);
34 
35  switch (Type) {
37  if (Context)
38  return IRObjectFile::create(Object, *Context);
62  return ObjectFile::createObjectFile(Object, Type);
64  return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
69  ObjectFile::createObjectFile(Object, Type);
70  if (!Obj || !Context)
71  return std::move(Obj);
72 
75  if (!BCData)
76  return std::move(Obj);
77 
78  return IRObjectFile::create(
79  MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
80  *Context);
81  }
82  }
83  llvm_unreachable("Unexpected Binary File Type");
84 }
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.
Definition: ObjectFile.cpp:116
Represents either an error or a value T.
Definition: ErrorOr.h:68
LLVMContext & Context
WebAssembly Object file.
Definition: FileSystem.h:267
ELF Relocatable object file.
Definition: FileSystem.h:246
SymbolicFile(unsigned int Type, MemoryBufferRef Source)
Tagged union holding either a T or a Error.
ELF dynamically linked shared lib.
Definition: FileSystem.h:248
Windows compiled resource file (.rc)
Definition: FileSystem.h:266
static Expected< std::unique_ptr< IRObjectFile > > create(MemoryBufferRef Object, LLVMContext &Context)
ar style archive file
Definition: FileSystem.h:244
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
Microsoft cl.exe's intermediate code file.
Definition: FileSystem.h:262
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Path.cpp:999
StringRef getBuffer() const
Definition: MemoryBuffer.h:169
reference get()
Returns a reference to the stored T value.
MemoryBufferRef Data
Definition: Binary.h:37
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
Definition: FileSystem.h:240
static ErrorOr< MemoryBufferRef > findBitcodeInObject(const ObjectFile &Obj)
Finds and returns bitcode embedded in the given object file, or an error code if not found...
StringRef getBufferIdentifier() const
Definition: MemoryBuffer.h:171
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:239
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, sys::fs::file_magic Type, LLVMContext *Context)