238 lines
4.4 KiB
C++
238 lines
4.4 KiB
C++
#ifndef _AS68HC11_EMIT_HPP_
|
|
#define _AS68HC11_EMIT_HPP_
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#endif
|
|
#ifndef _COMMON_PUREVIEWOFFILE_HPP_
|
|
#include <common/pview.hpp>
|
|
#endif
|
|
#ifndef _AS68HC11_CODEPOINTER_HPP_
|
|
#include <as68hc11/codeptr.hpp>
|
|
#endif
|
|
#ifndef _AS68HC11_ORIGIN_HPP_
|
|
#include <as68hc11/origin.hpp>
|
|
#endif
|
|
|
|
class Emit
|
|
{
|
|
public:
|
|
Emit(PureViewOfFile &inputView,PureViewOfFile &outputView);
|
|
Emit(PureViewOfFile &inputView,PureViewOfFile &outputView,const CodePointer &codePointer);
|
|
virtual ~Emit();
|
|
void emit(const char *lpLiteralValue);
|
|
void emit(const String &literalValue);
|
|
void emit(int code,int type,int identifier);
|
|
void emit(int code);
|
|
void emit(int code,double value);
|
|
void emit(int code,int op);
|
|
void emit(BYTE value);
|
|
void emit(WORD value);
|
|
int peek(int &someInt);
|
|
int read(void);
|
|
int read(void *variable,size_t size);
|
|
int read(String &strLiteralString);
|
|
int read(int &someInt);
|
|
int read(double &someDouble);
|
|
int read(BYTE &value);
|
|
BYTE hiByte(DWORD value)const;
|
|
BYTE loByte(DWORD value)const;
|
|
void emitting(int);
|
|
int emitting(void)const;
|
|
PureViewOfFile &inputView(void);
|
|
PureViewOfFile &outputView(void);
|
|
CodePointer &codePointer(void);
|
|
private:
|
|
int mIsEmitting;
|
|
char mLastSymbol;
|
|
PureViewOfFile &mInputView;
|
|
PureViewOfFile &mOutputView;
|
|
CodePointer mCodePointer;
|
|
};
|
|
|
|
inline
|
|
Emit::Emit(PureViewOfFile &inputView,PureViewOfFile &outputView)
|
|
: mIsEmitting(true), mInputView(inputView), mOutputView(outputView)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Emit::Emit(PureViewOfFile &inputView,PureViewOfFile &outputView,const CodePointer &codePointer)
|
|
: mIsEmitting(true), mInputView(inputView), mOutputView(outputView), mCodePointer(codePointer)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Emit::~Emit()
|
|
{
|
|
}
|
|
|
|
inline
|
|
void Emit::emitting(int isEmitting)
|
|
{
|
|
mIsEmitting=isEmitting;
|
|
}
|
|
|
|
inline
|
|
int Emit::emitting(void)const
|
|
{
|
|
return mIsEmitting;
|
|
}
|
|
|
|
inline
|
|
int Emit::read(void)
|
|
{
|
|
if(!mInputView.read((unsigned char&)mLastSymbol))return 0xFFFF;
|
|
return mLastSymbol;
|
|
}
|
|
|
|
inline
|
|
int Emit::read(void *variable,size_t size)
|
|
{
|
|
if(!mInputView.read((char*)variable,size))return 0xFFFF;
|
|
return 0;
|
|
}
|
|
|
|
inline
|
|
int Emit::read(String &strLiteralString)
|
|
{
|
|
String strLiteral;
|
|
int strLength;
|
|
|
|
read(strLength);
|
|
strLiteral.reserve(strLength+1);
|
|
if(0xFFFF==read((char*)strLiteral,strLength))return 0xFFFF;
|
|
strLiteralString=strLiteral;
|
|
return 0;
|
|
}
|
|
|
|
inline
|
|
int Emit::peek(int &someInt)
|
|
{
|
|
if(!mInputView.peek(someInt))return 0xFFFF;
|
|
return 0;
|
|
}
|
|
|
|
inline
|
|
int Emit::read(BYTE &value)
|
|
{
|
|
if(!mInputView.read(value))return 0xFFFF;
|
|
return 0;
|
|
}
|
|
|
|
inline
|
|
int Emit::read(int &someInt)
|
|
{
|
|
if(!mInputView.read(someInt))return 0xFFFF;
|
|
return 0;
|
|
}
|
|
|
|
inline
|
|
int Emit::read(double &someDouble)
|
|
{
|
|
if(!mInputView.read(someDouble))return 0xFFFF;
|
|
return 0;
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(int code)
|
|
{
|
|
if(!mIsEmitting)return;
|
|
mOutputView.write(code);
|
|
mCodePointer+=sizeof(code);
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(int code,int type,int identifier)
|
|
{
|
|
if(!mIsEmitting)return;
|
|
mOutputView.write(code);
|
|
mOutputView.write(type);
|
|
mOutputView.write(identifier);
|
|
mCodePointer+=sizeof(code)+sizeof(type)+sizeof(identifier);
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(int code,double value)
|
|
{
|
|
if(!mIsEmitting)return;
|
|
mOutputView.write(code);
|
|
mOutputView.write(value);
|
|
mCodePointer+=sizeof(code)+sizeof(value);
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(int code,int op)
|
|
{
|
|
if(!mIsEmitting)return;
|
|
mOutputView.write(code);
|
|
mOutputView.write(op);
|
|
mCodePointer+=sizeof(code)+sizeof(op);
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(WORD value)
|
|
{
|
|
if(!mIsEmitting)return;
|
|
mOutputView.write(hiByte(value));
|
|
mOutputView.write(loByte(value));
|
|
mCodePointer+=sizeof(value);
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(BYTE value)
|
|
{
|
|
if(!mIsEmitting)return;
|
|
mOutputView.write(value);
|
|
mCodePointer+=sizeof(value);
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(const char *lpLiteralValue)
|
|
{
|
|
if(!mIsEmitting||!lpLiteralValue)return;
|
|
String strLiteral(lpLiteralValue);
|
|
mOutputView.write(strLiteral);
|
|
mCodePointer+=strLiteral.length();
|
|
}
|
|
|
|
inline
|
|
void Emit::emit(const String &literalValue)
|
|
{
|
|
if(!mIsEmitting)return;
|
|
int stringLength(literalValue.length());
|
|
mOutputView.write(stringLength);
|
|
mOutputView.write(literalValue);
|
|
mCodePointer+=sizeof(stringLength)+stringLength;
|
|
}
|
|
|
|
inline
|
|
BYTE Emit::hiByte(DWORD value)const
|
|
{
|
|
return (BYTE)(((WORD)value)>>0x08);
|
|
}
|
|
|
|
inline
|
|
BYTE Emit::loByte(DWORD value)const
|
|
{
|
|
return (BYTE)value;
|
|
}
|
|
|
|
inline
|
|
PureViewOfFile &Emit::inputView(void)
|
|
{
|
|
return mInputView;
|
|
}
|
|
|
|
inline
|
|
PureViewOfFile &Emit::outputView(void)
|
|
{
|
|
return mOutputView;
|
|
}
|
|
|
|
inline
|
|
CodePointer &Emit::codePointer(void)
|
|
{
|
|
return mCodePointer;
|
|
}
|
|
#endif
|