* src/pic/glue.h: added pic14aopLiteral prototype
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Jun 2006 16:50:14 +0000 (16:50 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Jun 2006 16:50:14 +0000 (16:50 +0000)
* 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
src/pic/gen.c
src/pic/glue.c
src/pic/glue.h
src/pic16/gen.c
src/pic16/glue.c
src/pic16/glue.h

index 56e43f8a58cb57d427be0e73e59a926e417c63ab..71f9f688fa191868eabe825ad5b9cef9c55a055e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-06-19 Raphael Neider <rneider AT web.de>
+
+       * 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 <borut.razem AT siol.net>
 
        * support/regression/tests/structflexarray.c: flexible array members
index 169fc0f3d620bc2bdb6b5aab1db0acde3dc40e94..931f82d364af143c72046511004cb05caf370fa4 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#ifndef __sun__
-#if defined(_MSC_VER)
-       #include "pstdint.h"
-#else
-       #include <stdint.h>
-#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++;
index 11a8664dd654fb13c13c80505c085cc7da64ee76..f8f4a24cce6ebe1e4ebac487ccf7225a464d0a30 100644 (file)
@@ -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;
index ce5424317b6dc915b1b7d740b76ede93edb60e77..b5b285dfc285bf6049d9db6166f0b26e49ffe398 100644 (file)
@@ -26,5 +26,6 @@
 #define PIC_GLUE_H
 
 void picglue (void);
+unsigned int pic14aopLiteral (value *val, int offset);
 
 #endif
index 74da6f0ec6f7c676010b49cce13805c731129a24..898f47302e83cacbfe09e06d7319053cd4b539b2 100644 (file)
@@ -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);
 }
index 43e01599e7671537eba4f08de82df1c18eb7a1b0..107c2e941a645af28580278985de820363573947 100644 (file)
@@ -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;
index 7df7587c71d25037cb416efaa4c57718a38b958b..2fc4da55066cdd7de6b58f7010cc36512547df8b 100644 (file)
@@ -26,5 +26,6 @@
 #define PIC16_GLUE_H
 
 void pic16glue (void);
+unsigned int pic16aopLiteral (value *val, int offset);
 
 #endif