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 recommended on this target due to memory restrictions");
136 FD_DCG(
"atmCodeGenerator(" <<
this <<
")::DoGenerate()");
140 Comment(
"************************************************");
141 Comment(
"CodeGenerator: Target ATmega Microcontroller ");
142 Comment(
"************************************************");
157 Output() <<
"}; /* end function " <<
mPrefix <<
"cyclic() */";
167 Comment(
"************************************************");
168 Comment(
"CodeGenerator: Generated Code Ends Here ");
169 Comment(
"************************************************");
176 bool outexists=
false;
177 std::map<char, std::set< std::string > > outbits;
181 if(!ait->second.mSetClr)
continue;
182 if(ait->second.mAddress.size()!=3) {
183 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
185 if(ait->second.mAddress[0]!=
'P') {
186 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
188 char port = ait->second.mAddress[1];
189 if((port <
'A') || (port >
'F')) {
190 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
192 int pin = ait->second.mAddress[2] -
'0';
193 if((pin < 0) || (pin > 7)) {
194 FCG_ERR(
"atmCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
196 outbits[port].insert(ait->second.mAddress);
200 bool inpexists=
false;
201 std::map<char, std::set< std::string > > inpbits;
205 if(lit->second.mAddress.size()!=3)
continue;
206 if(lit->second.mAddress[0]!=
'P')
continue;
207 char port = lit->second.mAddress[1];
208 if((port <
'A') || (port >
'F'))
continue;
209 int pin = lit->second.mAddress[2] -
'0';
210 if((pin < 0) || (pin > 7))
continue;
211 inpbits[port].insert(lit->second.mAddress);
217 Comment(
"************************************************");
218 Comment(
"* initialise input/output pins *");
219 Comment(
"************************************************");
223 std::map<char, std::set< std::string > >::iterator oit = outbits.begin();
224 for(;oit!= outbits.end(); ++oit) {
225 Output() <<
"DDR" << oit->first <<
" |= ";
226 std::set< std::string >::iterator bit= oit->second.begin();
228 Output() <<
"( 1 << " << *bit <<
" )";
230 if(bit== oit->second.end())
break;
237 std::map<char, std::set< std::string > >::iterator iit = inpbits.begin();
238 for(;iit!= inpbits.end(); ++iit) {
239 Output() <<
"PORT" << iit->first <<
" |= ";
240 std::set< std::string >::iterator bit= iit->second.begin();
242 Output() <<
"( 1 << " << *bit <<
" )";
244 if(bit== iit->second.end())
break;
257 void ATmegaCodeGenerator::RunActionSet(
const std::string& address) {
258 Output() <<
"PORT" << address[1] <<
" |= ( 1 << " << address <<
" );";
261 void ATmegaCodeGenerator::RunActionClr(
const std::string& address) {
262 Output() <<
"PORT" << address[1] <<
" &= ~( 1 << " << address <<
" );";
269 if(address.size()==3)
274 if(address[2]<=
'7') {
275 std::string res =
"( PIN" + address.substr(1,1) +
" & ( 1 << " + address +
" ) )";
279 std::string res = address;
301 bool pgm_finteger = address.find(
"#PGM_FINTEGER# ")==0;
302 bool pgm_fword = address.find(
"#PGM_FWORD# ")==0;
305 size_t beg= address.find_first_of(
'#',1)+2;
306 std::string addr=address.substr(beg);
311 size_t beg= address.find_first_of(
'#',1)+2;
312 std::string addr=address.substr(beg);
321 bool pgm_finteger = address.find(
"#PGM_FINTEGER# ")==0;
322 bool pgm_fword = address.find(
"#PGM_FWORD# ")==0;
324 if(pgm_finteger || pgm_fword) {
325 FCG_ERR(
"ATmegaCodeGenerator: cannot convert pgm-address to target address")
327 std::string res=
mPrefix+address;
333 void ATmegaCodeGenerator::CintarrayDeclare(
const AA& address,
int offset,
const std::vector<int>& val) {
335 FCG_ERR(
"atmCodeGenerator::Cintarray(): ignoring empty const vector");
339 FCG_ERR(
"atmCodeGenerator::Cwordarray(): const vector exceeds addres range");
350 Output() << IntarrayConstant(offset,val) <<
";";
359 return AA(
"#PGM_FINTEGER# " +
TargetAddress(address) +
"[" + ToStringInteger(index) +
"]");
361 return AA(address +
"[" + ToStringInteger(index) +
"]");
376 void ATmegaCodeGenerator::CwordarrayDeclare(
const AA& address,
int offset,
const std::vector<word_t>& val) {
378 FCG_ERR(
"ecCodeGenerator::Cwordarray(): ignoring empty const vector");
382 FCG_ERR(
"ecCodeGenerator::Cwordarray(): const vector exceeds addres range");
393 Output() << WordarrayConstant(offset,val) <<
";";
401 return AA(
"#PGM_FWORD# " +
TargetAddress(address) +
"[" + ToStringInteger(index) +
"]");
403 return AA(address +
"[" + ToStringInteger(index) +
"]");
418 void ATmegaCodeGenerator::CstrarrayDeclare(
const AA& address,
int offset,
const std::vector<std::string>& val) {
420 FCG_ERR(
"ATmegaCodeGenerator::Cstrarrayy(): ignoring empty string array");
424 FCG_ERR(
"ATmegaCodeGenerator::Cstrarray(): string array exceeds address range");
429 Output() << StrarrayConstant(offset,val) <<
";";
436 for(vit=offset; vit<val.size()+offset; ++vit) {
438 Output() << StringConstant(val[vit-offset]) <<
";";
444 std::stringstream strstr;
446 strstr <<
"{" << std::endl;
449 if(vit==val.size()+offset)
break;
450 if(vit < (
size_t)offset)
455 if(vit==val.size()+offset)
break;
464 Output() <<
AX(strstr.str()) <<
";";
474 FCG_ERR(
"ATmegaCodeGenerator::Cstrarray(): constant-str-arrays access not defined");
480 FCG_ERR(
"ATmegaCodeGenerator::Cstrarray(): constant-str-arrays access not defined");
#define FAUDES_REGISTERCODEGENERATOR(ftype, ctype)
Class registration macro.
virtual void DoGenerateCyclicCode(void)
cut-and-paste template for code snippet assembly
Code-generator for ATmega microcontrollers.
std::string mATmegaPgmReadInteger
ATmega code options.
Abstract expression; see also Absstract_Addresses.
LineIterator LinesEnd()
Access to line records by iterator.
virtual std::ostream & Output(void)
Output stream.
virtual void DoGenerateResetCode(void)
cut-and-paste template for code snippet assembly
int mWordSize
compressed boolean capacity of target type word
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
virtual void DoReadTargetConfiguration(TokenReader &rTr)
File i/o.
virtual void LineFeed(int lines=1)
LineFeed (convenience support for derived classes)
Implementation of code primitives by generic C-code.
virtual void DecrementTimers(void)
re-implemented/additional code blocks
virtual void InitialisePorts(void)
reimplemented/additional code blocks
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
virtual void Clear(void)
Clear all data.
virtual void IndentInc()
Indentation (convenience support for derived classes)
bool mArrayForBitmasks
code option: use const array to represent bit-masks
virtual void DoGenerateDeclarations(void)
cut-and-paste template for code snippet assembly
void DoCompile(void)
add my preferences to DoCompile
static std::string VersionString(void)
Version (refers to macro COMPILEDES_VERSION, defined in cgp_codegenerator.h)
std::string mIntegerType
target data type for integer
Target ATmega micro-controller (AVR8)
virtual AX TargetExpression(const AA &address)
abstract address conversion
virtual void LiteralAppend(void)
Cosmetic: append literally from configuration.
virtual void DoReadTargetConfiguration(TokenReader &rTr)
File i/o.
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
int mIntegerSize
compressed boolean capacity of target type integer
std::map< std::string, ActionAddress >::iterator ActionAddressIterator
Access to action record by iterator.
std::string mWordType
target data type for word
virtual ~ATmegaCodeGenerator(void)
bool mEventNameLookup
code option: event name lookup
ActionAddressIterator ActionAddressesBegin()
Access to action addresses by iterator.
virtual std::string TargetAddress(const AA &address)
abstract address conversion
std::string mATmegaPgmReadWord
ATmega code options.
bool mATmegaProgmem
ATmega code options.
Abstract address; see also Absstract_Addresses.
bool mArrayForTransitions
code option: use const array to represent transitions
bool mStateNameLookup
code option: state name lookup
bool mATmegaPullups
ATmega code options.
ActionAddressIterator ActionAddressesEnd()
Access to action addresses by iterator.
void DoCompile(void)
add my preferences to DoCompile
std::string mPrefix
universal prefix (pseudo name space)
ATmegaCodeGenerator(void)
void DoGenerate(void)
protected version of generate
virtual void IndentDec()
Indentation (convenience support for derived classes)
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
std::map< std::string, bitarray_rec > mBitarrays
Record of all declared bit-arrays.
LineIterator LinesBegin()
Access to line records by iterator.
virtual void LiteralPrepend(void)
Cosmetic: prepend literally from configuration data.
bool mBitAddressArithmetic
code option: compute bit and word address on target
virtual void Comment(const std::string &text)
Target comments (see EmbeddedcCodeGenerator for consistent reimplementation pattern) ...