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,
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(val) <<
";";
358 CodePrimitives::AA ATmegaCodeGenerator::CintarrayAccess(
const AA& address,
int index) {
360 return AA(
"#PGM_FINTEGER# " +
TargetAddress(address) +
"[" + ToStringInteger(index) +
"]");
362 return AA(address +
"[" + ToStringInteger(index) +
"]");
367 CodePrimitives::AA ATmegaCodeGenerator::CintarrayAccess(
const AA& address,
const AA &indexaddr){
377 void ATmegaCodeGenerator::CwordarrayDeclare(
const AA& address,
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(val) <<
";";
400 CodePrimitives::AA ATmegaCodeGenerator::CwordarrayAccess(
const AA& address,
int index) {
402 return AA(
"#PGM_FWORD# " +
TargetAddress(address) +
"[" + ToStringInteger(index) +
"]");
404 return AA(address +
"[" + ToStringInteger(index) +
"]");
409 CodePrimitives::AA ATmegaCodeGenerator::CwordarrayAccess(
const AA& address,
const AA& indexaddr){