From 55250da7ff51808e9785e3eff75748ee47cc98d1 Mon Sep 17 00:00:00 2001 From: tecodev Date: Mon, 19 Jun 2006 16:50:14 +0000 Subject: [PATCH] * src/pic/glue.h: added pic14aopLiteral prototype * src/pic/glue.c (pic14aopLiteral): return unsigned int * src/pic/gen.c: removed stdint.h dependency (aopGet): use Safe_strdup() (bitpatternFromVal): removed, replaced use with pic14aopLiteral (genDataPointerSet): use pic14aopLiteral() * src/pic16/glue.h, src/pic16/glue.c, src/pic16/gen.c: similar changes for pic16; thanks to Bernhard and Maarten git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4242 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 11 +++++++++ src/pic/gen.c | 58 +++++++----------------------------------------- src/pic/glue.c | 2 +- src/pic/glue.h | 1 + src/pic16/gen.c | 34 +++++++++------------------- src/pic16/glue.c | 2 +- src/pic16/glue.h | 1 + 7 files changed, 33 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 56e43f8a..71f9f688 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-06-19 Raphael Neider + + * src/pic/glue.h: added pic14aopLiteral prototype + * src/pic/glue.c (pic14aopLiteral): return unsigned int + * src/pic/gen.c: removed stdint.h dependency + (aopGet): use Safe_strdup() + (bitpatternFromVal): removed, replaced use with pic14aopLiteral + (genDataPointerSet): use pic14aopLiteral() + * src/pic16/glue.h, src/pic16/glue.c, src/pic16/gen.c: similar changes + for pic16; thanks to Bernhard and Maarten + 2006-06-18 Borut Razem * support/regression/tests/structflexarray.c: flexible array members diff --git a/src/pic/gen.c b/src/pic/gen.c index 169fc0f3..931f82d3 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -34,13 +34,6 @@ #include #include #include -#ifndef __sun__ -#if defined(_MSC_VER) - #include "pstdint.h" -#else - #include -#endif -#endif #include "SDCCglobl.h" #include "newalloc.h" @@ -49,6 +42,7 @@ #include "ralloc.h" #include "pcode.h" #include "gen.h" +#include "glue.h" /* When changing these, you must also update the assembler template * in device/lib/libsdcc/macros.inc */ @@ -78,7 +72,6 @@ static int GpsuedoStkPtr=0; pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func); extern char *get_op( pCodeOp *pcop,char *buff,size_t buf_size); -unsigned int pic14aopLiteral (value *val, int offset); const char *AopType(short type); #define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0x00ff) @@ -1216,9 +1209,8 @@ char *aopGet (asmop *aop, int offset, bool bit16, bool dname) return "AOP_accumulator_bug"; case AOP_LIT: - sprintf(s,"0x%02x", pic14aopLiteral (aop->aopu.aop_lit,offset)); - rs = Safe_calloc(1,strlen(s)+1); - strcpy(rs,s); + sprintf(s, "0x%02x", pic14aopLiteral (aop->aopu.aop_lit, offset)); + rs = Safe_strdup(s); return rs; case AOP_STR: @@ -9363,38 +9355,6 @@ static void genPackBits(sym_link *etype,operand *result,operand *right,int p_typ assert( !"bitfields larger than 8 bits or crossing byte boundaries are not yet supported" ); } -unsigned long -bitpatternFromVal (value *val) -{ - union { - float d; - uint32_t l; - } float_long; - - assert (sizeof (float) == sizeof (uint32_t)); - - //fprintf (stderr, "%s:%u(%s): val=%lf, type: %d, etype: %d\n", __FILE__, __LINE__, __FUNCTION__, floatFromVal(val), SPEC_NOUN(val->type), SPEC_NOUN(val->etype)); - - switch (SPEC_NOUN(val->type)) - { - case V_INT: - case V_CHAR: - return (unsigned long)floatFromVal (val); - - case V_FLOAT: - case V_DOUBLE: - float_long.d = floatFromVal (val); - return float_long.l; - - default: - assert( !"unhandled value type" ); - break; - } - - float_long.d = floatFromVal (val); - return float_long.l; -} - /*-----------------------------------------------------------------*/ /* genDataPointerSet - remat pointer to data space */ /*-----------------------------------------------------------------*/ @@ -9433,20 +9393,18 @@ static void genDataPointerSet(operand *right, emitpComment ("%s:%u: size=%d/%d, offset=%i", __FILE__,__LINE__, size, ressize, offset); if (AOP_TYPE(right) == AOP_LIT) { - /* XXX: might be float... */ - unsigned int lit = bitpatternFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit); - lit = lit >> (8*offset); + unsigned int lit = pic14aopLiteral(AOP(IC_RIGHT(ic))->aopu.aop_lit, offset); //fprintf (stderr, "%s:%u: lit %d 0x%x\n", __FUNCTION__,__LINE__, lit, lit); if(lit&0xff) { emitpcode(POC_MOVLW, popGetLit(lit&0xff)); - emitpcode(POC_MOVWF, popGet(AOP(result),offset)); + emitpcode(POC_MOVWF, popGet(AOP(result), offset)); } else { - emitpcode(POC_CLRF, popGet(AOP(result),offset)); + emitpcode(POC_CLRF, popGet(AOP(result), offset)); } } else { //fprintf (stderr, "%s:%u: no lit\n", __FUNCTION__,__LINE__); - emitpcode(POC_MOVFW, popGet(AOP(right),offset)); - emitpcode(POC_MOVWF, popGet(AOP(result),offset)); + emitpcode(POC_MOVFW, popGet(AOP(right), offset)); + emitpcode(POC_MOVWF, popGet(AOP(result), offset)); } offset++; diff --git a/src/pic/glue.c b/src/pic/glue.c index 11a8664d..f8f4a24c 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -81,7 +81,7 @@ int pic14_hasInterrupt = 0; // Indicates whether to emit interrupt handler or n /*-----------------------------------------------------------------*/ /* aopLiteral - string from a literal value */ /*-----------------------------------------------------------------*/ -int pic14aopLiteral (value *val, int offset) +unsigned int pic14aopLiteral (value *val, int offset) { union { float f; diff --git a/src/pic/glue.h b/src/pic/glue.h index ce542431..b5b285df 100644 --- a/src/pic/glue.h +++ b/src/pic/glue.h @@ -26,5 +26,6 @@ #define PIC_GLUE_H void picglue (void); +unsigned int pic14aopLiteral (value *val, int offset); #endif diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 74da6f0e..898f4730 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -47,6 +47,7 @@ #include "genutils.h" #include "device.h" #include "main.h" +#include "glue.h" /* Set the following to 1 to enable the slower/bigger * but more robust generic shifting routine (which also @@ -112,7 +113,6 @@ static int GpsuedoStkPtr=0; pCodeOp *pic16_popGetImmd(char *name, unsigned int offset, int index); -unsigned int pic16aopLiteral (value *val, int offset); const char *pic16_AopType(short type); static iCode *ifxForOp ( operand *op, iCode *ic ); @@ -11895,29 +11895,15 @@ static void genDataPointerSet(operand *right, while (size--) { if (AOP_TYPE(right) == AOP_LIT) { - unsigned int lit; - - if(!IS_FLOAT(operandType( right ))) - lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit); - else { - union { - unsigned long lit_int; - float lit_float; - } info; - - /* take care if literal is a float */ - info.lit_float = floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit); - lit = info.lit_int; - } - lit = lit >> (8*offset); - pic16_movLit2f(pic16_popGet(AOP(result),offset), lit); - } else { - pic16_mov2w(AOP(right), offset); - pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); // patch 8 - } - offset++; - resoffset++; - } + unsigned int lit = pic16aopLiteral(AOP(IC_RIGHT(ic))->aopu.aop_lit, offset); + pic16_movLit2f(pic16_popGet(AOP(result), offset), lit); + } else { + pic16_mov2w(AOP(right), offset); + pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), offset)); // patch 8 + } + offset++; + resoffset++; + } pic16_freeAsmop(right,NULL,ic,TRUE); } diff --git a/src/pic16/glue.c b/src/pic16/glue.c index 43e01599..107c2e94 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -79,7 +79,7 @@ extern void pic16_pCodeConstString(char *name, char *value); /*-----------------------------------------------------------------*/ /* aopLiteral - string from a literal value */ /*-----------------------------------------------------------------*/ -int pic16aopLiteral (value *val, int offset) +unsigned int pic16aopLiteral (value *val, int offset) { union { float f; diff --git a/src/pic16/glue.h b/src/pic16/glue.h index 7df7587c..2fc4da55 100644 --- a/src/pic16/glue.h +++ b/src/pic16/glue.h @@ -26,5 +26,6 @@ #define PIC16_GLUE_H void pic16glue (void); +unsigned int pic16aopLiteral (value *val, int offset); #endif -- 2.30.2