nilist->type = type;
nilist->lineno = mylineno;
+ nilist->filename = currFname;
switch (type)
{
return FALSE;
}
- if (!IS_AST_LIT_VALUE(decorateType(resolveSymbols(iLoop->init.node))))
+ if (!IS_AST_LIT_VALUE(decorateType(resolveSymbols(iLoop->init.node), RESULT_TYPE_NONE)))
{
return FALSE;
}
/* resolveIvalSym - resolve symbols in initial values */
/*------------------------------------------------------------------*/
void
-resolveIvalSym (initList * ilist)
+resolveIvalSym (initList * ilist, sym_link * type)
{
+ RESULT_TYPE resultType;
+
if (!ilist)
return;
if (ilist->type == INIT_NODE)
- ilist->init.node = decorateType (resolveSymbols (ilist->init.node));
+ {
+ if (IS_PTR (type))
+ resultType = RESULT_TYPE_INT;
+ else
+ resultType = getResultTypeFromType (getSpec (type));
+ ilist->init.node = decorateType (resolveSymbols (ilist->init.node),
+ resultType);
+ }
if (ilist->type == INIT_DEEP)
- resolveIvalSym (ilist->init.deep);
+ resolveIvalSym (ilist->init.deep, type);
- resolveIvalSym (ilist->next);
+ resolveIvalSym (ilist->next, type);
}
/*-----------------------------------------------------------------*/
TYPE_DWORD sval=0;
TYPE_UDWORD uval=0;
- if (IS_FLOAT(val->type) || IS_CHAR(val->type))
+ if (IS_FLOAT(val->type) || IS_FIXED(val->type) || IS_CHAR(val->type))
return val;
if (SPEC_LONG(val->type)) {
static value *cheapestVal (value *val)
{
+ if (IS_FLOAT (val->type) || IS_FIXED (val->type) || IS_CHAR (val->type))
+ return val;
+
/* - signed/unsigned must not be changed.
- long must not be changed.
!SPEC_USIGN(val->type) &&
!SPEC_LONG(val->type) &&
SPEC_CVAL(val->type).v_int >= -128 &&
- SPEC_CVAL(val->type).v_int <= 127)
+ SPEC_CVAL(val->type).v_int < 0)
{
SPEC_NOUN(val->type) = V_CHAR;
}
- /* this could be too aggressive:
- 'unsigned char' promotes to 'signed int', so that we can
+ /* 'unsigned char' promotes to 'signed int', so that we can
reduce it the other way */
if (IS_INT(val->type) &&
!SPEC_USIGN(val->type) &&
!SPEC_LONG(val->type) &&
- SPEC_CVAL(val->type).v_int >= 128 &&
+ SPEC_CVAL(val->type).v_int >= 0 &&
SPEC_CVAL(val->type).v_int <= 255)
{
return val;
}
+/*-----------------------------------------------------------------*/
+/* constFixed16x16Val - converts a FIXED16X16 constant to value */
+/*-----------------------------------------------------------------*/
+value *
+constFixed16x16Val (char *s)
+{
+ value *val = newValue ();
+ double sval;
+
+ if (sscanf (s, "%lf", &sval) != 1)
+ {
+ werror (E_INVALID_FLOAT_CONST, s);
+ return constVal ("0");
+ }
+
+ val->type = val->etype = newLink (SPECIFIER);
+ SPEC_NOUN (val->type) = V_FLOAT;
+ SPEC_SCLS (val->type) = S_LITERAL;
+ SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble ( sval );
+
+ return val;
+}
+
/*-----------------------------------------------------------------*/
/* constVal - converts an INTEGER constant into a cheapest value */
/*-----------------------------------------------------------------*/
}
/* Setup the flags first */
- /* set the _long flag if 'lL' is found */
+ /* set the b_long flag if 'lL' is found */
if (strchr (s, 'l') || strchr (s, 'L')) {
SPEC_NOUN (val->type) = V_INT;
SPEC_LONG (val->type) = 1;
the programer wants */
SPEC_NOUN (val->type) = V_INT;
}
- else if (dval>0x7f && !SPEC_USIGN (val->type)) { // check if we have to promote to int
-#if 0
- if ((hex || octal) && /* hex or octal constants may be stored in unsigned type */
- dval<=0xff) {
- SPEC_USIGN (val->type) = 1;
- } else {
- SPEC_NOUN (val->type) = V_INT;
- }
-#else
- /* this is quite agressive: 'unsigned char' will be promoted to 'signed int',
- so that the signedness of a char shouldn't matter */
+ else { /* store char's always as unsigned; this helps other optimizations */
SPEC_USIGN (val->type) = 1;
-#endif
}
if (dval>0xffff && SPEC_USIGN (val->type)) { // check if we have to promote to long
SPEC_LONG (val->type) = 1;
if (SPEC_NOUN (val->etype) == V_FLOAT)
return (double) SPEC_CVAL (val->etype).v_float;
+ if (SPEC_NOUN (val->etype) == V_FIXED16X16)
+ return (double) doubleFromFixed16x16( SPEC_CVAL (val->etype).v_fixed16x16 );
+
if (SPEC_LONG (val->etype))
{
if (SPEC_USIGN (val->etype))
/* depending on type */
if (SPEC_NOUN (val->etype) == V_FLOAT)
SPEC_CVAL (val->etype).v_float = -1.0 * SPEC_CVAL (val->etype).v_float;
+ if (SPEC_NOUN (val->etype) == V_FIXED16X16)
+ SPEC_CVAL (val->etype).v_fixed16x16 = -SPEC_CVAL (val->etype).v_fixed16x16;
else
{
if (SPEC_LONG (val->etype))
SPEC_CVAL (val->etype).v_uint = ~SPEC_CVAL (val->etype).v_uint;
else
SPEC_CVAL (val->etype).v_int = ~SPEC_CVAL (val->etype).v_int;
+ if (SPEC_NOUN(val->etype) == V_CHAR)
+ if ( SPEC_CVAL(val->etype).v_int < -128
+ || SPEC_CVAL(val->etype).v_int > 127)
+ SPEC_NOUN(val->etype) = V_INT;
}
// ~(unsigned 3) now really is signed
SPEC_USIGN(val->etype)=0;
/* create a new value */
val = newValue ();
- val->type = val->etype = newLink (SPECIFIER);
- SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
- IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
- SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */
- SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype));
- SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
- rval->etype,
- TRUE));
+ val->type = val->etype = computeType (lval->etype,
+ rval->etype,
+ RESULT_TYPE_INT,
+ '*');
+ SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
+
if (IS_FLOAT (val->type))
SPEC_CVAL (val->type).v_float = floatFromVal (lval) * floatFromVal (rval);
+ else
+ if (IS_FIXED16X16 (val->type))
+ SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble(floatFromVal (lval) * floatFromVal (rval));
/* signed and unsigned mul are the same, as long as the precision of the
result isn't bigger than the precision of the operands. */
else if (SPEC_LONG (val->type))
/* create a new value */
val = newValue ();
- val->type = val->etype = newLink(SPECIFIER);
- SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
- IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
- SPEC_SCLS (val->etype) = S_LITERAL;
- SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype));
- SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
- rval->etype,
- TRUE));
+ val->type = val->etype = computeType (lval->etype,
+ rval->etype,
+ RESULT_TYPE_INT,
+ '/');
+ SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
if (IS_FLOAT (val->type))
SPEC_CVAL (val->type).v_float = floatFromVal (lval) / floatFromVal (rval);
+ else
+ if (IS_FIXED16X16 (val->type))
+ SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble( floatFromVal (lval) / floatFromVal (rval) );
else if (SPEC_LONG (val->type))
{
if (SPEC_USIGN (val->type))
value *val;
/* create a new value */
- val = newValue ();
- val->type = val->etype = newLink (SPECIFIER);
- SPEC_NOUN (val->type) = V_INT; /* type is int */
- SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */
- SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype));
- SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
- rval->etype,
- TRUE));
+ val = newValue();
+ val->type = val->etype = computeType (lval->etype,
+ rval->etype,
+ RESULT_TYPE_INT,
+ '%');
+ SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
if (SPEC_LONG (val->type))
{
value *val;
/* create a new value */
- val = newValue ();
- val->type = val->etype = newLink (SPECIFIER);
- SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
- IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
- SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */
- SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype));
- SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
- rval->etype,
- TRUE));
+ val = newValue();
+ val->type = val->etype = computeType (lval->etype,
+ rval->etype,
+ RESULT_TYPE_INT,
+ '+');
+ SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
+
if (IS_FLOAT (val->type))
SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval);
+ else
+ if (IS_FIXED16X16 (val->type))
+ SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble( floatFromVal (lval) + floatFromVal (rval) );
else if (SPEC_LONG (val->type))
{
if (SPEC_USIGN (val->type))
value *val;
/* create a new value */
- val = newValue ();
- val->type = val->etype = newLink (SPECIFIER);
- SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
- IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
- SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */
- SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype));
- SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
- rval->etype,
- FALSE));
+ val = newValue();
+ val->type = val->etype = computeType (lval->etype,
+ rval->etype,
+ RESULT_TYPE_INT,
+ '-');
+ SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
+
if (IS_FLOAT (val->type))
SPEC_CVAL (val->type).v_float = floatFromVal (lval) - floatFromVal (rval);
+ else
+ if (IS_FIXED16X16 (val->type))
+ SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble( floatFromVal (lval) - floatFromVal (rval) );
else if (SPEC_LONG (val->type))
{
if (SPEC_USIGN (val->type))
value *val;
/* create a new value */
- val = newValue ();
- val->type = val->etype = newIntLink ();
- SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */
- SPEC_NOUN (val->etype) = V_INT;
- /* 'unsigned char' promotes to 'signed int' */
- if (!IS_CHAR (lval->etype))
- SPEC_USIGN (val->type) = SPEC_USIGN (lval->etype);
- SPEC_LONG (val->type) = SPEC_LONG (lval->etype);
+ val = newValue();
+ val->type = val->etype = computeType (lval->etype,
+ NULL,
+ RESULT_TYPE_INT,
+ 'S');
+ SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
if (getSize (val->type) * 8 <= (TYPE_UDWORD) floatFromVal (rval) &&
/* left shift */
{
SPEC_CVAL (val->type).v_int = floatFromVal (lval) == floatFromVal (rval);
}
+ else
+ if (SPEC_NOUN(lval->type) == V_FIXED16X16 ||
+ SPEC_NOUN(rval->type) == V_FIXED16X16)
+ {
+ SPEC_CVAL (val->type).v_int = floatFromVal (lval) == floatFromVal (rval);
+ }
else
{
/* integrals: ignore signedness */
{
SPEC_CVAL (val->type).v_int = floatFromVal (lval) != floatFromVal (rval);
}
+ else
+ if (SPEC_NOUN(lval->type) == V_FIXED16X16 ||
+ SPEC_NOUN(rval->type) == V_FIXED16X16)
+ {
+ SPEC_CVAL (val->type).v_int = floatFromVal (lval) != floatFromVal (rval);
+ }
else
{
/* integrals: ignore signedness */
/* create a new value */
val = newValue ();
- val->type = copyLinkChain (getSize(rval->type) > getSize(lval->type) ?
- rval->type : lval->type);
+ val->type = computeType (lval->etype, rval->etype, RESULT_TYPE_CHAR, op);
val->etype = getSpec (val->type);
+ SPEC_SCLS (val->etype) = S_LITERAL;
switch (op)
{
if (SPEC_LONG (val->type))
{
if (SPEC_USIGN (val->type))
- SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) &
- (unsigned long) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) &
+ (TYPE_UDWORD) floatFromVal (rval);
else
- SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) &
- (long) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) &
+ (TYPE_DWORD) floatFromVal (rval);
}
else
{
if (SPEC_USIGN (val->type))
- SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) &
- (unsigned) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) &
+ (TYPE_UWORD) floatFromVal (rval);
else
- SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) & (int) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) & (TYPE_WORD) floatFromVal (rval);
}
break;
if (SPEC_LONG (val->type))
{
if (SPEC_USIGN (val->type))
- SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) |
- (unsigned long) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) |
+ (TYPE_UDWORD) floatFromVal (rval);
else
- SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) |
- (long) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) |
+ (TYPE_DWORD) floatFromVal (rval);
}
else
{
if (SPEC_USIGN (val->type))
- SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) |
- (unsigned) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) |
+ (TYPE_UWORD) floatFromVal (rval);
else
SPEC_CVAL (val->type).v_int =
- (int) floatFromVal (lval) | (int) floatFromVal (rval);
+ (TYPE_WORD) floatFromVal (lval) | (TYPE_WORD) floatFromVal (rval);
}
break;
if (SPEC_LONG (val->type))
{
if (SPEC_USIGN (val->type))
- SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) ^
- (unsigned long) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) ^
+ (TYPE_UDWORD) floatFromVal (rval);
else
- SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) ^
- (long) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) ^
+ (TYPE_DWORD) floatFromVal (rval);
}
else
{
if (SPEC_USIGN (val->type))
- SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) ^
- (unsigned) floatFromVal (rval);
+ SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) ^
+ (TYPE_UWORD) floatFromVal (rval);
else
SPEC_CVAL (val->type).v_int =
- (int) floatFromVal (lval) ^ (int) floatFromVal (rval);
+ (TYPE_WORD) floatFromVal (lval) ^ (TYPE_WORD) floatFromVal (rval);
}
break;
}
-
+
return cheapestVal(val);
}
val->type = val->etype = newCharLink ();
val->type->class = SPECIFIER;
SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */
- SPEC_USIGN (val->type) = 0;
+ SPEC_USIGN (val->type) = 1;
switch (op)
{
return NULL;
val = newValue ();
- val->etype = getSpec (val->type = copyLinkChain (dtype));
+ if (dtype)
+ val->etype = getSpec (val->type = copyLinkChain (dtype));
+ else
+ {
+ val->etype = val->type = newLink (SPECIFIER);
+ SPEC_NOUN (val->etype) = V_VOID;
+ }
SPEC_SCLS (val->etype) = S_LITERAL;
/* if it is not a specifier then we can assume that */
if (SPEC_NOUN (val->etype) == V_FLOAT)
SPEC_CVAL (val->etype).v_float = fval;
+ else if (SPEC_NOUN (val->etype) == V_FIXED16X16)
+ SPEC_CVAL (val->etype).v_fixed16x16 = fixed16x16FromDouble( fval );
+ else if (SPEC_NOUN (val->etype) == V_BIT ||
+ SPEC_NOUN (val->etype) == V_SBIT)
+ SPEC_CVAL (val->etype).v_uint = l ? 1 : 0;
+ else if (SPEC_NOUN (val->etype) == V_BITFIELD)
+ SPEC_CVAL (val->etype).v_uint = l &
+ (0xffffu >> (16 - SPEC_BLEN (val->etype)));
else if (SPEC_NOUN (val->etype) == V_CHAR) {
if (SPEC_USIGN (val->etype))
SPEC_CVAL (val->etype).v_uint= (TYPE_UBYTE) l;
DCL_TYPE (val->type) = EEPPOINTER;
else
DCL_TYPE (val->type) = POINTER;
- val->type->next = arrExpr->left->ftype;
+ val->type->next = arrExpr->left->ftype->next;
val->etype = getSpec (val->type);
return val;
}