Commit 8651f70d authored by malenov's avatar malenov
Browse files

inclusion of stdio.h and stdlib.h

parent e4b85995
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -519,7 +519,7 @@ void print_wmops(void)
 * Maximum heap is measured by summing the sizes of all memory blocks allocated by malloc() or calloc() and deallocated by free(). The maximum heap size is
 * updated each time when the macros malloc_() or calloc_() is invoked. The macros 'malloc_ and calloc_' are inserted automatically during the instrumentation process.
 * As part of heap measurements, intra-frame heap and inter-frame heap are measured separately. Intra-frame heap refers to heap memory which is allocated and deallocated
 * within a single frame. Inter-frame heap, on the contrary, refers to heap memory which is preserved for more than one frame.
 * within a single frame. Inter-frame heap, on the contrary, refers to heap memory which is reserved for more than one frame.
 *
 * In order to run the memory counting tool the function reset_mem(cnt_size) must be called at the beginning of the encoding/decoding process.
 * The unit in which memory consumption is reported is set via the parameter 'cnt_size'. It can be set to 0 (bytes), 1 (32b words) or 2 (64b words).
+123 −56
Original line number Diff line number Diff line
@@ -15,6 +15,15 @@
#ifndef WMOPS_H
#define WMOPS_H
    
#ifndef EXIT_FAILURE
#include <stdlib.h>         /* stdlib is needed for exit() */
#endif

#ifndef EOF
#include <stdio.h>          /* stdio is needed for fprintf() */
#endif


/* To Prevent "warning: '$' in identifier or number" message under GCC */
#ifdef __GNUC__
#pragma GCC system_header
@@ -189,14 +198,6 @@ extern int cntr_push_pop;
static double* ops_cnt_ptr = &ops_cnt;
#define OP_COUNT_(op, x) (*ops_cnt_ptr+=(op##_C*(x)), inst_cnt[op]+=(x))

/* #pragma GCC diagnostic is Available from gcc V4.2.4 */
#if (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) >= 40204
/* Disable Some Warnings with Cygwin gcc Compiler (Only when WMOPS are Activated) */
/* To Avoid: "warning: suggest parentheses around && within ||" and
             "warning: suggest explicit braces to avoid ambiguous else" */
#pragma GCC diagnostic ignored "-Wparentheses" /* Otherwise use : "-Wno-parentheses" */
#endif

/******************************************************************/
/* NOTES:                                                         */
/*   The 'wmc_flag_' flag is global to avoid declaration in every */
@@ -327,60 +328,126 @@ static int wmc_flag_ = 0;

#ifdef WMOPS

/* Check if EOF is defined */
#ifndef EOF          
#include <stdio.h> /* required for 'fprintf' */
#endif
#define ACC 2
#define MUL 1

/* Counter Function (should not be called externally!) */
/* Counting Function (should not be called externally!) */
static void wops_(const char* ops)
{
    char lm = 0;        /* lm: Last Operation is Math */
    static char lo = 0; /* Last Operation */
#define ACC 2
#define MUL 1

    void (*fct)(const char* ops) = wops_;
st: while (*ops != '\0') {
    switch (*ops++) {

st:
    while ( *ops != '\0' )
    {
        switch ( *ops++ )
        {
            int cnt;
    case '-':          for (cnt = 0; ops[cnt] == '>'; cnt++); if (cnt & 1) goto ind;
    case '+':                     lm = 2; if (lo & MUL) { MULT_(-1); MAC_(1); break; }
    lo = ACC << 2; case 'U': case 'D':     ADD_(1); break;
    case '*':                     lm = 2; if (lo & ACC) { ADD_(-1); MAC_(1); break; }
            lo = MUL << 2;                        MULT_(1); break;
    case '/': case '%':           lm = 2;                         DIV_(1); break;
    case '&': case '|': case '^': lm = 2; case '~':             LOGIC_(1); break;
    case '<': case '>':                        if (*ops != ops[-1]) goto error; ops++;
    case -85: case -69:           lm = 2;                       SHIFT_(1); break;
    case 'L': case 'G':                                 if (*ops == 't') goto comp;
    case 'E': case 'N':                                 if (*ops != 'e') goto error;
    comp:                                                            ops++; ADD_(1); break;
    case '!':                                                  MISC_(2); break;
    case 'M':                                                  MOVE_(1); break;
    case 'S':                                                 STORE_(1); break;
    case 'P':                                              PTR_INIT_(1); break;
    case '[': case ']':                                                  goto st;
    ind:                                                                      ops++;
    case 'I': case '.':                                    INDIRECT_(1); break;
    case '=':                                                    if (lm) goto st;
    case '\0': /* This Cannot Happen */
        /* These are Used to Avoid: "warning: 'name' defined but not used"
           with Cygwin gcc Compiler */
            case '-':
                for ( cnt = 0; ops[cnt] == '>'; cnt++ )
                    ;
                if ( cnt & 1 )
                    goto ind;
            case '+':
                lm = 2;
                if ( lo & MUL )
                {
                    MULT_( -1 );
                    MAC_( 1 );
                    break;
                }
                lo = ACC << 2;
            case 'U':
            case 'D':
                ADD_( 1 );
                break;
            case '*':
                lm = 2;
                if ( lo & ACC )
                {
                    ADD_( -1 );
                    MAC_( 1 );
                    break;
                }
                lo = MUL << 2;
                MULT_( 1 );
                break;
            case '/':
            case '%':
                lm = 2;
                DIV_( 1 );
                break;
            case '&':
            case '|':
            case '^':
                lm = 2;
            case '~':
                LOGIC_( 1 );
                break;
            case '<':
            case '>':
                if ( *ops != ops[-1] )
                    goto error;
                ops++;
            case -85:
            case -69:
                lm = 2;
                SHIFT_( 1 );
                break;
            case 'L':
            case 'G':
                if ( *ops == 't' )
                    goto comp;
            case 'E':
            case 'N':
                if ( *ops != 'e' )
                    goto error;
            comp:
                ops++;
                ADD_( 1 );
                break;
            case '!':
                MISC_( 2 );
                break;
            case 'M':
                MOVE_( 1 );
                break;
            case 'S':
                STORE_( 1 );
                break;
            case 'P':
                PTR_INIT_( 1 );
                break;
            case '[':
            case ']':
                goto st;
            ind:
                ops++;
            case 'I':
            case '.':
                INDIRECT_( 1 );
                break;
            case '=':
                if ( lm )
                    goto st;
            case '\0': 
                /* This Shouldn't Happen */
                /* These are Used to Avoid: "warning: 'name' defined but not used" with Cygwin gcc Compiler */
                wmc_flag_ = wmc_flag_;
                ops_cnt_ptr = ops_cnt_ptr;
                fct( "" );
    error:      default:
        /* The Following Checks are made instead of Including the Required Files to
           avoid generating warnings if they are already Included in the Source File */
#ifdef EOF      /* Will exist if <stdio.h> is Included */
error:
            default:
                fprintf( stderr, "\r wops: Invalid Counting Operation '%s'\n", ops - 1 );
#ifdef EXIT_FAILURE /* Will exist if <stdlib.h> is Included */
        exit(EXIT_FAILURE);
#endif
#endif
        return; /* If no Exit Mechanism, just continue */
    } lm >>= 1; lo >>= 2;
                exit( -1 );
        }
        lm >>= 1;
        lo >>= 2;
    }

    return;
}

#endif