LLVM  13.0.0git
LineIterator.h
Go to the documentation of this file.
1 //===- LineIterator.h - Iterator to read a text buffer's lines --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_SUPPORT_LINEITERATOR_H
10 #define LLVM_SUPPORT_LINEITERATOR_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/DataTypes.h"
16 #include <iterator>
17 
18 namespace llvm {
19 
20 class MemoryBuffer;
21 
22 /// A forward iterator which reads text lines from a buffer.
23 ///
24 /// This class provides a forward iterator interface for reading one line at
25 /// a time from a buffer. When default constructed the iterator will be the
26 /// "end" iterator.
27 ///
28 /// The iterator is aware of what line number it is currently processing. It
29 /// strips blank lines by default, and comment lines given a comment-starting
30 /// character.
31 ///
32 /// Note that this iterator requires the buffer to be nul terminated.
34  : public std::iterator<std::forward_iterator_tag, StringRef> {
36  char CommentMarker = '\0';
37  bool SkipBlanks = true;
38 
39  unsigned LineNumber = 1;
40  StringRef CurrentLine;
41 
42 public:
43  /// Default construct an "end" iterator.
44  line_iterator() = default;
45 
46  /// Construct a new iterator around an unowned memory buffer.
47  explicit line_iterator(const MemoryBufferRef &Buffer, bool SkipBlanks = true,
48  char CommentMarker = '\0');
49 
50  /// Construct a new iterator around some memory buffer.
51  explicit line_iterator(const MemoryBuffer &Buffer, bool SkipBlanks = true,
52  char CommentMarker = '\0');
53 
54  /// Return true if we've reached EOF or are an "end" iterator.
55  bool is_at_eof() const { return !Buffer; }
56 
57  /// Return true if we're an "end" iterator or have reached EOF.
58  bool is_at_end() const { return is_at_eof(); }
59 
60  /// Return the current line number. May return any number at EOF.
61  int64_t line_number() const { return LineNumber; }
62 
63  /// Advance to the next (non-empty, non-comment) line.
65  advance();
66  return *this;
67  }
69  line_iterator tmp(*this);
70  advance();
71  return tmp;
72  }
73 
74  /// Get the current line as a \c StringRef.
75  StringRef operator*() const { return CurrentLine; }
76  const StringRef *operator->() const { return &CurrentLine; }
77 
78  friend bool operator==(const line_iterator &LHS, const line_iterator &RHS) {
79  return LHS.Buffer == RHS.Buffer &&
80  LHS.CurrentLine.begin() == RHS.CurrentLine.begin();
81  }
82 
83  friend bool operator!=(const line_iterator &LHS, const line_iterator &RHS) {
84  return !(LHS == RHS);
85  }
86 
87 private:
88  /// Advance the iterator to the next line.
89  void advance();
90 };
91 }
92 
93 #endif
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Optional.h
llvm::line_iterator
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:33
StringRef.h
llvm::line_iterator::operator*
StringRef operator*() const
Get the current line as a StringRef.
Definition: LineIterator.h:75
MemoryBufferRef.h
llvm::Optional
Definition: APInt.h:33
tmp
alloca< 16 x float >, align 16 %tmp2=alloca< 16 x float >, align 16 store< 16 x float > %A,< 16 x float > *%tmp %s=bitcast< 16 x float > *%tmp to i8 *%s2=bitcast< 16 x float > *%tmp2 to i8 *call void @llvm.memcpy.i64(i8 *%s, i8 *%s2, i64 64, i32 16) %R=load< 16 x float > *%tmp2 ret< 16 x float > %R } declare void @llvm.memcpy.i64(i8 *nocapture, i8 *nocapture, i64, i32) nounwind which compiles to:_foo:subl $140, %esp movaps %xmm3, 112(%esp) movaps %xmm2, 96(%esp) movaps %xmm1, 80(%esp) movaps %xmm0, 64(%esp) movl 60(%esp), %eax movl %eax, 124(%esp) movl 56(%esp), %eax movl %eax, 120(%esp) movl 52(%esp), %eax< many many more 32-bit copies > movaps(%esp), %xmm0 movaps 16(%esp), %xmm1 movaps 32(%esp), %xmm2 movaps 48(%esp), %xmm3 addl $140, %esp ret On Nehalem, it may even be cheaper to just use movups when unaligned than to fall back to lower-granularity chunks. Implement processor-specific optimizations for parity with GCC on these processors. GCC does two optimizations:1. ix86_pad_returns inserts a noop before ret instructions if immediately preceded by a conditional branch or is the target of a jump. 2. ix86_avoid_jump_misspredicts inserts noops in cases where a 16-byte block of code contains more than 3 branches. The first one is done for all AMDs, Core2, and "Generic" The second one is done for:Atom, Pentium Pro, all AMDs, Pentium 4, Nocona, Core 2, and "Generic" Testcase:int x(int a) { return(a &0xf0)> >4 tmp
Definition: README.txt:1347
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::line_iterator::operator->
const StringRef * operator->() const
Definition: LineIterator.h:76
llvm::line_iterator::is_at_end
bool is_at_end() const
Return true if we're an "end" iterator or have reached EOF.
Definition: LineIterator.h:58
llvm::line_iterator::operator!=
friend bool operator!=(const line_iterator &LHS, const line_iterator &RHS)
Definition: LineIterator.h:83
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::line_iterator::operator==
friend bool operator==(const line_iterator &LHS, const line_iterator &RHS)
Definition: LineIterator.h:78
llvm::line_iterator::line_iterator
line_iterator()=default
Default construct an "end" iterator.
llvm::line_iterator::operator++
line_iterator & operator++()
Advance to the next (non-empty, non-comment) line.
Definition: LineIterator.h:64
llvm::line_iterator::is_at_eof
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
Definition: LineIterator.h:55
llvm::line_iterator::line_number
int64_t line_number() const
Return the current line number. May return any number at EOF.
Definition: LineIterator.h:61
DataTypes.h
llvm::line_iterator::operator++
line_iterator operator++(int)
Definition: LineIterator.h:68
llvm::StringRef::begin
iterator begin() const
Definition: StringRef.h:131