next up previous contents index
Next: 3.20 Defines Created by Up: 3. Using SDCC Previous: 3.18.2 DS390 Memory Model   Contents   Index


3.19 Pragmas

Pragmas are used to turn on and/or off certain compiler options. Some of them are closely related to corresponding command-line options (see section sec:Command-Line-Options).
Pragmas should be placed before and/or after a function, placing pragmas inside a function body could have unpredictable results.

SDCC supports the following #pragma directives:

The preprocessor SDCPP supports the following #pragma directives:
#pragma pedantic_parse_number + 
 
#define LO_B(x) ((x) & 0xff) 
 
unsigned char foo(void) 
{ 
   unsigned char c=0xfe-LO_B(3); 
 
   return c; 
} 
#pragma preproc_asm - 
/* this is a c code nop */ 
#define NOP ; 
 
void foo (void) 
{ 
   ... 
   while (-i) 
      NOP 
   ... 
   __asm 
   ; this is an assembler nop instruction 
   ; it is not preprocessed to ';' since the asm preprocessing is disabled 
   NOP 
   __endasm; 
   ... 
} 

The pragma preproc_asm should not be used to define multilines of assembly code (even if it supports it), since this behavior is only a side effect of sdcpp __asm __endasm implementation in combination with pragma preproc_asm and is not in conformance with the C standard. This behavior might be changed in the future sdcpp versions. To define multilines of assembly code you have to include each assembly line into it's own __asm __endasm block. Below is an example for multiline assembly defines.

#define Nop __asm \ 
nop \ 
__endasm 
 
#define ThreeNops Nop; \ 
Nop; \ 
Nop 
 
void foo (void) 
{  
   ...  
   ThreeNops; 
   ...  
}  
#pragma preproc_asm + 
#pragma sdcc_hash + 
 
#define ROMCALL(x) \ 
   mov R6_B3, #(x & 0xff) \ 
   mov R7_B3, #((x >> 8) & 0xff) \ 
   lcall __romcall 
 
... 
__asm 
ROMCALL(72) 
__endasm; 
... 

Some of the pragmas are intended to be used to turn-on or off certain optimizations which might cause the compiler to generate extra stack and/or data space to store compiler generated temporary variables. This usually happens in large functions. Pragma directives should be used as shown in the following example, they are used to control options and optimizations for a given function.

#pragma save       /* save the current settings */  
#pragma nogcse     /* turnoff global subexpression elimination */  
#pragma noinduction /* turn off induction optimizations */  
int foo ()  
{  
   ...  
   /* large code */  
   ...  
}  
#pragma restore /* turn the optimizations back on */
The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the save and restore pragmas be used when changing options for a function.



next up previous contents index
Next: 3.20 Defines Created by Up: 3. Using SDCC Previous: 3.18.2 DS390 Memory Model   Contents   Index
2011-03-20