Hi All.
As an intermediate step to check errors and perform cleanup and
optimisation I'm using a CIL derivative[1]. This produces a considerably
more readable and smaller program than the generated original. The
attached program is a simple serial port echo program produced first by
TinyOS+nesc and then by the CIL inline tool.

When compiling it with Keil it compiles cleanly and does what I would
expect (echo back chars), but using SDCC the errors explode all over the
screen and the program behaves strangely (ver 2.8.0 from Ubuntu). I've
been unable to narrow the error to any specific line, so any help would
be appreciated.

[1] http://www.cs.utah.edu/~coop/research/tools/

I'm compiling it with the following arguments, and the resulting program
does not repeat the char that I type back (it writes something just not
the char that I typed). A guess would be that the global variable
"EchoP__buf" is not updated correctly (line 307)
 sdcc -mmcs51 --model-large --no-c-code-in-asm --std-sdcc99 app.c -oapp

Does anyone have a clue as to what could be causing this difference in
behaviour?

The output from SDCC is:
app.c:45: warning 166: useless declaration (possible use of keyword as
variable name)
app.c:46: warning 166: useless declaration (possible use of keyword as
variable name)
app.c:48: warning 166: useless declaration (possible use of keyword as
variable name)
app.c:176: warning 126: unreachable code
app.c:177: warning 126: unreachable code
app.c:177: warning 126: unreachable code
app.c:177: warning 126: unreachable code
app.c:177: warning 126: unreachable code
app.c:178: warning 126: unreachable code
app.c:178: warning 126: unreachable code
app.c:178: warning 126: unreachable code
app.c:178: warning 126: unreachable code
app.c:181: warning 126: unreachable code
app.c:182: warning 126: unreachable code
app.c:182: warning 126: unreachable code
app.c:182: warning 126: unreachable code
app.c:182: warning 126: unreachable code
app.c:184: warning 126: unreachable code
app.c:185: warning 126: unreachable code
app.c:185: warning 126: unreachable code
app.c:185: warning 126: unreachable code
app.c:185: warning 126: unreachable code
app.c:186: warning 126: unreachable code
app.c:186: warning 126: unreachable code
app.c:186: warning 126: unreachable code
app.c:186: warning 126: unreachable code
app.c:243: warning 126: unreachable code
app.c:275: warning 166: useless declaration (possible use of keyword as
variable name)
app.c:342: warning 126: unreachable code
app.c:342: warning 126: unreachable code
app.c:343: warning 126: unreachable code
app.c:343: warning 126: unreachable code
app.c:343: warning 126: unreachable code
app.c:349: warning 166: useless declaration (possible use of keyword as
variable name)
app.c:362: warning 166: useless declaration (possible use of keyword as
variable name)


-- 
Regards Martin Leopold.
#define MANGLED_NESC_APP_C
/* Inline flags --8051 --auto --clean --shorten */
/* Generated by CIL v. 1.3.4 */
/* print_CIL_Input is true */

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef uint8_t bool;
typedef uint8_t __nesc_atomic_t;
enum __nesc_unnamed4252 {
    B75 = 1,
    B150 = 2,
    B300 = 4,
    B600 = 8,
    B1200 = 16,
    B1800 = 24,
    B2400 = 32,
    B4800 = 64,
    B9600 = 128,
    B19200 = 256,
    B38400 = 512,
    B57600 = 768,
    B76800 = 1024,
    B115200 = 1536,
    B230400 = 3072,
    B460800 = 6144,
    B576000 = 7680,
    B921600 = 12288,
    B1152000 = 15360,
    B3000000 = -25536
} ;
typedef enum __nesc_unnamed4252 ser_rate_t;
enum __nesc_unnamed4256 {
    MCS51_TIMER_MODE_13BIT = 0,
    MCS51_TIMER_MODE_16BIT = 1,
    MCS51_TIMER_MODE_8BIT_RELOAD = 2,
    MCS51_TIMER_MODE_DOUBLE_8BIT = 3
} ;
typedef enum __nesc_unnamed4256 mcs51_timer_mode_t;
extern void *memset(void *s , char val , int n ) ;
static bool SchedulerBasicP__Scheduler__runNextTask(void) ;

int main(void) ;
void /*__attribute__((__interrupt__))  __vector_4(void)  __attribute__((__interrupt__))*/ ;
void /*__attribute__((__interrupt__))  __vector_1(void)  __attribute__((__interrupt__))*/ ;
//#line 116
void /*__attribute__((__interrupt__))  __vector_3(void)  __attribute__((__interrupt__))*/ ;
#ifdef SDCC
__sfr __at (0x98) SCON0 ;
__sfr __at (0x99) SBUF0 ;
__sfr __at (0xA6) P2MDOUT ;
__sfr __at (0xA9) CLKSEL ;
__sfr __at (0xB2) OSCICN ;
__sfr __at (0xB6) FLSCL ;
__sfr __at (0xB8) IP ;
__sfr __at (0xB9) CLKMUL ;
__sfr __at (0xD4) P0SKIP ;
__sfr __at (0xD5) P1SKIP ;
__sfr __at (0xD6) P2SKIP ;
__sfr __at (0xD9) PCA0MD ;
__sfr __at (0xE1) XBR0 ;
__sfr __at (0xE2) XBR1 ;
__sfr __at (0xE3) XBR2 ;
__sbit __at (0xAC) ES0 ;
__sbit __at (0xAB) ET1 ;
__sfr __at (0x89) TMOD ;
__sfr __at (0x8B) TL1 ;
__sfr __at (0x8D) TH1 ;
__sfr __at (0x8E) CKCON ;
__sfr __at (0x98) SCON ;
__sbit __at (0x8F) TF1 ;
__sbit __at (0x8E) TR1 ;
__sbit __at (0x8D) TF0 ;
__sbit __at (0xAF) EA ;
__sbit __at (0xA2) P2_2 ;
__sbit __at (0xA3) P2_3 ;
#else
sfr SCON0 = 0x98;
sfr SBUF0 = 0x99;
sfr P2MDOUT = 0xA6;
sfr CLKSEL = 0xA9;
sfr OSCICN = 0xB2;
sfr FLSCL = 0xB6;
sfr IP = 0xB8;
sfr CLKMUL = 0xB9;
sfr P0SKIP = 0xD4;
sfr P1SKIP = 0xD5;
sfr P2SKIP = 0xD6;
sfr PCA0MD = 0xD9;
sfr XBR0 = 0xE1;
sfr XBR1 = 0xE2;
sfr XBR2 = 0xE3;
sbit ES0 = 0xAC;
sbit ET1 = 0xAB;
sfr TMOD = 0x89;
sfr TL1 = 0x8B;
sfr TH1 = 0x8D;
sfr CKCON = 0x8E;
sfr SCON = 0x98;
sbit TF1 = 0x8F;
sbit TR1 = 0x8E;
sbit TF0 = 0x8D;
sbit EA = 0xAF;
sbit P2_2 = 0xA2;
sbit P2_3 = 0xA3;
#endif

uint8_t SchedulerBasicP__m_head  ;
uint8_t SchedulerBasicP__m_tail  ;
uint8_t SchedulerBasicP__m_next[1]  ;
char EchoP__buf  =    (char)68;

int main(void) 
{ __nesc_atomic_t _cil_inline_tmp_264 ;
  uint16_t _cil_inline_tmp_268 ;
  unsigned char _cil_inline_tmp_276 ;
  uint8_t _cil_inline_tmp_285 ;
  unsigned char _cil_inline_tmp_295 ;
  uint8_t _cil_inline_tmp_298 ;
  __nesc_atomic_t _cil_inline_tmp_306 ;
  uint8_t _cil_inline_tmp_307 ;
  uint8_t _cil_inline_tmp_308 ;
  uint8_t _cil_inline_tmp_309 ;
  uint8_t _cil_inline_tmp_313 ;

  {
  _cil_inline_tmp_264 = (__nesc_atomic_t )EA;
  EA = (unsigned char)0;
  memset((void *)(SchedulerBasicP__m_next), (char)-1, 1);
  SchedulerBasicP__m_head = (unsigned char)255;
  SchedulerBasicP__m_tail = (unsigned char)255;
  PCA0MD = (unsigned char )((int volatile   )PCA0MD & -65);
  OSCICN = (unsigned char)131;
  CLKMUL = (unsigned char)0;
  CLKMUL = (unsigned char )((int volatile   )CLKMUL | 128);
  _cil_inline_tmp_268 = (unsigned short)0;
  while ((int )_cil_inline_tmp_268 < 500) {
    _cil_inline_tmp_268 = (uint16_t )((int )_cil_inline_tmp_268 + 1);
  }
  CLKMUL = (unsigned char )((int volatile   )CLKMUL | 64);
  _cil_inline_tmp_268 = (unsigned short)0;
  while ((int )_cil_inline_tmp_268 < 500) {
    _cil_inline_tmp_268 = (uint16_t )((int )_cil_inline_tmp_268 + 1);
  }
  while (! ((int volatile   )CLKMUL & 32)) {

  }
  FLSCL = (unsigned char )((int volatile   )FLSCL | 16);
  CLKSEL = (unsigned char)3;
  P2MDOUT = (unsigned char )((int volatile   )P2MDOUT | 4);
  P2MDOUT = (unsigned char )((int volatile   )P2MDOUT | 8);
  P2_2 = (unsigned char)0;
  P2_3 = (unsigned char)0;
  P0SKIP = (unsigned char)192;
  P1SKIP = (unsigned char)3;
  P2SKIP = (unsigned char)4;
  XBR0 = (unsigned char)7;
  XBR1 = (unsigned char)64;
  EA = (unsigned char)1;
  while (1) {
    _cil_inline_tmp_276 = SchedulerBasicP__Scheduler__runNextTask();
    if (! _cil_inline_tmp_276) {
      break;
    }
  }
  XBR0 = (unsigned char )((int volatile   )XBR0 | 1);
  XBR2 = (unsigned char )((int volatile   )XBR2 | 1);
  XBR1 = (unsigned char )((int volatile   )XBR1 | 64);
  if (((48000000UL / ((unsigned long )((ser_rate_t )3072) * 75UL)) / 2UL) / 256UL < 1UL) {
    _cil_inline_tmp_285 = (unsigned char )(- ((48000000UL / ((unsigned long )((ser_rate_t )3072) * 75UL)) / 2UL));
    CKCON = (unsigned char )((int volatile   )CKCON & -12);
    CKCON = (unsigned char )((int volatile   )CKCON | 8);
  } else {
    if (((48000000UL / ((unsigned long )((ser_rate_t )3072) * 75UL)) / 2UL) / 256UL < 4UL) {
      _cil_inline_tmp_285 = (unsigned char )(- (((48000000UL / ((unsigned long )((ser_rate_t )3072) * 75UL)) / 2UL) / 4UL));
      CKCON = (unsigned char )((int volatile   )CKCON & -12);
      CKCON = (unsigned char )((int volatile   )CKCON | 9);
    } else {
      if (((48000000UL / ((unsigned long )((ser_rate_t )3072) * 75UL)) / 2UL) / 256UL < 12UL) {
        _cil_inline_tmp_285 = (unsigned char )(- (((48000000UL / ((unsigned long )((ser_rate_t )3072) * 75UL)) / 2UL) / 12UL));
        CKCON = (unsigned char )((int volatile   )CKCON & -12);
      } else {
        _cil_inline_tmp_285 = (unsigned char )(- (((48000000UL / ((unsigned long )((ser_rate_t )3072) * 75UL)) / 2UL) / 48UL));
        CKCON = (unsigned char )((int volatile   )CKCON & -12);
        CKCON = (unsigned char )((int volatile   )CKCON | 2);
      }
    }
  }
  TL1 = _cil_inline_tmp_285;
  TH1 = _cil_inline_tmp_285;
  SCON0 = (unsigned char)16;
  IP = (unsigned char )((int volatile   )IP | 16);
  TMOD = (unsigned char )(((int volatile   )TMOD & -4) | (int volatile   )((int )((mcs51_timer_mode_t )2) << 4));
  TR1 = (unsigned char)1;
  ET1 = (unsigned char)0;
  ES0 = (unsigned char)1;
  while (1) {
    _cil_inline_tmp_295 = SchedulerBasicP__Scheduler__runNextTask();
    if (! _cil_inline_tmp_295) {
      break;
    }
  }
  EA = _cil_inline_tmp_264;
  EA = (unsigned char)1;
  P2_2 = (unsigned char)1;
  _cil_inline_tmp_298 = (unsigned char )EchoP__buf;
  SBUF0 = 'Q';//_cil_inline_tmp_298;
  while (1) {
    _cil_inline_tmp_306 = (__nesc_atomic_t )EA;
    EA = (unsigned char)0;
    while (1) {
      if ((int )SchedulerBasicP__m_head != 255) {
        _cil_inline_tmp_308 = SchedulerBasicP__m_head;
        SchedulerBasicP__m_head = SchedulerBasicP__m_next[SchedulerBasicP__m_head];
        if ((int )SchedulerBasicP__m_head == 255) {
          SchedulerBasicP__m_tail = (unsigned char)255;
        }
        SchedulerBasicP__m_next[_cil_inline_tmp_308] = (unsigned char)255;
        _cil_inline_tmp_307 = _cil_inline_tmp_308;
      } else {
        _cil_inline_tmp_307 = (unsigned char)255;
      }
      if (! ((int )_cil_inline_tmp_307 == 255)) {
        break;
      }
      EA = (unsigned char)1;
      _cil_inline_tmp_309 = (unsigned char)0;
      while ((int )_cil_inline_tmp_309 < 10) {
        _cil_inline_tmp_309 = (uint8_t )((int )_cil_inline_tmp_309 + 1);
      }
      EA = (unsigned char)0;
    }
    EA = _cil_inline_tmp_306;
    switch ((int )_cil_inline_tmp_307) {
    case 0: ;
      _cil_inline_tmp_313 = (unsigned char )EchoP__buf;
      //_cil_inline_tmp_313 = SBUF0;
    SBUF0 = _cil_inline_tmp_313;
    break;
    }
  }
  return (-1);
}
}
static bool SchedulerBasicP__Scheduler__runNextTask(void) 
{ uint8_t _cil_inline_tmp_318 ;
  uint8_t _cil_inline_tmp_319 ;
  uint8_t _cil_inline_tmp_322 ;

  {
  if ((int )SchedulerBasicP__m_head != 255) {
    _cil_inline_tmp_319 = SchedulerBasicP__m_head;
    SchedulerBasicP__m_head = SchedulerBasicP__m_next[SchedulerBasicP__m_head];
    if ((int )SchedulerBasicP__m_head == 255) {
      SchedulerBasicP__m_tail = (unsigned char)255;
    }
    SchedulerBasicP__m_next[_cil_inline_tmp_319] = (unsigned char)255;
    _cil_inline_tmp_318 = _cil_inline_tmp_319;
  } else {
    _cil_inline_tmp_318 = (unsigned char)255;
  }
  if ((int )_cil_inline_tmp_318 == 255) {
    return ((unsigned char)0);
  }
  switch ((int )_cil_inline_tmp_318) {
  case 0: ;
  _cil_inline_tmp_322 = (unsigned char )EchoP__buf;
  SBUF0 = 'W';//_cil_inline_tmp_322;
  break;
  }
  return ((unsigned char)1);
}
}
void /*__attribute__((__interrupt__))  __vector_4(void)  __attribute__((__interrupt__))*/ ;

#ifdef SDCC
void __vector_4(void) __interrupt (4)
#else
void __vector_4(void) interrupt 4
#endif
{ uint8_t rx ;
  __nesc_atomic_t _cil_inline_tmp_328 ;
  uint8_t _cil_inline_tmp_330 ;
  __nesc_atomic_t _cil_inline_tmp_335 ;
  __nesc_atomic_t _cil_inline_tmp_340 ;
  __nesc_atomic_t _cil_inline_tmp_345 ;
  __nesc_atomic_t _cil_inline_tmp_351 ;
  __nesc_atomic_t _cil_inline_tmp_357 ;
  int _cil_inline_tmp_363 ;
  __nesc_atomic_t _cil_inline_tmp_365 ;

  {
  rx = (unsigned char)0;
  _cil_inline_tmp_328 = (__nesc_atomic_t )EA;
  EA = (unsigned char)0;
  if ((int volatile   )SCON & 2) {
    SCON = (unsigned char )((int volatile   )SCON & -3);
  }
  if ((int volatile   )SCON & 1) {
    SCON = (unsigned char )((int volatile   )SCON & -2);
    rx = (unsigned char)1;
  }
  EA = _cil_inline_tmp_328;
  if ((int )rx == 1) {
    _cil_inline_tmp_330 = SBUF0;
    EchoP__buf = (char )_cil_inline_tmp_330;
    _cil_inline_tmp_335 = (__nesc_atomic_t )EA;
    EA = (unsigned char)0;
    P2_2 = (unsigned char )(~ ((int volatile   )P2_2));
    EA = _cil_inline_tmp_335;
    _cil_inline_tmp_340 = (__nesc_atomic_t )EA;
    EA = (unsigned char)0;
    P2_3 = (unsigned char )(~ ((int volatile   )P2_3));
    EA = _cil_inline_tmp_340;
    _cil_inline_tmp_345 = (__nesc_atomic_t )EA;
    EA = (unsigned char)0;
    EA = _cil_inline_tmp_345;
    _cil_inline_tmp_357 = (__nesc_atomic_t )EA;
    EA = (unsigned char)0;
    _cil_inline_tmp_351 = _cil_inline_tmp_357;
    if ((int )SchedulerBasicP__m_next[(unsigned char)0] != 255) {
      _cil_inline_tmp_363 = 1;
    } else {
      if ((int )SchedulerBasicP__m_tail == 0) {
        _cil_inline_tmp_363 = 1;
      } else {
        _cil_inline_tmp_363 = 0;
      }
    }
    if (! ((unsigned char )_cil_inline_tmp_363)) {
      if ((int )SchedulerBasicP__m_head == 255) {
        SchedulerBasicP__m_head = (unsigned char)0;
        SchedulerBasicP__m_tail = (unsigned char)0;
      } else {
        SchedulerBasicP__m_next[SchedulerBasicP__m_tail] = (unsigned char)0;
        SchedulerBasicP__m_tail = (unsigned char)0;
      }
    }
    EA = _cil_inline_tmp_357;
    goto __inlineSchedulerBasicP__TaskBasic__postTask_338_473_508_639;
    _cil_inline_tmp_365 = _cil_inline_tmp_351;
    EA = _cil_inline_tmp_365;
    __inlineSchedulerBasicP__TaskBasic__postTask_338_473_508_639: ;
  }
  return;
}
}
void /*__attribute__((__interrupt__))  __vector_1(void)  __attribute__((__interrupt__))*/ ;
#ifdef SDCC
void __vector_1(void) __interrupt (1)
#else
void __vector_1(void) interrupt 1
#endif
{ 

  {
  TF0 = (unsigned char)0;
  return;
}
}
void /*__attribute__((__interrupt__))  __vector_3(void)  __attribute__((__interrupt__))*/ ;

#ifdef SDCC
void __vector_3(void) __interrupt (3)
#else
void __vector_3(void) interrupt 3
#endif
{ 

  {
  TF1 = (unsigned char)0;
  return;
}
}
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to