33 FD_DCG(
"atmCodeGenerator(" <<
this <<
")::atmCodeGenerator()");
38 FD_DCG(
"atmCodeGenerator(" <<
this <<
")::~atmCodeGenerator()");
44 FD_DCG(
"atmCodeGenerator::Clear()");
60 FD_DCG(
"atmCodeGenerator::DoReadTargetConfiguration()");
65 if(rTr.ExistsBegin(
"ATmegaProgmem")) {
66 rTr.ReadBegin(
"ATmegaProgmem",token);
68 rTr.ReadEnd(
"ATmegaProgmem");
70 if(rTr.ExistsBegin(
"ATmegaPullups")) {
71 rTr.ReadBegin(
"ATmegaPullups",token);
73 rTr.ReadEnd(
"ATmegaPullups");
79 FD_DCG(
"atmCodeGenerator::DoWriteTargetConfiguration()");
100 FD_DCG(
"atmCodeGenerator(" <<
this <<
")::DoCompile()");
116 FCG_VERB0(
"ATmegaCodeGenerator::DoCompile(): target supports pgmread only for 8bit or 16bit data types --- ignoring option ATmegaProgmen ");
121 FCG_ERR(
"atmCodeGenerator::DoCompile(): target supports only 8bit or 16bit integers in compiled transition arrays");
125 FCG_VERB1(
"atmCodeGenerator::DoCompile(): with progmen we prefer bit-address maths over compiled bitmasks");
130 FCG_VERB1(
"atmCodeGenerator::DoCompile(): symbol tables not supported on this target");
138 FD_DCG(
"atmCodeGenerator(" <<
this <<
")::DoGenerate()");
142 Comment(
"************************************************");
143 Comment(
"CodeGenerator: Target ATmega Microcontroller ");
144 Comment(
"************************************************");
158 Output() <<
"}; /* end function " <<
mPrefix <<
"cyclic() */";
168 Comment(
"************************************************");
169 Comment(
"CodeGenerator: Generated Code Ends Here ");
170 Comment(
"************************************************");
177 bool outexists=
false;
178 std::map<char, std::set< std::string > > outbits;
182 if(!ait->second.mSetClr)
continue;
183 if(ait->second.mAddress.size()!=3) {
184 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
186 if(ait->second.mAddress[0]!=
'P') {
187 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
189 char port = ait->second.mAddress[1];
190 if((port <
'A') || (port >
'F')) {
191 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
193 int pin = ait->second.mAddress[2] -
'0';
194 if((pin < 0) || (pin > 7)) {
195 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
197 outbits[port].insert(ait->second.mAddress);
201 bool inpexists=
false;
202 std::map<char, std::set< std::string > > inpbits;
206 if(lit->second.mAddress.size()!=3)
continue;
207 if(lit->second.mAddress[0]!=
'P')
continue;
208 char port = lit->second.mAddress[1];
209 if((port <
'A') || (port >
'F'))
continue;
210 int pin = lit->second.mAddress[2] -
'0';
211 if((pin < 0) || (pin > 7))
continue;
212 inpbits[port].insert(lit->second.mAddress);
218 Comment(
"************************************************");
219 Comment(
"* initialise input/output pins *");
220 Comment(
"************************************************");
224 std::map<char, std::set< std::string > >::iterator oit = outbits.begin();
225 for(;oit!= outbits.end(); ++oit) {
226 Output() <<
"DDR" << oit->first <<
" |= ";
227 std::set< std::string >::iterator bit= oit->second.begin();
229 Output() <<
"( 1 << " << *bit <<
" )";
231 if(bit== oit->second.end())
break;
238 std::map<char, std::set< std::string > >::iterator iit = inpbits.begin();
239 for(;iit!= inpbits.end(); ++iit) {
240 Output() <<
"PORT" << iit->first <<
" |= ";
241 std::set< std::string >::iterator bit= iit->second.begin();
243 Output() <<
"( 1 << " << *bit <<
" )";
245 if(bit== iit->second.end())
break;
258 void ATmegaCodeGenerator::RunActionSet(
const std::string& address) {
259 Output() <<
"PORT" << address[1] <<
" |= ( 1 << " << address <<
" );";
262 void ATmegaCodeGenerator::RunActionClr(
const std::string& address) {
263 Output() <<
"PORT" << address[1] <<
" &= ~( 1 << " << address <<
" );";
270 if(address.size()==3)
275 if(address[2]<=
'7') {
276 std::string res =
"( PIN" + address.substr(1,1) +
" & ( 1 << " + address +
" ) )";
280 std::string res = address;
302 bool pgm_finteger = address.find(
"#PGM_FINTEGER# ")==0;
303 bool pgm_fword = address.find(
"#PGM_FWORD# ")==0;
306 size_t beg= address.find_first_of(
'#',1)+2;
307 std::string addr=address.substr(beg);
312 size_t beg= address.find_first_of(
'#',1)+2;
313 std::string addr=address.substr(beg);
322 bool pgm_finteger = address.find(
"#PGM_FINTEGER# ")==0;
323 bool pgm_fword = address.find(
"#PGM_FWORD# ")==0;
325 if(pgm_finteger || pgm_fword) {
326 FCG_ERR(
"ATmegaCodeGenerator: cannot convert pgm-address to target address")
328 std::string res=
mPrefix+address;
334 void ATmegaCodeGenerator::CintarrayDeclare(
const AA& address,
int offset,
const std::vector<int>& val) {
336 FCG_ERR(
"atmCodeGenerator::Cintarray(): ignoring empty const vector");
340 FCG_ERR(
"atmCodeGenerator::Cwordarray(): const vector exceeds addres range");
351 Output() << IntarrayConstant(offset,val) <<
";";
360 return AA(
"#PGM_FINTEGER# " +
TargetAddress(address) +
"[" + ToStringInteger(index) +
"]");
362 return AA(address +
"[" + ToStringInteger(index) +
"]");
377 void ATmegaCodeGenerator::CwordarrayDeclare(
const AA& address,
int offset,
const std::vector<word_t>& val) {
379 FCG_ERR(
"ecCodeGenerator::Cwordarray(): ignoring empty const vector");
383 FCG_ERR(
"ecCodeGenerator::Cwordarray(): const vector exceeds addres range");
394 Output() << WordarrayConstant(offset,val) <<
";";
402 return AA(
"#PGM_FWORD# " +
TargetAddress(address) +
"[" + ToStringInteger(index) +
"]");
404 return AA(address +
"[" + ToStringInteger(index) +
"]");
std::string mWordType
target data type for word
virtual void DoReadTargetConfiguration(TokenReader &rTr)
File i/o.
bool mBitAddressArithmetic
code option: compute bit and word address on target
ActionAddressIterator ActionAddressesBegin()
Access to action addresses by iterator.
ActionAddressIterator ActionAddressesEnd()
Access to action addresses by iterator.
LineIterator LinesEnd()
Access to line records by iterator.
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
virtual void DoReadTargetConfiguration(TokenReader &rTr)
File i/o.
virtual std::string TargetAddress(const AA &address)
abstract address conversion
std::string mIntegerType
target data type for integer
virtual void DecrementTimers(void)
re-implemented/additional code blocks
Code-generator for ATmega microcontrollers.
virtual void IndentDec()
Indentation (convenience support for derived classes)
Abstract expression; see also Absstract_Addresses.
virtual void DoGenerateDeclarations(void)
cut-and-paste template for code snippet assembly
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
virtual void LiteralAppend(void)
Cosmetic: append literally from configuration.
virtual AX TargetExpression(const AA &address)
abstract address conversion
Target ATmega micro-controller (AVR8)
bool mATmegaPullups
ATmega code options.
bool mEventNameLookup
code option: event name lookup
void DoGenerate(void)
protected version of generate
std::map< std::string, bitarray_rec > mBitarrays
Record of all declared bit-arrays.
std::map< std::string, ActionAddress >::iterator ActionAddressIterator
Access to action record by iterator.
std::string mATmegaPgmReadInteger
ATmega code options.
LineIterator LinesBegin()
Access to line records by iterator.
bool mArrayForBitmasks
code option: use const array to represent bit-masks
Implementation of code primitives by generic C-code.
Abstract address; see also Absstract_Addresses.
std::string mPrefix
universal prefix (pseudo name space)
static std::string VersionString(void)
Version (refers to macro COMPILEDES_VERSION, defined in cgp_codegenerator.h)
virtual std::ostream & Output(void)
Output stream.
int mWordSize
compressed boolean capacity of target type word
void DoCompile(void)
add my preferences to DoCompile
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
virtual ~ATmegaCodeGenerator(void)
virtual void LineFeed(int lines=1)
LineFeed (convenience support for derived classes)
virtual void DoGenerateCyclicCode(void)
cut-and-paste template for code snippet assembly
void DoCompile(void)
add my preferences to DoCompile
ATmegaCodeGenerator(void)
virtual void InitialisePorts(void)
reimplemented/additional code blocks
bool mArrayForTransitions
code option: use const array to represent transitions
bool mStateNameLookup
code option: state name lookup
virtual void LiteralPrepend(void)
Cosmetic: prepend literally from configuration data.
bool mATmegaProgmem
ATmega code options.
virtual void IndentInc()
Indentation (convenience support for derived classes)
#define FAUDES_REGISTERCODEGENERATOR(ftype, ctype)
Class registration macro.
std::string mATmegaPgmReadWord
ATmega code options.
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
virtual void Comment(const std::string &text)
Target comments (see EmbeddedcCodeGenerator for consistent reimplementation pattern) ...
int mIntegerSize
compressed boolean capacity of target type integer
virtual void Clear(void)
Clear all data.