C test format

Overview

In order to facilitate the task of specifying tests to be reproduced/generated by Microprobe, we defined a C code environment so that the users can write down the test cases in C, and then let the compiler and the Microprobe framework to perform the code generation and all the plumbing required to make it work.

In brief, besides the actual implementation of the test case main function (named c2mpt_function), the user has to define a set of C macros so that the framework knows which variables and functions should also be included in the generated MPT. Optionally, the user can also define an initialization function, which will be called before the test case main function, to initialize the data values. The following sections explain more details about this environment.

Variable declaration and registration

The variables have to be declared and registered using a set of macros provided by the C test environment (defined in c2mpt.h file shown below). This allows the environment to know which variables are required to be part of the generated MPT.

The following macros are defined to declare variables:

  • DECLARE_VARIABLE(type, name, alignment)

  • DECLARE_VARIABLE_WITH_VALUE(type, name, alignment, init_value)

  • DECLARE_VARIABLE_ARRAY(type, name, name+dimension, alignment)

  • DECLARE_VARIABLE_ARRAY_WITH_VALUE(type, name, name+dimension alignment, init_value)

where:

  • type: is the variable type (e.g. char)

  • name: is the variable name (e.g. myvar)

  • name+dimension: is the name of the array and the dimensions of the array (e.g. myvar[10][20] )

  • alignment: is the minimum alignment for the variable

  • init_value: is the initial value

The following macros are defined to register the variables:

  • BEGIN_VARIABLE_REGISTRATION

  • REGISTER_VARIABLE(name)

  • END_VARIABLE_REGISTRATION

where:

  • name: is the variable name to register

Function registration

Besides the variables, the functions that need to be placed in the generated MPT also have to be declared using special macros. Instead of using regular fname(type1 arg1, type2 arg2,  ...  , type3 arg3) function signature declarations, the declarations should of the form MPT_FUNCTION(fname(type1 arg1, type2 arg2,  ...  , type3 arg3)). That is, just wrap the function signatures using the MPT_FUNCTION macro.

Function implementation

After defining how to declare variables and define function signatures, one needs to provide the implementation of the following function:

  • void c2mpt_function() : This is the main test function, which will be converted to the MPT format. This function can not perform library calls and it only should access to local variables (that will be placed in the stack) or global MPT register variables.

  • void c2mpt_init_global_vars() (optional): Use this function to initialize any global variables registered to the MPT. This function, since it is not going to be included in the generate MPT, can call any other functions and does not have any restriction.

  • Any other subroutine called by the c2mpt_function. Again, these subroutines, like the c2mpt_function can not perform library calls or access to global variables not registered in the MPT environment.

Examples

A matrix multiply example:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "c2mpt.h"

/****************************************************************************/
// Global variables
//
// Define in the section below the global variable to be used in the 
// "c2mpt_function" and its subroutines. Variable below are going to be
// imported to the mpt format. The variables have to be declared first
// and then, they have to be registered (see example below).
//
// The following macros are defined to declare variables:
//
// DECLARE_VARIABLE(type, name, alignment)
// DECLARE_VARIABLE_WITH_VALUE(type, name, alignment, init_value)
// DECLARE_VARIABLE_ARRAY(type, name, name+dimension, alignment)
// DECLARE_VARIABLE_ARRAY_WITH_VALUE(type, name, name+dimension alignment, init_value)
//
// where:
//
// - type: is the variable type (e.g. char)
// - name: is the variable name (e.g. myvar)
// - name+dimension: is the name of the array and the dimensions of the array 
//                   (e.g. myvar[10][20] )
// - alignment: is the minimum algnment for the variable                 
// - init_value: is the initial value
//
// The following macros are defined to register the variables:
//
// BEGIN_VARIABLE_REGISTRATION
// REGISTER_VARIABLE(name)
// END_VARIABLE_REGISTRATION
//
// where:
//
// - name: is the variable name to register
//
/****************************************************************************/

#define N 10

DECLARE_VARIABLE_ARRAY(int64_t,matA,matA[N][N],sizeof(int64_t))
DECLARE_VARIABLE_ARRAY(int64_t,matB,matB[N][N],sizeof(int64_t))
DECLARE_VARIABLE_ARRAY_WITH_VALUE(int64_t,matC,matC[N][N],sizeof(int64_t), {[0][1]=2,[1][0]=1} )

BEGIN_VARIABLE_REGISTRATION
REGISTER_VARIABLE(matA)
REGISTER_VARIABLE(matB)
REGISTER_VARIABLE(matC)
END_VARIABLE_REGISTRATION

/****************************************************************************/
// Function declaration 
//
// Declare the functions to be converted to the MPT format. It is mandatory 
// to define a "c2mpt_function", which will be the "main" of the test. Also
// include any related subroutines. The related subroutines have to be
// defined using the MPT_FUNCTION(signature) macro provided.
//
// The function signature for the main c2mpt_function should not be modified.
// It does not have any parameter. One can use global variables to pass parameters
// to the function (see the example).
//
/****************************************************************************/

MPT_FUNCTION(int64_t my_subroutine(int64_t X, int64_t Y, int64_t Z))

/****************************************************************************/
// Function implementation
//
// Include below the implementation of the routines defined above, which
// should be included in the mpt. They should not call functions not defined 
// here because the test should be self-contained to be reproduced safely.
//
// Remember to defined the "c2mpt_function" main function.
//
/****************************************************************************/

int64_t __attribute__ ((noinline)) my_subroutine(int64_t X, int64_t Y, int64_t Z)
{
    return Z + (X * Y);
}

void c2mpt_function()
{
    int i,j,k;

    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            matC[i][j]=0;
            for(k=0;k<N;k++){
                matC[i][j]=my_subroutine(matA[i][k], matB[k][j], matC[i][j]);
            }
        }
    }
}


/****************************************************************************/
// Initialization function 
//
// In case you need to initialize the global variables, you can do that in
// the function below. This function can use any external function
// including IO (e.g. reading values from disk) . This function will not
// be included the mpt.
//
// If you initialize variable pointers, they should point to addresses of 
// variables defined to be included in the MPT.
// 
/****************************************************************************/

void c2mpt_init_global_vars()
{ 
    for(int i=0; i < N; i++){
        for(int j=0; j < N; j++){
            matA[i][j] = i;
            matB[i][j] = j;
            matC[i][j] = i+j;
        }
    }
}

A linked list code example:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "c2mpt.h"

/****************************************************************************/
// Global variables
//
// Define in the section below the global variable to be used in the 
// "c2mpt_function" and its subroutines. Variable below are going to be
// imported to the mpt format. The variables have to be declared first
// and then, they have to be registered (see example below).
//
// The following macros are defined to declare variables:
//
// DECLARE_VARIABLE(type, name, alignment)
// DECLARE_VARIABLE_WITH_VALUE(type, name, alignment, init_value)
// DECLARE_VARIABLE_ARRAY(type, name, name+dimension, alignment)
// DECLARE_VARIABLE_ARRAY_WITH_VALUE(type, name, name+dimension alignment, init_value)
//
// where:
//
// - type: is the variable type (e.g. char)
// - name: is the variable name (e.g. myvar)
// - name+dimension: is the name of the array and the dimensions of the array 
//                   (e.g. myvar[10][20] )
// - alignment: is the minimum algnment for the variable                 
// - init_value: is the initial value
//
// The following macros are defined to register the variables:
//
// BEGIN_VARIABLE_REGISTRATION
// REGISTER_VARIABLE(name)
// END_VARIABLE_REGISTRATION
//
// where:
//
// - name: is the variable name to register
//
/****************************************************************************/

#define N 5

struct node {
      int64_t x;
      struct node *next;
};

typedef struct node node_t;
node_t array[N];

DECLARE_VARIABLE_ARRAY(node_t,linkedlist,linkedlist[N],sizeof(node_t))
DECLARE_VARIABLE_WITH_VALUE(int64_t,count,sizeof(int64_t), 0xCAFECAFE)

BEGIN_VARIABLE_REGISTRATION
REGISTER_VARIABLE(count)
REGISTER_VARIABLE(linkedlist)
END_VARIABLE_REGISTRATION

/****************************************************************************/
// Function declaration 
//
// Declare the functions to be converted to the MPT format. It is mandatory 
// to define a "c2mpt_function", which will be the "main" of the test. Also
// include any related subroutines. The related subroutines have to be
// defined using the MPT_FUNCTION(signature) macro provided.
//
// The function signature for the main c2mpt_function should not be modified.
// It does not have any parameter. One can use global variables to pass parameters
// to the function (see the example).
//
/****************************************************************************/

MPT_FUNCTION(void my_subroutine(int64_t count))

/****************************************************************************/
// Function implementation
//
// Include below the implementation of the routines defined above, which
// should be included in the mpt. They should not call functions not defined 
// here because the test should be self-contained to be reproduced safely.
//
// Remember to defined the "c2mpt_function" main function.
//
/****************************************************************************/

void c2mpt_function()
{

    node_t* node = & linkedlist[0];
    while(node->next != NULL)
    {
        node = node->next;
        count += node->x;
    }

    my_subroutine(count);

}

void my_subroutine(int64_t lcount)
{
    count=lcount+lcount;
}

/****************************************************************************/
// Initialization function 
//
// In case you need to initialize the global variables, you can do that in
// the function below. This function can use any external function
// including IO (e.g. reading values from disk) . This function will not
// be included the mpt.
//
// If you initialize variable pointers, they should point to addresses of 
// variables defined to be included in the MPT.
// 
/****************************************************************************/

void c2mpt_init_global_vars()
{ 
    for(int i=0; i < N; i++){
        linkedlist[i].x = 0x0102030405060708;
       
        if(i<N-1)
        {
            linkedlist[i].next = &(linkedlist[i+1]);
        }
        else
        {
            linkedlist[i].next = NULL;
        }
    }
}

Template

Copy and paste the following template (or use the --dump-c2mpt-template flag to get it) to start editing an empty C test format:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#include "c2mpt.h"

/****************************************************************************/
// Global variables
//
// Define in the section below the global variable to be used in the 
// "c2mpt_function" and its subroutines. Variables below are going to be
// imported to the mpt format. The variables have to be declared first
// and then they have to be registered (see example below).
//
// The following macros are defined to declare variables:
//
// DECLARE_VARIABLE(type, name, alignment)
// DECLARE_VARIABLE_WITH_VALUE(type, name, alignment, init_value)
// DECLARE_VARIABLE_ARRAY(type, name, name+dimension, alignment)
// DECLARE_VARIABLE_ARRAY_WITH_VALUE(type, name, name+dimension alignment, init_value)
//
// where:
//
// - type: is the variable type (e.g. char)
// - name: is the variable name (e.g. myvar)
// - name+dimension: is the name of the array and the dimensions of the array 
//                   (e.g. myvar[10][20] )
// - alignment: is the minimum algnment for the variable                 
// - init_value: is the initial value
//
// The following macros are defined to register the variables:
//
// BEGIN_VARIABLE_REGISTRATION
// REGISTER_VARIABLE(name)
// END_VARIABLE_REGISTRATION
//
// where:
//
// - name: is the variable name to register
//
// Example:
//
// #define N 10
//
// DECLARE_VARIABLE_ARRAY(int64_t,matA,matA[N][N],sizeof(int64_t))
// DECLARE_VARIABLE_ARRAY(int64_t,matB,matB[N][N],sizeof(int64_t))
// DECLARE_VARIABLE_ARRAY_WITH_VALUE(int64_t,matC,matC[N][N],sizeof(int64_t),
//                                   {[0][1]=2,[1][0]=1} )
//
// BEGIN_VARIABLE_REGISTRATION
// REGISTER_VARIABLE(matA)
// REGISTER_VARIABLE(matB)
// REGISTER_VARIABLE(matC)
// END_VARIABLE_REGISTRATION
//
/****************************************************************************/

<< DECLARE AND REGISTER YOUR VARIABLES HERE >>

/****************************************************************************/
// Subroutine declaration 
//
// Declare any subroutine to be included in the MPT generated using the 
// MPT_FUNCTION(signature) macro provided.
//
// Example:
//
// MPT_FUNCTION(int64_t my_subroutine(int64_t X, int64_t Y, int64_t Z))
//
/****************************************************************************/

<< DECLARE YOUR SUBROUTINES HERE >>

/****************************************************************************/
// Function implementation
//
// Include below the implementation of the routines defined above, which
// will be included in the MPT. They should not call functions that will not 
// be included in the MPT. That is, only call functions declared using the 
// MPT_FUNCTION macro.
//
// Remember to implement the "c2mpt_function", which will be the main test
// function.
//
/****************************************************************************/

void c2mpt_function()
{

    << IMPLEMENT THE MAIN FUNCTION HERE >>

}

<< IMPLEMENT ANY SUBROUTINES HERE >>

/****************************************************************************/
// Initialization function 
//
// In case you need to initialize the global variables, you can do that in
// the function below. This function can use any external function
// including IO (e.g. reading values from disk) . This function will not
// be included the MPT generated.
//
// If you initialize variable pointers, they should point to addresses of 
// variables defined to be included in the MPT.
// 
/****************************************************************************/

void c2mpt_init_global_vars()
{ 

    << INITIALIZE THE GLOBAL VARIABLES HERE >>
    
}

Implementation details

The following two files are compiled along the C test file provided as input by the user. Check them to understand the implementation details in case you want to debug the functionality:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <strings.h>
#include <string.h>
#include <assert.h>

typedef struct c2mpt_var {           
    char vartype[50];        
    char varname[50];       
    void * address;                
    uint_fast64_t nelems;         
    uint_fast64_t elems_size;    
    uint_fast64_t alignment;    
} c2mpt_var ;                  

void c2mpt_dump_data(void);

#define DECLARE_VARIABLE_ARRAY(type,name,array,alignment)                      \
    type array                                                                 \
        __attribute__ ((section ("microprobe.data")))                          \
        __attribute__ ((aligned (alignment)))                                  \
    ;                                                                          \
    c2mpt_var c2mpt_var_##name = { #type, #name,                               \
                                 (void * ) & name[0],                          \
                                        sizeof(name)/                          \
                                     sizeof(type),                             \
                                          alignment }; 

#define DECLARE_VARIABLE_ARRAY_WITH_VALUE(type,name,array,alignment, ...)      \
    type array                                                                 \
        __attribute__ ((section ("microprobe.data")))                          \
        __attribute__ ((aligned (alignment)))                                  \
    = __VA_ARGS__;                                                             \
    c2mpt_var c2mpt_var_##name = { #type, #name,                               \
                                 (void * ) & name[0],                          \
                                        sizeof(name)/                          \
                                     sizeof(type),                             \
                                          alignment }; 

#define DECLARE_VARIABLE(type,name,alignment)                                  \
    type name                                                                  \
        __attribute__ ((section ("microprobe.data")))                          \
        __attribute__ ((aligned (alignment)))                                  \
    ;                                                                          \
    c2mpt_var c2mpt_var_##name = { #type, #name,                               \
                                 (void * ) & name, 1,                          \
                                         sizeof(name),                         \
                                          alignment }; 

#define DECLARE_VARIABLE_WITH_VALUE(type,name,alignment, value)                \
    type name                                                                  \
        __attribute__ ((section ("microprobe.data")))                          \
        __attribute__ ((aligned (alignment)))                                  \
    = value;                                                                   \
    c2mpt_var c2mpt_var_##name = { #type, #name,                               \
                                 (void * ) & name, 1,                          \
                                         sizeof(name),                         \
                                          alignment }; 

#define BEGIN_VARIABLE_REGISTRATION                                            \
    c2mpt_var* c2mpt_vars[] = {                        

#define REGISTER_VARIABLE(name) &c2mpt_var_##name,
        
#define END_VARIABLE_REGISTRATION                                              \
    };                                                                         \
    extern void c2mpt_dump_var(c2mpt_var var);                                 \
    MPT_DUMP_FUNCTION 
    
#define MPT_FUNCTION(signature)                                                \
    signature                                                                  \
    __attribute__ ((section ("microprobe.text")));

MPT_FUNCTION(void c2mpt_function(void))

#define MPT_DUMP_FUNCTION                                                      \
    void c2mpt_dump_data(void)                                                 \
    {                                                                          \
        uint_fast64_t i = 0;                                                   \
        uint_fast64_t nvars = 0;                                               \
        nvars = sizeof(c2mpt_vars) / sizeof(c2mpt_vars[0]);                    \
        for(i=0; i < nvars; i++)                                               \
        {                                                                      \
            c2mpt_dump_var(*(c2mpt_vars[i]));                                  \
        }                                                                      \
    }                                                                          \

#ifndef MPT_BASE_ADDRESS
    #define MPT_BASE_ADDRESS 0x0
#endif
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#include "c2mpt.h"

extern c2mpt_var* c2mpt_vars; 
extern void c2mpt_function(void);
extern void c2mpt_dump_data(void);
extern void c2mpt_init_global_vars(void);

/****************************************************************************/
// Dump data functions
/****************************************************************************/

void c2mpt_print_value(void * value, uint_fast64_t size, char* vartype)
{
    // pointers
    if(index(vartype, '*') != NULL)
    {
        assert(size == sizeof(void *));
        printf("%p", value);
    }
    // C generic data types
    else if(strcasecmp(vartype, "char") == 0)
    {
        assert(size == sizeof(char));
        printf("%hhu", *((char *) value));
    }
    else if(strcasecmp(vartype, "signed char") == 0)
    {
        assert(size == sizeof(signed char));
        printf("%hhi", *((signed char *) value));
    }
    else if(strcasecmp(vartype, "unsigned char") == 0)
    {
        assert(size == sizeof(unsigned char));
        printf("%hhu", *((unsigned char *) value));
    }
    else if(strcasecmp(vartype, "short") == 0)
    {
        assert(size == sizeof(short));
        printf("%hi", *((short *) value));
    }
    else if(strcasecmp(vartype, "short int") == 0)
    {
        assert(size == sizeof(short int));
        printf("%hi", *((short int *) value));
    }
    else if(strcasecmp(vartype, "signed short") == 0)
    {
        assert(size == sizeof(signed short));
        printf("%hi", *((signed short *) value));
    }
    else if(strcasecmp(vartype, "signed short int") == 0)
    {
        assert(size == sizeof(signed short int));
        printf("%hi", *((signed short int *) value));
    }
    else if(strcasecmp(vartype, "unsigned short") == 0)
    {
        assert(size == sizeof(unsigned short));
        printf("%hu", *((unsigned short *) value));
    }
    else if(strcasecmp(vartype, "unsigned short int") == 0)
    {
        assert(size == sizeof(unsigned short int));
        printf("%hu", *((unsigned short int *) value));
    }
    else if(strcasecmp(vartype, "int") == 0)
    {
        assert(size == sizeof(int));
        printf("%d", *((int *) value));
    }
    else if(strcasecmp(vartype, "signed") == 0)
    {
        assert(size == sizeof(signed));
        printf("%d", *((signed *) value));
    }
    else if(strcasecmp(vartype, "signed int") == 0)
    {
        assert(size == sizeof(signed int));
        printf("%d", *((signed int *) value));
    }
    else if(strcasecmp(vartype, "unsigned") == 0)
    {
        assert(size == sizeof(unsigned));
        printf("%u", *((unsigned *) value));
    }
    else if(strcasecmp(vartype, "unsigned int") == 0)
    {
        assert(size == sizeof(unsigned int));
        printf("%u", *((unsigned int *) value));
    }
    else if(strcasecmp(vartype, "long") == 0)
    {
        assert(size == sizeof(long));
        printf("%li", *((long *) value));
    }
    else if(strcasecmp(vartype, "long int") == 0)
    {
        assert(size == sizeof(long int));
        printf("%li", *((long int *) value));
    }
    else if(strcasecmp(vartype, "signed long") == 0)
    {
        assert(size == sizeof(signed long));
        printf("%li", *((signed long *) value));
    }
    else if(strcasecmp(vartype, "signed long int") == 0)
    {
        assert(size == sizeof(signed long int));
        printf("%li", *((signed long int *) value));
    }
    else if(strcasecmp(vartype, "unsigned long") == 0)
    {
        assert(size == sizeof(unsigned long));
        printf("%lu", *((unsigned long *) value));
    }
    else if(strcasecmp(vartype, "unsigned long int") == 0)
    {
        assert(size == sizeof(unsigned long int));
        printf("%lu", *((unsigned long int *) value));
    }
    else if(strcasecmp(vartype, "long long") == 0)
    {
        assert(size == sizeof(long long));
        printf("%lli", *((long long *) value));
    }
    else if(strcasecmp(vartype, "long long int") == 0)
    {
        assert(size == sizeof(long long int));
        printf("%lli", *((long long int *) value));
    }
    else if(strcasecmp(vartype, "signed long long") == 0)
    {
        assert(size == sizeof(signed long long));
        printf("%lli", *((signed long long *) value));
    }
    else if(strcasecmp(vartype, "signed long long int") == 0)
    {
        assert(size == sizeof(signed long long int));
        printf("%lli", *((signed long long int *) value));
    }
    else if(strcasecmp(vartype, "float") == 0)
    {
        assert(size == sizeof(float));
        printf("%f", *((float *) value));
    }
    else if(strcasecmp(vartype, "double") == 0)
    {
        assert(size == sizeof(double));
        printf("%f", *((double *) value));
    }
    else if(strcasecmp(vartype, "long double") == 0)
    {
        assert(size == sizeof(long double));
        printf("%Lf", *((long double *) value));
    }
    // C width fixed data types
    else if(strcasecmp(vartype, "int8_t") == 0)
    {
        assert(size == sizeof(int8_t));
        printf("%hhi", *((int8_t *) value));
    }
    else if(strcasecmp(vartype, "int_least8_t") == 0)
    {
        assert(size == sizeof(int_least8_t));
        printf("%"PRIdLEAST8, *((int_least8_t *) value));
    }
    else if(strcasecmp(vartype, "int_fast8_t") == 0)
    {
        assert(size == sizeof(int_fast8_t));
        printf("%"PRIdFAST8, *((int_fast8_t *) value));
    }
    else if(strcasecmp(vartype, "uint8_t") == 0)
    {
        assert(size == sizeof(uint8_t));
        printf("%hhu", *((uint8_t *) value));
    }
    else if(strcasecmp(vartype, "uint_least8_t") == 0)
    {
        assert(size == sizeof(uint_least8_t));
        printf("%"PRIuLEAST8, *((uint_least8_t *) value));
    }
    else if(strcasecmp(vartype, "uint_fast8_t") == 0)
    {
        assert(size == sizeof(uint_fast8_t));
        printf("%"PRIuFAST8, *((uint_fast8_t *) value));
    }
    else if(strcasecmp(vartype, "int16_t") == 0)
    {
        assert(size == sizeof(int16_t));
        printf("%hi", *((int16_t *) value));
    }
    else if(strcasecmp(vartype, "int_least16_t") == 0)
    {
        assert(size == sizeof(int_least16_t));
        printf("%"PRIdLEAST16, *((int_least16_t *) value));
    }
    else if(strcasecmp(vartype, "int_fast16_t") == 0)
    {
        assert(size == sizeof(int_fast16_t));
        printf("%"PRIdFAST16, *((int_fast16_t *) value));
    }
    else if(strcasecmp(vartype, "uint16_t") == 0)
    {
        assert(size == sizeof(uint16_t));
        printf("%hu", *((uint16_t *) value));
    }
    else if(strcasecmp(vartype, "uint_least16_t") == 0)
    {
        assert(size == sizeof(uint_least16_t));
        printf("%"PRIuLEAST16, *((uint_least16_t *) value));
    }
    else if(strcasecmp(vartype, "uint_fast16_t") == 0)
    {
        assert(size == sizeof(uint_fast16_t));
        printf("%"PRIuFAST16, *((uint_fast16_t *) value));
    }
    else if(strcasecmp(vartype, "int32_t") == 0)
    {
        assert(size == sizeof(int32_t));
        printf("%d", *((int32_t *) value));
    }
    else if(strcasecmp(vartype, "int_least32_t") == 0)
    {
        assert(size == sizeof(int_least32_t));
        printf("%"PRIdLEAST32, *((int_least32_t *) value));
    }
    else if(strcasecmp(vartype, "int_fast32_t") == 0)
    {
        assert(size == sizeof(int_fast32_t));
        printf("%"PRIdFAST32, *((int_fast32_t *) value));
    }
    else if(strcasecmp(vartype, "uint32_t") == 0)
    {
        assert(size == sizeof(uint32_t));
        printf("%u", *((uint32_t *) value));
    }
    else if(strcasecmp(vartype, "uint_least32_t") == 0)
    {
        assert(size == sizeof(uint_least32_t));
        printf("%"PRIuLEAST32, *((uint_least32_t *) value));
    }
    else if(strcasecmp(vartype, "uint_fast32_t") == 0)
    {
        assert(size == sizeof(uint_fast32_t));
        printf("%"PRIdFAST32, *((uint_fast32_t *) value));
    }
    else if(strcasecmp(vartype, "int64_t") == 0)
    {
        assert(size == sizeof(int64_t));
        printf("%li", *((int64_t *) value));
    }
    else if(strcasecmp(vartype, "int_least64_t") == 0)
    {
        assert(size == sizeof(int_least64_t));
        printf("%"PRIdLEAST64, *((int_least64_t *) value));
    }
    else if(strcasecmp(vartype, "int_fast64_t") == 0)
    {
        assert(size == sizeof(int_fast64_t));
        printf("%"PRIdFAST64, *((int_fast64_t *) value));
    }
    else if(strcasecmp(vartype, "uint64_t") == 0)
    {
        assert(size == sizeof(uint64_t));
        printf("%lu", *((uint64_t *) value));
    }
    else if(strcasecmp(vartype, "uint_least64_t") == 0)
    {
        assert(size == sizeof(uint_least64_t));
        printf("%"PRIuLEAST64, *((uint_least64_t *) value));
    }
    else if(strcasecmp(vartype, "uint_fast64_t") == 0)
    {
        assert(size == sizeof(uint_fast64_t));
        printf("%"PRIuFAST64, *((uint_fast64_t *) value));
    }
    // Fall back to char 
    else
    {
        for(int i=0; i < size; i++)
        {
            if ((i>0) && (i < size)) printf(", ");
            printf("%hhu", *((char *) value));
            value = (void *) ((uint64_t) value + sizeof(char));
        }
    }

}

void c2mpt_fix_vartype(char* fix_vartype, char* vartype)
{
    if((index(vartype, '*') != NULL)||
    (strcasecmp(vartype, "char") == 0)||
    (strcasecmp(vartype, "signed char") == 0)||
    (strcasecmp(vartype, "unsigned char") == 0)||
    (strcasecmp(vartype, "short") == 0)||
    (strcasecmp(vartype, "short int") == 0)||
    (strcasecmp(vartype, "signed short") == 0)||
    (strcasecmp(vartype, "signed short int") == 0)||
    (strcasecmp(vartype, "unsigned short") == 0)||
    (strcasecmp(vartype, "unsigned short int") == 0)||
    (strcasecmp(vartype, "int") == 0)||
    (strcasecmp(vartype, "signed") == 0)||
    (strcasecmp(vartype, "signed int") == 0)||
    (strcasecmp(vartype, "unsigned") == 0)||
    (strcasecmp(vartype, "unsigned int") == 0)||
    (strcasecmp(vartype, "long") == 0)||
    (strcasecmp(vartype, "long int") == 0)||
    (strcasecmp(vartype, "signed long") == 0)||
    (strcasecmp(vartype, "signed long int") == 0)||
    (strcasecmp(vartype, "unsigned long") == 0)||
    (strcasecmp(vartype, "unsigned long int") == 0)||
    (strcasecmp(vartype, "long long") == 0)||
    (strcasecmp(vartype, "long long int") == 0)||
    (strcasecmp(vartype, "signed long long") == 0)||
    (strcasecmp(vartype, "signed long long int") == 0)||
    (strcasecmp(vartype, "float") == 0)||
    (strcasecmp(vartype, "double") == 0)||
    (strcasecmp(vartype, "long double") == 0)||
    (strcasecmp(vartype, "int8_t") == 0)||
    (strcasecmp(vartype, "int_least8_t") == 0)||
    (strcasecmp(vartype, "int_fast8_t") == 0)||
    (strcasecmp(vartype, "uint8_t") == 0)||
    (strcasecmp(vartype, "uint_least8_t") == 0)||
    (strcasecmp(vartype, "uint_fast8_t") == 0)||
    (strcasecmp(vartype, "int16_t") == 0)||
    (strcasecmp(vartype, "int_least16_t") == 0)||
    (strcasecmp(vartype, "int_fast16_t") == 0)||
    (strcasecmp(vartype, "uint16_t") == 0)||
    (strcasecmp(vartype, "uint_least16_t") == 0)||
    (strcasecmp(vartype, "uint_fast16_t") == 0)||
    (strcasecmp(vartype, "int32_t") == 0)||
    (strcasecmp(vartype, "int_least32_t") == 0)||
    (strcasecmp(vartype, "int_fast32_t") == 0)||
    (strcasecmp(vartype, "uint32_t") == 0)||
    (strcasecmp(vartype, "uint_least32_t") == 0)||
    (strcasecmp(vartype, "uint_fast32_t") == 0)||
    (strcasecmp(vartype, "int64_t") == 0)||
    (strcasecmp(vartype, "int_least64_t") == 0)||
    (strcasecmp(vartype, "int_fast64_t") == 0)||
    (strcasecmp(vartype, "uint64_t") == 0)||
    (strcasecmp(vartype, "uint_least64_t") == 0)||
    (strcasecmp(vartype, "uint_fast64_t") == 0))
    {
        strcpy(fix_vartype, vartype);
    }
    else
    {
        strcpy(fix_vartype, "uint8_t");
    }

}


void c2mpt_dump_var(c2mpt_var var)
{
    uint_fast64_t i = 0;
    uint_fast64_t multiplier = 1;

    void * cval;
    char fix_vartype[50];        

    c2mpt_fix_vartype(fix_vartype, var.vartype);

    if(strcasecmp(fix_vartype, var.vartype) != 0)
    {
        printf("WARNING: Variable '%s' is not a base type ('%s'). You might"
                " hit endianness issues if the host and target platforms"
                " have different endianness. Double check your initialization"
                " data in the generated MPT file\n",
                var.varname, var.vartype);
        multiplier = var.elems_size;

    }


    #if __64BIT__ ||  __x86_64__ || __ppc64__ || __aarch64__ || __powerpc64__ || __s390x__
        printf("%s = [ \"%s\", %"PRIu64", 0x%"PRIx64", %"PRIu64", ", 
                var.varname, fix_vartype, var.nelems * multiplier,
                (uint64_t) var.address - (uint64_t) MPT_BASE_ADDRESS, 
                var.alignment);
    #else
	printf("%s = [ \"%s\", %"PRIu64", 0x%"PRIx32", %"PRIu64", ", 
                var.varname, fix_vartype, var.nelems * multiplier,
                (uint32_t) var.address - (uint64_t) MPT_BASE_ADDRESS,
                var.alignment);
    #endif

    if (var.nelems > 1)
    {
        printf("[ ");
    }

    cval = (void *) var.address;
    for(i=0; i < var.nelems; i++) 
    {
        if ((i>0) && (i < var.nelems)) printf(", ");
        c2mpt_print_value(cval, var.elems_size, var.vartype);
        cval = (void *) ((uint_fast64_t) cval + var.elems_size);
    }

    if (var.nelems > 1)
    {
    printf(" ]");
    }

    printf(" ]\n");

}

/****************************************************************************/
// Main c2mpt function
/****************************************************************************/

int main(int argc, char** argv)
{
    c2mpt_init_global_vars();
    c2mpt_dump_data();
    c2mpt_function();
    exit(0);
}