#include <stdio.h>
#include <string.h>
#include <ctype.h>
-#include "SDCCglobl.h"
-#include "SDCCsymt.h"
-#include "SDCCval.h"
-#include "SDCCast.h"
-#include "SDCCy.h"
-#include "SDCChasht.h"
-#include "SDCCmem.h"
+#include "common.h"
char *stringLiteral();
char *currFname;
{
return(1);
}
-
+#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
+ check_type(yytext))
char asmbuff[MAX_INLINEASM] ;
char *asmp ;
-extern int check_type ( );
+extern int check_type ();
+ extern int isTargetKeyword ();
extern int checkCurrFile (char *);
extern int processPragma (char *);
extern int printListing (int );
<asm>. { *asmp++ = yytext[0] ; }
<asm>\n { count(); *asmp++ = '\n' ;}
"/*" { comment(); }
-"at" { count(); return(AT) ; }
-"auto" { count(); return(AUTO); }
-"bit" { count(); return(BIT) ; }
-"break" { count(); return(BREAK); }
-"case" { count(); return(CASE); }
+"at" { count(); TKEYWORD(AT) ; }
+"auto" { count(); return(AUTO); }
+"bit" { count(); TKEYWORD(BIT) ; }
+"break" { count(); return(BREAK); }
+"case" { count(); return(CASE); }
"char" { count(); return(CHAR); }
-"code" { count(); return(CODE); }
+"code" { count(); TKEYWORD(CODE); }
"const" { count(); return(CONST); }
"continue" { count(); return(CONTINUE); }
-"critical" { count(); return(CRITICAL); }
-"data" { count(); return(DATA); }
+"critical" { count(); TKEYWORD(CRITICAL); }
+"data" { count(); TKEYWORD(DATA); }
"default" { count(); return(DEFAULT); }
"do" { count(); return(DO); }
"double" { count(); werror(W_DOUBLE_UNSUPPORTED);return(FLOAT); }
"else" { count(); return(ELSE); }
"enum" { count(); return(ENUM); }
"extern" { count(); return(EXTERN); }
-"far" { count(); return(XDATA); }
+"far" { count(); TKEYWORD(XDATA); }
"float" { count(); return(FLOAT); }
"for" { count(); return(FOR); }
"goto" { count(); return(GOTO); }
-"idata" { count(); return(IDATA);}
+"idata" { count(); TKEYWORD(IDATA);}
"if" { count(); return(IF); }
"int" { count(); return(INT); }
"interrupt" { count(); return(INTERRUPT);}
"long" { count(); return(LONG); }
-"near" { count(); return(DATA);}
+"near" { count(); TKEYWORD(DATA);}
"pdata" { count(); return(PDATA); }
-"reentrant" { count(); return(REENTRANT);}
+"reentrant" { count(); TKEYWORD(REENTRANT);}
"register" { count(); return(REGISTER); }
"return" { count(); return(RETURN); }
-"sfr" { count(); return(SFR) ; }
-"sbit" { count(); return(SBIT) ; }
+"sfr" { count(); TKEYWORD(SFR) ; }
+"sbit" { count(); TKEYWORD(SBIT) ; }
"short" { count(); return(SHORT); }
"signed" { count(); return(SIGNED); }
"sizeof" { count(); return(SIZEOF); }
"unsigned" { count(); return(UNSIGNED); }
"void" { count(); return(VOID); }
"volatile" { count(); return(VOLATILE); }
-"using" { count(); return(USING); }
+"using" { count(); TKEYWORD(USING); }
"while" { count(); return(WHILE); }
-"xdata" { count(); return(XDATA); }
-"_data" { count(); return(_NEAR); }
-"_code" { count(); return(_CODE); }
-"_generic" { count(); return(_GENERIC); }
-"_near" { count(); return(_NEAR); }
-"_xdata" { count(); return(_XDATA);}
-"_pdata" { count () ; return(_PDATA); }
-"_idata" { count () ; return(_IDATA); }
-"..." { count(); return(VAR_ARGS);}
+"xdata" { count(); TKEYWORD(XDATA); }
+"_data" { count(); TKEYWORD(_NEAR); }
+"_code" { count(); TKEYWORD(_CODE); }
+"_generic" { count(); TKEYWORD(_GENERIC); }
+"_near" { count(); TKEYWORD(_NEAR); }
+"_xdata" { count(); TKEYWORD(_XDATA);}
+"_pdata" { count(); TKEYWORD(_PDATA); }
+"_idata" { count(); TKEYWORD(_IDATA); }
+"..." { count(); return(VAR_ARGS);}
{L}({L}|{D})* { count(); return(check_type()); }
0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
0{D}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
"==" { count(); return(EQ_OP); }
"!=" { count(); return(NE_OP); }
";" { count(); return(';'); }
-"{" { count() ; NestLevel++ ; return('{'); }
-"}" { count(); NestLevel--; return('}'); }
+"{" { count(); NestLevel++ ; return('{'); }
+"}" { count(); NestLevel--; return('}'); }
"," { count(); return(','); }
":" { count(); return(':'); }
"=" { count(); return('='); }
werror(W_UNKNOWN_PRAGMA,cp);
return 0;
}
+
+/* will return 1 if the string is a part
+ of a target specific keyword */
+int isTargetKeyword(char *s)
+{
+ int i;
+
+ if (port->keywords == NULL)
+ return 0;
+ for ( i = 0 ; port->keywords[i] ; i++ ) {
+ if (strcmp(port->keywords[i],s) == 0)
+ return 1;
+ }
+
+ return 0;
+}
/* change not */
if (IS_NOT(tree)) {
- tree->left = backPatchLabels (tree->left,trueLabel,falseLabel);
+ tree->left = backPatchLabels (tree->left,falseLabel,trueLabel);
/* if the left is already a IFX */
if ( ! IS_IFX(tree->left) )
deleteGetPointers(&cseSet,&ptrSetSet,IC_LEFT(ic),ebb);
ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,IC_LEFT(ic)->key);
for (i = 0 ; i < count ;ebbs[i++]->visited = 0);
- applyToSet(ebb->succList,delGetPointerSucc,IC_LEFT(ic),ebb->dfnum);
+ applyToSet(ebb->succList,delGetPointerSucc,
+ IC_LEFT(ic),ebb->dfnum);
}
continue;
}
algebraicOpts (ic);
while (constFold(ic,cseSet));
+ /* small klugde */
+ if (POINTER_GET(ic) && !IS_PTR(operandType(IC_LEFT(ic)))) {
+ setOperandType(IC_LEFT(ic),
+ aggrToPtr(operandType(IC_LEFT(ic)),FALSE));
+ }
+ if (POINTER_SET(ic) && !IS_PTR(operandType(IC_RESULT(ic)))) {
+ setOperandType(IC_RESULT(ic),
+ aggrToPtr(operandType(IC_RESULT(ic)),FALSE));
+ }
+
/* if this is a condition statment then */
/* check if the condition can be replaced */
if (ic->op == IFX ) {
for the same pointer visible if yes
then change this into an assignment */
pdop = NULL;
- if (applyToSetFTrue(cseSet,findPointerSet,IC_LEFT(ic),&pdop)){
+ if (applyToSetFTrue(cseSet,findPointerSet,IC_LEFT(ic),&pdop) &&
+ !bitVectBitValue(ebb->ptrsSet,pdop->key)){
ic->op = '=';
IC_LEFT(ic) = NULL;
IC_RIGHT(ic) = pdop;
asmArgs[0] = port->assembler.exec_name;
-/* if (options.debug) */
asmArgs[1] = port->assembler.debug_opts;
-/* else */
-/* asmArgs[1] = port->assembler.plain_opts; */
/* add the extra options if any */
for (; asmOptions[i-2] ; i++)
int fatalError = 0 ;/* fatal error flag */
/*-----------------------------------------------------------------*/
-/* allocMap - allocates a memory map */
+/* allocMap - allocates a memory map */
/*-----------------------------------------------------------------*/
memmap *allocMap (char rspace, /* sfr space */
char farmap, /* far or near segment */
ljmp %5
%2:
} by {
- ; Peephole 112 removed ljmp by inverse jump logic
+ ; Peephole 112 removed ljmp by inverse jump logic
jb %1,%5
%2:
} if labelInRange
+replace {
+ ljmp %5
+%1:
+} by {
+ ; Peephole 132 changed ljmp to sjmp
+ sjmp %5
+%1:
+} if labelInRange
+
+
replace {
clr a
cjne %1,%2,%3
mov %2,%1
}
-replace {
- ljmp %5
-%1:
-} by {
- ; Peephole 132 changed ljmp to sjmp
- sjmp %5
-%1:
-} if labelInRange
-
replace {
mov r%1,%2
mov ar%3,@r%1
} by {
; Peephole 164 removed sjmp by inverse jump logic
jb %3,%2
-%1:}
+%1:
+}
replace {
jb %3,%1
} by {
; Peephole 165 removed sjmp by inverse jump logic
jnb %3,%2
-%1:}
+%1:
+}
replace {
mov %1,%2
mov @r%1,a
inc r%1
mov @r%1,a
-}
+}
\ No newline at end of file
" ljmp %5\n"
"%2:\n"
"} by {\n"
-" ; Peephole 112 removed ljmp by inverse jump logic\n"
+" ; Peephole 112 removed ljmp by inverse jump logic\n"
" jb %1,%5\n"
"%2:\n"
"} if labelInRange\n"
"\n"
"replace {\n"
+" ljmp %5\n"
+"%1:\n"
+"} by {\n"
+" ; Peephole 132 changed ljmp to sjmp\n"
+" sjmp %5\n"
+"%1:\n"
+"} if labelInRange\n"
+"\n"
+"\n"
+"replace {\n"
" clr a\n"
" cjne %1,%2,%3\n"
" cpl a\n"
"}\n"
"\n"
"replace {\n"
-" ljmp %5\n"
-"%1:\n"
-"} by {\n"
-" ; Peephole 132 changed ljmp to sjmp\n"
-" sjmp %5\n"
-"%1:\n"
-"} if labelInRange\n"
-"\n"
-"replace {\n"
" mov r%1,%2\n"
" mov ar%3,@r%1\n"
" inc r%3\n"
"} by {\n"
" ; Peephole 164 removed sjmp by inverse jump logic\n"
" jb %3,%2\n"
-"%1:}\n"
+"%1:\n"
+"}\n"
"\n"
"replace {\n"
" jb %3,%1\n"
"} by {\n"
" ; Peephole 165 removed sjmp by inverse jump logic\n"
" jnb %3,%2\n"
-"%1:}\n"
+"%1:\n"
+"}\n"
"\n"
"replace {\n"
" mov %1,%2\n"
// c = bit ^ val
// if val>>1 != 0, result = 1
emitcode("setb","c");
- while(sizer--){
+ while(sizer){
MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE));
if(sizer == 1)
// test the msb of the lsb
emitcode("anl","a,#0xfe");
emitcode("jnz","%05d$",tlbl->key+100);
+ sizer--;
}
// val = (0,1)
emitcode("rrc","a");
#include "main.h"
#include "ralloc.h"
+/* list of key words used by msc51 */
+static char *_mcs51_keywords[] = {
+ "at",
+ "bit",
+ "code",
+ "critical",
+ "data",
+ "far",
+ "idata",
+ "interrupt",
+ "near",
+ "pdata",
+ "reentrant",
+ "sfr",
+ "sbit",
+ "using",
+ "xdata",
+ "_data",
+ "_code",
+ "_generic",
+ "_near",
+ "_xdata",
+ "_pdata",
+ "_idata",
+ NULL
+};
+
void mcs51_assignRegisters (eBBlock **ebbs, int count);
_mcs51_finaliseOptions,
_mcs51_setDefaultOptions,
mcs51_assignRegisters,
- _mcs51_getRegName
+ _mcs51_getRegName ,
+ _mcs51_keywords
+
};
operation is a '*','/' or '%' then 'b' may
cause a problem */
if (( dic->op == '%' || dic->op == '/' || dic->op == '*') &&
- getSize(aggrToPtr(operandType(op),FALSE)) >= 3)
+ getSize(operandType(op)) >= 3)
return NULL;
/* if left or right or result is in far space */
typedef struct {
/** Target name used for -m */
const char *target;
+
/** Target name string, used for --help */
const char *target_name;
+
+ /* assembler related information */
struct {
/** Command to run (eg as-z80) */
const char *exec_name;
/** TRUE if the output file name should be pre-pended to the args */
bool requires_output_name;
} assembler;
+
+ /* linker related info */
struct {
/** Command to run (eg link-z80) */
const char *exec_name;
} linker;
+
/** Basic type sizes */
struct {
int char_size;
int float_size;
int max_base_size;
} s;
+
/** Names for all the memory regions */
struct {
const char *xstack_name;
const char *static_name;
const char *overlay_name;
} mem;
+
+ /* stack related information */
struct {
/** -1 for grows down (z80), +1 for grows up (mcs51) */
int direction;
} stack;
struct {
- /** One more than the smallest mul/div operation the processor can do nativley
+ /** One more than the smallest
+ mul/div operation the processor can do nativley
Eg if the processor has an 8 bit mul, nativebelow is 2 */
int nativebelow;
} muldiv;
+
/** Parses one option + its arguments */
bool (*parseOption)(int *pargc, char **argv);
/** Called after all the options have been parsed. */
void (*setDefaultOptions)(void);
/** Does the dirty work. */
void (*assignRegisters)(eBBlock **, int);
+
/** Returns the register name of a symbol.
Used so that 'regs' can be an incomplete type. */
const char *(*getRegName)(struct regs *reg);
+
+ /* list of keywords that are used by this
+ target (used by lexer) */
+ char **keywords;
} PORT;
extern PORT *port;
#include "common.h"
#include "ralloc.h"
+static char *_z80_keywords[] = { NULL };
+
void z80_assignRegisters (eBBlock **ebbs, int count);
static bool _z80_parseOptions(int *pargc, char **argv)
_z80_finaliseOptions,
_z80_setDefaultOptions,
z80_assignRegisters,
- _z80_getRegName
+ _z80_getRegName,
+ _z80_keywords
};