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

Side by Side Diff: lib/Bitcode/Reader/BitcodeStream.cpp

Issue 8393017: Bitcode streaming (Closed)
Patch Set: Created 9 years, 1 month 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
OLDNEW
(Empty)
1 //===---- llvm/Bitcode/Reader/BitcodeStream.cpp - ----*- 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 // Support for streaming (lazy reading) of bitcode files on disk
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Bitcode/BitcodeStream.h"
15 #include "llvm/Support/SourceMgr.h"
16 #include <string>
17 #include <cerrno>
18 #include <cstdio>
19
20 namespace {
21 class FileStream {
22 FILE *Fd;
23 public:
24 FileStream() : Fd(NULL) {}
25 size_t FileGetBytes(unsigned char *buf, size_t len) {
26 return fread(buf, 1, len, Fd);
27 }
28
29 bool OpenFileStream(const std::string &Filename) {
30 Fd = fopen(Filename.c_str(), "r");
31 return Fd != NULL;
32 }
33 };
34
35 static FileStream *stream;
36 size_t FileStreamCallback(unsigned char *buf, size_t len) {
37 return stream->FileGetBytes(buf, len);
38 }
39 }
40
41 namespace llvm {
42 StreamChunkCallback GetBitcodeFileStream(const std::string &Filename,
43 SMDiagnostic &Err) {
44 stream = new FileStream();
45 if (!stream->OpenFileStream(Filename)) {
46 Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
47 "Could not open input file");
48 return NULL;
49 }
50 return FileStreamCallback;
51 }
52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698