mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-04 05:17:07 +00:00 
			
		
		
		
	The patch is generated using clang-tidy misc-use-override check.
This command was used:
  tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \
    -checks='-*,misc-use-override' -header-filter='llvm|clang' \
    -j=32 -fix -format
http://reviews.llvm.org/D8925
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234679 91177308-0d34-0410-b5e6-96231b3b80d8
		
	
		
			
				
	
	
		
			89 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
//===--- llvm/Support/DataStream.cpp - Lazy streamed data -----------------===//
 | 
						|
//
 | 
						|
//                     The LLVM Compiler Infrastructure
 | 
						|
//
 | 
						|
// This file is distributed under the University of Illinois Open Source
 | 
						|
// License. See LICENSE.TXT for details.
 | 
						|
//
 | 
						|
//===----------------------------------------------------------------------===//
 | 
						|
//
 | 
						|
// This file implements DataStreamer, which fetches bytes of Data from
 | 
						|
// a stream source. It provides support for streaming (lazy reading) of
 | 
						|
// bitcode. An example implementation of streaming from a file or stdin
 | 
						|
// is included.
 | 
						|
//
 | 
						|
//===----------------------------------------------------------------------===//
 | 
						|
 | 
						|
#include "llvm/Support/DataStream.h"
 | 
						|
#include "llvm/ADT/Statistic.h"
 | 
						|
#include "llvm/Support/FileSystem.h"
 | 
						|
#include "llvm/Support/Program.h"
 | 
						|
#include <string>
 | 
						|
#include <system_error>
 | 
						|
#if !defined(_MSC_VER) && !defined(__MINGW32__)
 | 
						|
#include <unistd.h>
 | 
						|
#else
 | 
						|
#include <io.h>
 | 
						|
#endif
 | 
						|
using namespace llvm;
 | 
						|
 | 
						|
#define DEBUG_TYPE "Data-stream"
 | 
						|
 | 
						|
// Interface goals:
 | 
						|
// * StreamingMemoryObject doesn't care about complexities like using
 | 
						|
//   threads/async callbacks to actually overlap download+compile
 | 
						|
// * Don't want to duplicate Data in memory
 | 
						|
// * Don't need to know total Data len in advance
 | 
						|
// Non-goals:
 | 
						|
// StreamingMemoryObject already has random access so this interface only does
 | 
						|
// in-order streaming (no arbitrary seeking, else we'd have to buffer all the
 | 
						|
// Data here in addition to MemoryObject).  This also means that if we want
 | 
						|
// to be able to to free Data, BitstreamBytes/BitcodeReader will implement it
 | 
						|
 | 
						|
STATISTIC(NumStreamFetches, "Number of calls to Data stream fetch");
 | 
						|
 | 
						|
namespace llvm {
 | 
						|
DataStreamer::~DataStreamer() {}
 | 
						|
}
 | 
						|
 | 
						|
namespace {
 | 
						|
 | 
						|
// Very simple stream backed by a file. Mostly useful for stdin and debugging;
 | 
						|
// actual file access is probably still best done with mmap.
 | 
						|
class DataFileStreamer : public DataStreamer {
 | 
						|
 int Fd;
 | 
						|
public:
 | 
						|
  DataFileStreamer() : Fd(0) {}
 | 
						|
  ~DataFileStreamer() override { close(Fd); }
 | 
						|
  size_t GetBytes(unsigned char *buf, size_t len) override {
 | 
						|
    NumStreamFetches++;
 | 
						|
    return read(Fd, buf, len);
 | 
						|
  }
 | 
						|
 | 
						|
  std::error_code OpenFile(const std::string &Filename) {
 | 
						|
    if (Filename == "-") {
 | 
						|
      Fd = 0;
 | 
						|
      sys::ChangeStdinToBinary();
 | 
						|
      return std::error_code();
 | 
						|
    }
 | 
						|
 | 
						|
    return sys::fs::openFileForRead(Filename, Fd);
 | 
						|
  }
 | 
						|
};
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
namespace llvm {
 | 
						|
DataStreamer *getDataFileStreamer(const std::string &Filename,
 | 
						|
                                  std::string *StrError) {
 | 
						|
  DataFileStreamer *s = new DataFileStreamer();
 | 
						|
  if (std::error_code e = s->OpenFile(Filename)) {
 | 
						|
    *StrError = std::string("Could not open ") + Filename + ": " +
 | 
						|
        e.message() + "\n";
 | 
						|
    return nullptr;
 | 
						|
  }
 | 
						|
  return s;
 | 
						|
}
 | 
						|
 | 
						|
}
 |