LLVM  3.7.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 
15 #include "llvm/Object/ObjectFile.h"
18 
19 using namespace llvm;
20 using namespace object;
21 
23  : Binary(Type, Source) {}
24 
26 
29  StringRef Data = Object.getBuffer();
30  if (Type == sys::fs::file_magic::unknown)
31  Type = sys::fs::identify_magic(Data);
32 
33  switch (Type) {
35  if (Context)
36  return IRObjectFile::create(Object, *Context);
37  // Fallthrough
59  return ObjectFile::createObjectFile(Object, Type);
64  ObjectFile::createObjectFile(Object, Type);
65  if (!Obj || !Context)
66  return std::move(Obj);
67 
70  if (!BCData)
71  return std::move(Obj);
72 
73  return IRObjectFile::create(
74  MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
75  *Context);
76  }
77  }
78  llvm_unreachable("Unexpected Binary File Type");
79 }
Represents either an error or a value T.
Definition: ErrorOr.h:82
ELF Relocatable object file.
Definition: FileSystem.h:230
static ErrorOr< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, sys::fs::file_magic Type, LLVMContext *Context)
SymbolicFile(unsigned int Type, MemoryBufferRef Source)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
static ErrorOr< std::unique_ptr< IRObjectFile > > create(MemoryBufferRef Object, LLVMContext &Context)
ELF dynamically linked shared lib.
Definition: FileSystem.h:232
Windows compiled resource file (.rc)
Definition: FileSystem.h:249
ar style archive file
Definition: FileSystem.h:228
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:41
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Path.cpp:900
StringRef getBuffer() const
Definition: MemoryBuffer.h:157
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:224
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:159
static ErrorOr< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.
Definition: ObjectFile.cpp:102
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
reference get()
Definition: ErrorOr.h:175