Ejemplo n.º 1
0
static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt,
                        uint8_t flags, int fieldwidth, int valwidth)
{
  int i;

  /* Apply field justification to the integer value. */

  switch (fmt)
    {
      default:
      case FMT_RJUST:
      case FMT_RJUST0:
        break;

      case FMT_LJUST:
        if (IS_SIGNED(flags))
          {
            valwidth++;
          }

        for (i = fieldwidth - valwidth; i > 0; i--)
          {
            obj->put(obj, ' ');
          }
        break;
    }
}
Ejemplo n.º 2
0
static void Transform2(
	size_t nrCells,
	void  *buf,
	CSF_CR destCellRepr, /* the output representation */
	CSF_CR currCellRepr)  /* at start of while this is the representation
				read in the MAP-file */
{
  /* subsequent looping changes the to the new
   * converted type
   */
	while(currCellRepr != destCellRepr)
	{
		switch(currCellRepr)
		{
			case CR_INT1:    ConvertToINT2(nrCells, buf,
						currCellRepr);
					currCellRepr = CR_INT2;
					break;
			case CR_INT2:    ConvertToINT4(nrCells, buf, 
						currCellRepr);
					currCellRepr = CR_INT4;
					break;
			case CR_INT4:    ConvertToREAL4(nrCells, buf,
						currCellRepr);
					currCellRepr = CR_REAL4;
					break;
			case CR_UINT1: 	if (IS_SIGNED(destCellRepr))
					{
						ConvertToINT2(nrCells, buf,
							currCellRepr);
						currCellRepr = CR_INT2;
					}
					else
					{
						UINT1tUINT2(nrCells, buf);
						currCellRepr = CR_UINT2;
					}
					break;
			case CR_UINT2:   if (destCellRepr == CR_INT4)
					{
						ConvertToINT4(nrCells, buf,
							currCellRepr);
					 	currCellRepr = CR_INT4;
					 }
					 else
					 {
						UINT2tUINT4(nrCells, buf);
						currCellRepr = CR_UINT4;
					 }
					 break;
			case CR_UINT4:   ConvertToREAL4(nrCells, buf,
						currCellRepr);
					currCellRepr = CR_REAL4;
					break;
			default       :	POSTCOND(currCellRepr == CR_REAL4);
					REAL4tREAL8(nrCells, buf);
					currCellRepr = CR_REAL8;
		}
	}
}
Ejemplo n.º 3
0
static void ConvertToREAL4( size_t nrCells, void *buf, CSF_CR src)
{
	size_t i;

	i = (size_t)nrCells;

	if (IS_SIGNED(src))
	{
		POSTCOND(src == CR_INT4);
		INT4tREAL4(nrCells, buf);
	}
	else
	{
		POSTCOND(src == CR_UINT4);
		{
			do {
				i--;
				if ( ((UINT4 *)buf)[i] == MV_UINT4 )
					((UINT4 *)buf)[i] = MV_UINT4;
				else
					((REAL4 *)buf)[i] = (REAL4)((UINT4 *)buf)[i];
			    }
			while(i != 0);
		}
	}
}
Ejemplo n.º 4
0
static void prejustify(FAR struct lib_outstream_s *obj, uint8_t fmt,
                       uint8_t flags, int fieldwidth, int valwidth)
{
  int i;

  switch (fmt)
    {
      default:
      case FMT_RJUST:
        if (IS_SIGNED(flags))
          {
            valwidth++;
          }

        for (i = fieldwidth - valwidth; i > 0; i--)
          {
            obj->put(obj, ' ');
          }

        if (IS_NEGATE(flags))
          {
            obj->put(obj, '-');
          }
        else if (IS_SHOWPLUS(flags))
          {
            obj->put(obj, '+');
          }
        break;

      case FMT_RJUST0:
         if (IS_NEGATE(flags))
          {
            obj->put(obj, '-');
            valwidth++;
          }
        else if (IS_SHOWPLUS(flags))
          {
            obj->put(obj, '+');
            valwidth++;
          }

        for (i = fieldwidth - valwidth; i > 0; i--)
          {
            obj->put(obj, '0');
          }
        break;

      case FMT_LJUST:
         if (IS_NEGATE(flags))
          {
            obj->put(obj, '-');
          }
        else if (IS_SHOWPLUS(flags))
          {
            obj->put(obj, '+');
          }
        break;
    }
}
Ejemplo n.º 5
0
static ucl_bool basic_ptr_check(void)
{
    ucl_bool r = 1;
    ucl_bool sanity;

    r &= __ucl_assert(sizeof(char *) >= sizeof(int));
    r &= __ucl_assert(sizeof(ucl_byte *) >= sizeof(char *));

    r &= __ucl_assert(sizeof(ucl_voidp) == sizeof(ucl_byte *));
    r &= __ucl_assert(sizeof(ucl_voidp) == sizeof(ucl_voidpp));
    r &= __ucl_assert(sizeof(ucl_voidp) == sizeof(ucl_bytepp));
    r &= __ucl_assert(sizeof(ucl_voidp) >= sizeof(ucl_uint));

    r &= __ucl_assert(sizeof(ucl_ptr_t) == sizeof(ucl_voidp));
    r &= __ucl_assert(sizeof(ucl_ptr_t) >= sizeof(ucl_uint));

    r &= __ucl_assert(sizeof(ucl_ptrdiff_t) >= 4);
    r &= __ucl_assert(sizeof(ucl_ptrdiff_t) >= sizeof(ptrdiff_t));

#if defined(SIZEOF_CHAR_P)
    r &= __ucl_assert(SIZEOF_CHAR_P == sizeof(char *));
#endif
#if defined(SIZEOF_PTRDIFF_T)
    r &= __ucl_assert(SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t));
#endif

    /* assert the signedness of our integral types */
    sanity = IS_UNSIGNED(unsigned short) && IS_UNSIGNED(unsigned) &&
             IS_UNSIGNED(unsigned long) &&
             IS_SIGNED(short) && IS_SIGNED(int) && IS_SIGNED(long);
    if (sanity)
    {
        r &= __ucl_assert(IS_UNSIGNED(ucl_ptr_t));
        r &= __ucl_assert(IS_UNSIGNED(ucl_moff_t));
        r &= __ucl_assert(IS_SIGNED(ucl_ptrdiff_t));
        r &= __ucl_assert(IS_SIGNED(ucl_sptr_t));
    }

    return r;
}
Ejemplo n.º 6
0
static void ConvertToINT4( size_t nrCells, void *buf, CSF_CR src)
{
	if (IS_SIGNED(src))
	{
		POSTCOND(src == CR_INT2);
		CONV_SMALL_TO_BIG(nrCells,buf, INT4, INT2);
	}
	else  
	{
		POSTCOND(src == CR_UINT2);
		CONV_SMALL_TO_BIG(nrCells,buf, INT4, UINT2);
	}
}
Ejemplo n.º 7
0
static ucl_bool basic_integral_check(void)
{
    ucl_bool r = 1;
    ucl_bool sanity;

    /* paranoia */
    r &= __ucl_assert(CHAR_BIT == 8);
    r &= __ucl_assert(sizeof(char) == 1);
    r &= __ucl_assert(sizeof(short) >= 2);
    r &= __ucl_assert(sizeof(long) >= 4);
    r &= __ucl_assert(sizeof(int) >= sizeof(short));
    r &= __ucl_assert(sizeof(long) >= sizeof(int));

    r &= __ucl_assert(sizeof(ucl_uint32) >= 4);
    r &= __ucl_assert(sizeof(ucl_uint32) >= sizeof(unsigned));
#if defined(__UCL_STRICT_16BIT)
    r &= __ucl_assert(sizeof(ucl_uint) == 2);
#else
    r &= __ucl_assert(sizeof(ucl_uint) >= 4);
    r &= __ucl_assert(sizeof(ucl_uint) >= sizeof(unsigned));
#endif

#if defined(SIZEOF_UNSIGNED)
    r &= __ucl_assert(SIZEOF_UNSIGNED == sizeof(unsigned));
#endif
#if defined(SIZEOF_UNSIGNED_LONG)
    r &= __ucl_assert(SIZEOF_UNSIGNED_LONG == sizeof(unsigned long));
#endif
#if defined(SIZEOF_UNSIGNED_SHORT)
    r &= __ucl_assert(SIZEOF_UNSIGNED_SHORT == sizeof(unsigned short));
#endif
#if !defined(__UCL_IN_MINIUCL)
#if defined(SIZEOF_SIZE_T)
    r &= __ucl_assert(SIZEOF_SIZE_T == sizeof(size_t));
#endif
#endif

    /* assert the signedness of our integral types */
    sanity = IS_UNSIGNED(unsigned short) && IS_UNSIGNED(unsigned) &&
             IS_UNSIGNED(unsigned long) &&
             IS_SIGNED(short) && IS_SIGNED(int) && IS_SIGNED(long);
    if (sanity)
    {
        r &= __ucl_assert(IS_UNSIGNED(ucl_uint32));
        r &= __ucl_assert(IS_UNSIGNED(ucl_uint));
        r &= __ucl_assert(IS_SIGNED(ucl_int32));
        r &= __ucl_assert(IS_SIGNED(ucl_int));

        r &= __ucl_assert(INT_MAX    == UCL_STYPE_MAX(sizeof(int)));
        r &= __ucl_assert(UINT_MAX   == UCL_UTYPE_MAX(sizeof(unsigned)));
        r &= __ucl_assert(LONG_MAX   == UCL_STYPE_MAX(sizeof(long)));
        r &= __ucl_assert(ULONG_MAX  == UCL_UTYPE_MAX(sizeof(unsigned long)));
        r &= __ucl_assert(SHRT_MAX   == UCL_STYPE_MAX(sizeof(short)));
        r &= __ucl_assert(USHRT_MAX  == UCL_UTYPE_MAX(sizeof(unsigned short)));
        r &= __ucl_assert(UCL_UINT32_MAX == UCL_UTYPE_MAX(sizeof(ucl_uint32)));
        r &= __ucl_assert(UCL_UINT_MAX   == UCL_UTYPE_MAX(sizeof(ucl_uint)));
#if !defined(__UCL_IN_MINIUCL)
        r &= __ucl_assert(SIZE_T_MAX     == UCL_UTYPE_MAX(sizeof(size_t)));
#endif
    }

#if 0
    /* for some reason this fails on a Cray ??? */
    r &= __ucl_assert(UCL_BYTE(257) == 1);
    r &= __ucl_assert(UCL_USHORT(65537L) == 1);
#endif

    return r;
}
Ejemplo n.º 8
0
static ret_code GetSimpleExpression( hll_list * hll, int *i, int ilabel, bool is_true, char * buffer, char **jmp, expr_list *opndx )
/**********************************************************************************************************************************/
{
    //expr_list opndx;
    expr_list op2;
    c_bop op;
    //int size;
    //int end_tok;
    int op1_pos;
    int op1_end;
    int op2_pos;
    int op2_end;
    char *label;
    bool issigned;

    DebugMsg(("GetSimpleExpression(buffer=%s) enter\n", buffer ));

    while ( AsmBuffer[*i]->string_ptr[0] == '!' && AsmBuffer[*i]->string_ptr[1] == '\0' ) {
        GetCOp(i);
        is_true = 1 - is_true;
    }

    op1_pos = *i;
    /* the problem with '()' is that is might enclose just a standard Masm
     * expression or a "hll" expression. The first case is to be handled 
     * entirely by the expression evaluator, while the latter case is to be
     * handled HERE!
     */
    if ( AsmBuffer[*i]->token == T_OP_BRACKET ) {
        int brcnt;
        int j;
        for ( brcnt = 1, j = *i + 1; AsmBuffer[j]->token != T_FINAL; j++ ) {
            if ( AsmBuffer[j]->token == T_OP_BRACKET )
                brcnt++;
            else if ( AsmBuffer[j]->token == T_CL_BRACKET ) {
                brcnt--;
                if ( brcnt == 0 ) /* a standard Masm expression? */
                    break;
            } else if ( ( GetCOp( &j )) != COP_NONE )
                break;
        }
        if ( brcnt ) {
            (*i)++;
            DebugMsg(("GetSimpleExpression: calling GetExpression, i=%u\n", *i));
            if ( ERROR == GetExpression( hll, i, ilabel, is_true, buffer, jmp, opndx ) )
                return( ERROR );
            DebugMsg(("return from GetExpression, i=%u\n", *i));

            if ( AsmBuffer[*i]->token != T_CL_BRACKET ) {
                //if ((AsmBuffer[*i]->token == T_FINAL) || (AsmBuffer[*i]->token == T_CL_BRACKET))
                DebugMsg(( "GetSimpleExpression: expected ')', found: %s\n", AsmBuffer[*i]->string_ptr ));
                AsmError( SYNTAX_ERROR_IN_CONTROL_FLOW_DIRECTIVE );
                return( ERROR );
            }
            (*i)++;
            return( NOT_ERROR );
        }
    }

    if ( ERROR == GetToken( hll, i, is_true, opndx ) )
        return ( ERROR );

    op1_end = *i;

    op = GetCOp( i );

    if ( op == COP_AND || op == COP_OR ) {
        *i = op1_end;
        if ( opndx->kind == EXPR_EMPTY )
            return( NOT_ERROR );
        op = COP_NONE;
    }

    label = GetLabel( hll, ilabel );

    DebugMsg(("GetSimpleExpression: EvalOperand ok, kind=%X, i=%u\n", opndx->kind, *i));

    if ( opndx->kind == EXPR_EMPTY ) {
        /* no valid ASM expression detected. check for some special ops */
        /* COP_ZERO, COP_CARRY, COP_SIGN, COP_PARITY, COP_OVERFLOW */
        if ( op >= COP_ZERO ) {
            //char t;
            char * p;
            //char * s;
            p = buffer;
            *jmp = p;
            *p++ = 'j';
            if ( is_true == FALSE )
                *p++ = 'n';

            switch ( op ) {
            case COP_CARRY:
                *p++ = 'c';
                break;
            case COP_ZERO:
                *p++ = 'z';
                break;
            case COP_SIGN:
                *p++ = 's';
                break;
            case COP_PARITY:
                *p++ = 'p';
                break;
            case COP_OVERFLOW:
                *p++ = 'o';
                break;
            }
            *p++ = ' ';
            if ( is_true == TRUE )
                *p++ = ' ';
            strcpy( p, label );
            goto done;
        }
        if ( hll->condlines )
            return( NOT_ERROR );
        else {
            AsmError( SYNTAX_ERROR_IN_CONTROL_FLOW_DIRECTIVE );
            return( NOT_ERROR );
        }
    }

    if ( ( opndx->kind != EXPR_CONST ) && ( opndx->kind != EXPR_ADDR ) && ( opndx->kind != EXPR_REG ) )
        return( ERROR );

    op2_pos = *i;

    if ( op != COP_NONE ) {
        if ( ERROR == GetToken( hll, i, is_true, &op2 ) ) {
            return( ERROR );
        }
        DebugMsg(("GetSimpleExpression: EvalOperand 2 ok, type=%X, i=%u\n", op2.type, *i));
        if ( ( op2.kind != EXPR_CONST ) && ( op2.kind != EXPR_ADDR ) && ( op2.kind != EXPR_REG ) ) {
            DebugMsg(("GetSimpleExpression: syntax error, op2.kind=%u\n", op2.kind ));
            AsmError( SYNTAX_ERROR );
            return( ERROR );
        }
    }
    op2_end = *i;

    /* now generate ASM code for expression */

    buffer[0] = 0;
    if ( ( op == COP_EQ ) ||
        ( op == COP_NE ) ||
        ( op == COP_GT ) ||
        ( op == COP_LT ) ||
        ( op == COP_GE ) ||
        ( op == COP_LE ) ) {
        char * p;

        /* optimisation: generate 'or EAX,EAX' instead of 'cmp EAX,0' */
        if ( Options.masm_compat_gencode &&
            ( op == COP_EQ || op == COP_NE ) &&
            opndx->kind == EXPR_REG &&
            opndx->indirect == FALSE &&
            op2.kind == EXPR_CONST &&
            op2.value == 0 ) {
            strcat( buffer," or " );
            RenderOpnd( opndx, buffer, op1_pos, op1_end );
            strcat( buffer, ", " );
            RenderOpnd( opndx, buffer, op1_pos, op1_end );
        } else {
            strcat( buffer," cmp " );
            RenderOpnd( opndx, buffer, op1_pos, op1_end );
            strcat( buffer, ", " );
            RenderOpnd( &op2, buffer, op2_pos, op2_end );
        }
        strcat( buffer, "\n" );

        p = buffer + strlen( buffer );
        *jmp = p;

        if (IS_SIGNED( opndx->mem_type ) || IS_SIGNED(op2.mem_type))
            issigned = TRUE;
        else
            issigned = FALSE;

        switch ( op ) {
        case COP_EQ:
            if ( is_true )
                strcpy( p, "jz  " );
            else
                strcpy( p, "jnz " );
            break;
        case COP_NE:
            if ( is_true )
                strcpy( p, "jnz " );
            else
                strcpy( p, "jz  " );
            break;
        case COP_GT:
            if ( issigned == TRUE ) {
                if ( is_true )
                    strcpy( p, "jg  " );
                else
                    strcpy( p, "jle " );
            } else {
                if ( is_true )
                    strcpy( p, "ja  " );
                else
                    strcpy( p, "jbe " );
            }
            break;
        case COP_LT:
            if ( issigned == TRUE ) {
                if ( is_true )
                    strcpy( p, "jl  " );
                else
                    strcpy( p, "jge " );
            } else {
                if ( is_true )
                    strcpy( p, "jb  " );
                else
                    strcpy( p, "jae " );
            }
            break;
        case COP_GE:
            if ( issigned == TRUE ) {
                if ( is_true )
                    strcpy( p, "jge " );
                else
                    strcpy( p, "jl  " );
            } else {
                if ( is_true )
                    strcpy( p, "jae " );
                else
                    strcpy( p, "jb  " );
            }
            break;
        case COP_LE:
            if ( issigned == TRUE ) {
                if ( is_true )
                    strcpy( p, "jle " );
                else
                    strcpy( p, "jg  " );
            } else {
                if ( is_true )
                    strcpy( p, "jbe " );
                else
                    strcpy( p, "ja  " );
            }
            break;
        }
        strcat( p, label );

    } else if ( op == COP_ANDB ) {
        char * p;

        strcat( buffer," test " );
        RenderOpnd( opndx, buffer, op1_pos, op1_end );
        strcat( buffer, ", " );
        RenderOpnd( &op2, buffer, op2_pos, op2_end );
        strcat( buffer, "\n" );

        p = buffer + strlen( buffer );
        *jmp = p;

        if ( is_true )
            strcpy( p, "jne " );
        else
            strcpy( p, "je  " );

        strcat( p, label );

    } else if ( op == COP_NONE ) {
        char * p;

        switch ( opndx->kind ) {
        case EXPR_REG:
            if ( opndx->indirect == FALSE ) {
                strcat( buffer, "and " );
                RenderOpnd( opndx, buffer, op1_pos, op1_end );
                strcat( buffer, ", " );
                RenderOpnd( opndx, buffer, op1_pos, op1_end );
                strcat( buffer, "\n" );
                p = buffer + strlen( buffer );
                *jmp = p;
                if ( is_true )
                    strcpy( p, "jnz " );
                else
                    strcpy( p, "jz  " );
                strcat( p, label );
                break;
            }
        case EXPR_ADDR:
            strcat( buffer, "cmp " );
            RenderOpnd( opndx, buffer, op1_pos, op1_end );
            strcat( buffer, ", 0\n" );
            p = buffer + strlen( buffer );
            *jmp = p;
            if ( is_true )
                strcpy( p, "jnz " );  /* switched */
            else
                strcpy( p, "jz  " );
            strcat( buffer, label );
            break;
        case EXPR_CONST:
            if ( opndx->string != NULL ) {
                AsmError( SYNTAX_ERROR_IN_CONTROL_FLOW_DIRECTIVE );
                return ( ERROR );
            }
            *jmp = buffer;
            if ( is_true == TRUE )
                if ( opndx->value )
                    sprintf( buffer, "jmp %s", label );
                else
                    strcpy( buffer, " "); /* make sure there is a char */
            if ( is_true == FALSE )
                if ( opndx->value == 0 )
                    sprintf( buffer, "jmp %s", label );
                else
                    strcpy( buffer, " " ); /* make sure there is a char */
            break;
        }
    }
done:
    strcat( buffer, "\n" );

    return( NOT_ERROR );
}