OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
std::set< CompilerMessagecodeErrors_
 Error messages with line number.
 
std::set< CompilerMessageotherErrors_
 For positionless and internal errors.
 
std::shared_ptr< const std::string > listing_ = nullptr
 The current assembly listing.
 
std::vector< UValuelineStarts_
 New line start positions in assembly listing.
 

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 {
81 msg.message = message;
82 otherErrors_.insert(msg);
83}
std::set< CompilerMessage > otherErrors_
For positionless and internal errors.
std::string message
Message.

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
72 msg.lineNumber = lineNumber;
73 msg.message = message;
74 msg.assemblerLine = codeLine(lineNumber);
75 codeErrors_.insert(msg);
76}
std::string codeLine(UValue lineNumber) const
std::set< CompilerMessage > codeErrors_
Error messages with line number.
std::string assemblerLine
Assembly code line number.
UValue lineNumber
Message generation line number.

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

Referenced by InlineAsmParser::reportError(), and 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}
std::set< CompilerMessage > warnings_
Warning messages.

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 }
const std::set< CompilerMessage > & errors() const
const std::set< CompilerMessage > & otherErrors() const

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}
#define assert(condition)
std::shared_ptr< const std::string > listing_
The current assembly listing.
std::vector< UValue > lineStarts_
New line start positions in assembly listing.

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: