OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Assembler Class Reference

#include <Assembler.hh>

Collaboration diagram for Assembler:
Collaboration graph

Public Member Functions

 Assembler (TPEF::BinaryStream &assemblerFile, TTAMachine::Machine &assemblerMachine)
 
TPEF::Binarycompile ()
 
const std::set< CompilerMessage > & warnings () const
 
const CompilerMessageerror () const
 
void addWarning (UValue lineNumber, std::string errorMessage)
 
const TTAMachine::MachinetargetMachine () const
 

Private Member Functions

void readAssemblerCode ()
 
std::string codeLine (UValue lineNumber) const
 

Private Attributes

TPEF::BinaryStreamstream_
 File containing file to assemble.
 
TTAMachine::Machinemach_
 Machine for assembled TPEF.
 
CompilerMessage error_
 Last thrown error message.
 
AssemblyParserDiagnostic parserDiagnostic_
 Parser messages.
 
std::shared_ptr< std::string > asmCode_
 String containing code to compile.
 

Detailed Description

TCE Assembler user interface.

Definition at line 55 of file Assembler.hh.

Constructor & Destructor Documentation

◆ Assembler()

Assembler::Assembler ( TPEF::BinaryStream assemblerFile,
TTAMachine::Machine assemblerMachine 
)

Constructor.

Parameters
assemblerFileStream containing file to assemble.
assemblerMachineMachine to use for running compiled binary.

Definition at line 55 of file Assembler.cc.

57 :
58 stream_(assemblerFile), mach_(&assemblerMachine) {
59}
TTAMachine::Machine * mach_
Machine for assembled TPEF.
Definition Assembler.hh:80
TPEF::BinaryStream & stream_
File containing file to assemble.
Definition Assembler.hh:77

Member Function Documentation

◆ addWarning()

void Assembler::addWarning ( UValue  lineNumber,
std::string  errorMessage 
)

Adds warning message for client to see.

Parameters
lineNumberLine number of assembly code, where error accured.
errorMessageWarning message.

Definition at line 140 of file Assembler.cc.

140 {
141 parserDiagnostic_.addWarning(lineNumber, errorMessage);
142}
AssemblyParserDiagnostic parserDiagnostic_
Parser messages.
Definition Assembler.hh:86
void addWarning(UValue lineNumber, const std::string &message)

References AssemblyParserDiagnostic::addWarning(), and parserDiagnostic_.

Here is the call graph for this function:

◆ codeLine()

std::string Assembler::codeLine ( UValue  lineNumber) const
private

Definition at line 196 of file Assembler.cc.

196 {
197 return parserDiagnostic_.codeLine(lineNumber);
198}
std::string codeLine(UValue lineNumber) const

References AssemblyParserDiagnostic::codeLine(), and parserDiagnostic_.

Referenced by compile().

Here is the call graph for this function:

◆ compile()

Binary * Assembler::compile ( )

Compiles assembler and returns TPEF hierarchy.

Returns
Compiled TPEF.
Exceptions
CompileErrorIf there was any problems during the compilation.

Definition at line 68 of file Assembler.cc.

68 {
69 // read binary stream to string
71
72 // clear old warnings from previous compilation
74
75 Binary* newBinary = new Binary();
76
77 // this one does the actual parsing work
78 AssemblerParser parser(*newBinary, *mach_, &parserDiagnostic_);
79
80 try {
81 try {
82 if (!parser.compile(*asmCode_)) {
83
85 __FILE__, __LINE__, __func__, "Syntax error.");
86
87 error.setCodeFileLineNumber(parser.errorLine());
88
89 throw error;
90 }
91
92 // ObjectAllreadyExists and IllegalMachine exceptions.
93 } catch (Exception& e) {
94
96 __FILE__, __LINE__, __func__, e.errorMessage());
97
98 error.setCause(e);
99 error.setCodeFileLineNumber(parser.errorLine());
100
101 throw error;
102 }
103
104 parser.finalize(mach_->isLittleEndian());
105
106 } catch (CompileError& e) {
107
111
112 // clean up internals of creators and managers and delete
113 // partial binary
114 parser.cleanup();
115
116 delete newBinary;
117 newBinary = NULL;
118
120 __FILE__, __LINE__, __func__,
121 "Error in line " + Conversion::toString(error_.lineNumber) +
122 ": " + error_.assemblerLine + "\nMessage: " + error_.message);
123
124 error.setCause(e);
125 error.setCodeFileLineNumber(error_.lineNumber);
126
127 throw error;
128 }
129
130 return newBinary;
131}
#define __func__
const CompilerMessage & error() const
Definition Assembler.cc:165
std::string codeLine(UValue lineNumber) const
Definition Assembler.cc:196
std::shared_ptr< std::string > asmCode_
String containing code to compile.
Definition Assembler.hh:89
void readAssemblerCode()
Definition Assembler.cc:173
CompilerMessage error_
Last thrown error message.
Definition Assembler.hh:83
void reset(std::shared_ptr< const std::string > assemblyText)
int codeFileLineNumber()
static std::string toString(const T &source)
std::string errorMessage() const
Definition Exception.cc:123
bool isLittleEndian() const
Definition Machine.hh:258
std::string message
Message.
std::string assemblerLine
Assembly code line number.
UValue lineNumber
Message generation line number.

References __func__, asmCode_, CompilerMessage::assemblerLine, AssemblerParser::cleanup(), CompileError::codeFileLineNumber(), codeLine(), AssemblerParser::compile(), error(), error_, AssemblerParser::errorLine(), Exception::errorMessage(), AssemblerParser::finalize(), TTAMachine::Machine::isLittleEndian(), CompilerMessage::lineNumber, mach_, CompilerMessage::message, parserDiagnostic_, readAssemblerCode(), AssemblyParserDiagnostic::reset(), and Conversion::toString().

Referenced by main().

Here is the call graph for this function:

◆ error()

const CompilerMessage & Assembler::error ( ) const

Returns last thrown error message..

Returns
Error that halted compilation.

Definition at line 165 of file Assembler.cc.

165 {
166 return error_;
167}

References error_.

Referenced by compile().

◆ readAssemblerCode()

void Assembler::readAssemblerCode ( )
private

Reads assembly code from binary stream to a string.

Definition at line 173 of file Assembler.cc.

173 {
174 unsigned int streamPosition = stream_.readPosition();
175
176 asmCode_ = std::make_shared<std::string>();
177
178 // read file to string and mark line start indexes.
179 for (unsigned int i = streamPosition; i < stream_.sizeOfFile(); i++) {
180 Byte readByte = stream_.readByte();
181 *asmCode_ += readByte;
182 }
183
184 // restore stream position...
185 stream_.setReadPosition(streamPosition);
186}
unsigned char Byte
Definition BaseType.hh:116
void setReadPosition(unsigned int position)
unsigned int readPosition()
unsigned int sizeOfFile()

References asmCode_, TPEF::BinaryStream::readByte(), TPEF::BinaryStream::readPosition(), TPEF::BinaryStream::setReadPosition(), TPEF::BinaryStream::sizeOfFile(), and stream_.

Referenced by compile().

Here is the call graph for this function:

◆ targetMachine()

const TTAMachine::Machine & Assembler::targetMachine ( ) const

Returns the target machine of the assembler.

Returns
The target machine.

Definition at line 150 of file Assembler.cc.

150 {
151 return *mach_;
152}

References mach_.

◆ warnings()

const std::set< CompilerMessage > & Assembler::warnings ( ) const

Definition at line 155 of file Assembler.cc.

155 {
157}
const std::set< CompilerMessage > & warnings() const

References parserDiagnostic_, and AssemblyParserDiagnostic::warnings().

Referenced by main().

Here is the call graph for this function:

Member Data Documentation

◆ asmCode_

std::shared_ptr<std::string> Assembler::asmCode_
private

String containing code to compile.

Definition at line 89 of file Assembler.hh.

Referenced by compile(), and readAssemblerCode().

◆ error_

CompilerMessage Assembler::error_
private

Last thrown error message.

Definition at line 83 of file Assembler.hh.

Referenced by compile(), and error().

◆ mach_

TTAMachine::Machine* Assembler::mach_
private

Machine for assembled TPEF.

Definition at line 80 of file Assembler.hh.

Referenced by compile(), and targetMachine().

◆ parserDiagnostic_

AssemblyParserDiagnostic Assembler::parserDiagnostic_
private

Parser messages.

Definition at line 86 of file Assembler.hh.

Referenced by addWarning(), codeLine(), compile(), and warnings().

◆ stream_

TPEF::BinaryStream& Assembler::stream_
private

File containing file to assemble.

Definition at line 77 of file Assembler.hh.

Referenced by readAssemblerCode().


The documentation for this class was generated from the following files: