blob: 9a61a9b009fc5cd29c0cf12e7c283258ae4292c0 [file] [log] [blame]
Chris Lattneraa739d22009-03-13 07:05:43 +00001//===- TGSourceMgr.h - Manager for Source Buffers & Diagnostics -*- 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 declares the TGSourceMgr class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef TGSOURCEMGR_H
15#define TGSOURCEMGR_H
16
17#include <vector>
18
19namespace llvm {
20 class MemoryBuffer;
21
22/// FIXME: Make this a struct that is opaque.
23typedef const char *TGLocTy;
24
25/// TGSourceMgr - This owns the files read by tblgen, handles include stacks,
26/// and handles printing of diagnostics.
27class TGSourceMgr {
28 struct SrcBuffer {
29 /// Buffer - The memory buffer for the file.
30 MemoryBuffer *Buffer;
31
32 /// IncludeLoc - This is the location of the parent include, or null if at
33 /// the top level.
34 TGLocTy IncludeLoc;
35 };
36
37 /// Buffers - This is all of the buffers that we are reading from.
38 std::vector<SrcBuffer> Buffers;
39
40 TGSourceMgr(const TGSourceMgr&); // DO NOT IMPLEMENT
41 void operator=(const TGSourceMgr&); // DO NOT IMPLEMENT
42public:
43 TGSourceMgr() {}
44 ~TGSourceMgr();
45
46 const SrcBuffer &getBufferInfo(unsigned i) const {
47 assert(i < Buffers.size() && "Invalid Buffer ID!");
48 return Buffers[i];
49 }
50
51 const MemoryBuffer *getMemoryBuffer(unsigned i) const {
52 assert(i < Buffers.size() && "Invalid Buffer ID!");
53 return Buffers[i].Buffer;
54 }
55
56 TGLocTy getParentIncludeLoc(unsigned i) const {
57 assert(i < Buffers.size() && "Invalid Buffer ID!");
58 return Buffers[i].IncludeLoc;
59 }
60
61 unsigned AddNewSourceBuffer(MemoryBuffer *F, TGLocTy IncludeLoc) {
62 SrcBuffer NB;
63 NB.Buffer = F;
64 NB.IncludeLoc = IncludeLoc;
65 Buffers.push_back(NB);
66 return Buffers.size()-1;
67 }
68
69 /// FindBufferContainingLoc - Return the ID of the buffer containing the
70 /// specified location, returning -1 if not found.
71 int FindBufferContainingLoc(TGLocTy Loc) const;
72
73 /// FindLineNumber - Find the line number for the specified location in the
74 /// specified file. This is not a fast method.
75 unsigned FindLineNumber(TGLocTy Loc, int BufferID = -1) const;
76
77
78 /// PrintError - Emit an error message about the specified location with the
79 /// specified string.
80 void PrintError(TGLocTy ErrorLoc, const std::string &Msg) const;
81
82private:
83 void PrintIncludeStack(TGLocTy IncludeLoc) const;
84};
85
86} // end llvm namespace
87
88#endif