OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
AssemblyParserDiagnostic Class Reference

#include <AssemblyParserDiagnostic.hh>

Collaboration diagram for AssemblyParserDiagnostic:
Collaboration graph

Public Member Functions

void reset (std::shared_ptr< const std::string > assemblyText)
 
void addWarning (UValue lineNumber, const std::string &message)
 
void addError (UValue lineNumber, const std::string &message)
 
void addError (const std::string &message)
 
void clear ()
 
const std::set< CompilerMessage > & warnings () const
 
bool anyErrors () const
 
const std::set< CompilerMessage > & errors () const
 
const std::set< CompilerMessage > & otherErrors () const
 
std::string codeLine (UValue lineNumber) const
 

Private Attributes

std::set< CompilerMessagewarnings_
 Warning messages. More...
 
std::set< CompilerMessagecodeErrors_
 Error messages with line number. More...
 
std::set< CompilerMessageotherErrors_
 For positionless and internal errors. More...
 
std::shared_ptr< const std::string > listing_ = nullptr
 The current assembly listing. More...
 
std::vector< UValuelineStarts_
 New line start positions in assembly listing. More...
 

Detailed Description

The class for storing and query assembly parser reports.

Definition at line 68 of file AssemblyParserDiagnostic.hh.

Member Function Documentation

◆ addError() [1/2]

void AssemblyParserDiagnostic::addError ( const std::string &  message)

Definition at line 79 of file AssemblyParserDiagnostic.cc.

79  {
80  CompilerMessage msg;
81  msg.message = message;
82  otherErrors_.insert(msg);
83 }

References CompilerMessage::message, and otherErrors_.

◆ addError() [2/2]

void AssemblyParserDiagnostic::addError ( UValue  lineNumber,
const std::string &  message 
)

Definition at line 68 of file AssemblyParserDiagnostic.cc.

69  {
70 
71  CompilerMessage msg;
72  msg.lineNumber = lineNumber;
73  msg.message = message;
74  msg.assemblerLine = codeLine(lineNumber);
75  codeErrors_.insert(msg);
76 }

References CompilerMessage::assemblerLine, codeErrors_, codeLine(), CompilerMessage::lineNumber, and CompilerMessage::message.

Referenced by InlineAsmParser::reportError().

Here is the call graph for this function:

◆ addWarning()

void AssemblyParserDiagnostic::addWarning ( UValue  lineNumber,
const std::string &  message 
)

Definition at line 56 of file AssemblyParserDiagnostic.cc.

58  {
59 
60  CompilerMessage newWarning;
61  newWarning.lineNumber = lineNumber;
62  newWarning.message = message;
63  newWarning.assemblerLine = codeLine(lineNumber);
64  warnings_.insert(newWarning);
65 }

References CompilerMessage::assemblerLine, codeLine(), CompilerMessage::lineNumber, CompilerMessage::message, and warnings_.

Referenced by CodeSectionCreator::addMove(), Assembler::addWarning(), MachineResourceManager::indexResource(), and MachineResourceManager::rFPortOrFUIndexReference().

Here is the call graph for this function:

◆ anyErrors()

bool AssemblyParserDiagnostic::anyErrors ( ) const
inline

Definition at line 82 of file AssemblyParserDiagnostic.hh.

82  {
83  return errors().size() && otherErrors().size();
84  }

References errors(), and otherErrors().

Here is the call graph for this function:

◆ clear()

void AssemblyParserDiagnostic::clear ( )

Clears all accumulated reports.

Definition at line 89 of file AssemblyParserDiagnostic.cc.

89  {
90  warnings_.clear();
91  codeErrors_.clear();
92  otherErrors_.clear();
93 }

References codeErrors_, otherErrors_, and warnings_.

Referenced by reset().

◆ codeLine()

std::string AssemblyParserDiagnostic::codeLine ( UValue  lineNumber) const

Definition at line 96 of file AssemblyParserDiagnostic.cc.

96  {
97  std::string errorLine;
98 
99  assert(listing_ && "reset() must be called before codeLine().");
100 
101  unsigned int errorLineNum =
102  static_cast<unsigned int>(lineNumber - 1);
103 
104  if (errorLineNum < lineStarts_.size()) {
105 
106  std::string::size_type startPos =
107  lineStarts_[errorLineNum];
108 
109  std::string::size_type endPos = listing_->find('\n', startPos);
110 
111  // no line feed at end of file
112  if (endPos == std::string::npos) {
113  endPos = listing_->length();
114  }
115 
116  errorLine = listing_->substr(startPos, endPos - startPos);
117 
118  } else {
119  errorLine = "Invalid line number info, probably last line of file.";
120  }
121 
122  return errorLine;
123 }

References assert, lineStarts_, and listing_.

Referenced by addError(), addWarning(), and Assembler::codeLine().

◆ errors()

const std::set<CompilerMessage>& AssemblyParserDiagnostic::errors ( ) const
inline

Definition at line 86 of file AssemblyParserDiagnostic.hh.

86  {
87  return codeErrors_;
88  }

References codeErrors_.

Referenced by anyErrors().

◆ otherErrors()

const std::set<CompilerMessage>& AssemblyParserDiagnostic::otherErrors ( ) const
inline

Definition at line 90 of file AssemblyParserDiagnostic.hh.

90  {
91  return otherErrors_;
92  }

References otherErrors_.

Referenced by anyErrors().

◆ reset()

void AssemblyParserDiagnostic::reset ( std::shared_ptr< const std::string >  assemblyText)

Resets assembly text. Also clears all reports.

Definition at line 40 of file AssemblyParserDiagnostic.cc.

41  {
42 
43  clear();
44 
45  listing_ = assemblyText;
46  lineStarts_.push_back(0);
47  for (size_t pos = 0; pos < listing_->size(); pos++) {
48  char c = listing_->at(pos);
49  if (c == '\n') {
50  lineStarts_.push_back(pos+1);
51  }
52  }
53 }

References clear(), lineStarts_, and listing_.

Referenced by Assembler::compile(), and InlineAsmParser::parse().

Here is the call graph for this function:

◆ warnings()

const std::set<CompilerMessage>& AssemblyParserDiagnostic::warnings ( ) const
inline

Definition at line 78 of file AssemblyParserDiagnostic.hh.

78  {
79  return warnings_;
80  }

References warnings_.

Referenced by llvm::LLVMTCEBuilder::emitInlineAsm(), and Assembler::warnings().

Member Data Documentation

◆ codeErrors_

std::set<CompilerMessage> AssemblyParserDiagnostic::codeErrors_
private

Error messages with line number.

Definition at line 102 of file AssemblyParserDiagnostic.hh.

Referenced by addError(), clear(), and errors().

◆ lineStarts_

std::vector<UValue> AssemblyParserDiagnostic::lineStarts_
private

New line start positions in assembly listing.

Definition at line 111 of file AssemblyParserDiagnostic.hh.

Referenced by codeLine(), and reset().

◆ listing_

std::shared_ptr<const std::string> AssemblyParserDiagnostic::listing_ = nullptr
private

The current assembly listing.

Definition at line 108 of file AssemblyParserDiagnostic.hh.

Referenced by codeLine(), and reset().

◆ otherErrors_

std::set<CompilerMessage> AssemblyParserDiagnostic::otherErrors_
private

For positionless and internal errors.

Definition at line 105 of file AssemblyParserDiagnostic.hh.

Referenced by addError(), clear(), and otherErrors().

◆ warnings_

std::set<CompilerMessage> AssemblyParserDiagnostic::warnings_
private

Warning messages.

Definition at line 99 of file AssemblyParserDiagnostic.hh.

Referenced by addWarning(), clear(), and warnings().


The documentation for this class was generated from the following files:
AssemblyParserDiagnostic::codeErrors_
std::set< CompilerMessage > codeErrors_
Error messages with line number.
Definition: AssemblyParserDiagnostic.hh:102
CompilerMessage::message
std::string message
Message.
Definition: AssemblyParserDiagnostic.hh:47
CompilerMessage::assemblerLine
std::string assemblerLine
Assembly code line number.
Definition: AssemblyParserDiagnostic.hh:48
assert
#define assert(condition)
Definition: Application.hh:86
CompilerMessage::lineNumber
UValue lineNumber
Message generation line number.
Definition: AssemblyParserDiagnostic.hh:49
AssemblyParserDiagnostic::otherErrors_
std::set< CompilerMessage > otherErrors_
For positionless and internal errors.
Definition: AssemblyParserDiagnostic.hh:105
CompilerMessage
Definition: AssemblyParserDiagnostic.hh:46
AssemblyParserDiagnostic::clear
void clear()
Definition: AssemblyParserDiagnostic.cc:89
AssemblyParserDiagnostic::otherErrors
const std::set< CompilerMessage > & otherErrors() const
Definition: AssemblyParserDiagnostic.hh:90
AssemblyParserDiagnostic::errors
const std::set< CompilerMessage > & errors() const
Definition: AssemblyParserDiagnostic.hh:86
AssemblyParserDiagnostic::codeLine
std::string codeLine(UValue lineNumber) const
Definition: AssemblyParserDiagnostic.cc:96
AssemblyParserDiagnostic::lineStarts_
std::vector< UValue > lineStarts_
New line start positions in assembly listing.
Definition: AssemblyParserDiagnostic.hh:111
AssemblyParserDiagnostic::warnings_
std::set< CompilerMessage > warnings_
Warning messages.
Definition: AssemblyParserDiagnostic.hh:99
AssemblyParserDiagnostic::listing_
std::shared_ptr< const std::string > listing_
The current assembly listing.
Definition: AssemblyParserDiagnostic.hh:108