openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

cint_test_data.c (22136B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        cint_test_data.c
      8  * Purpose:     CINT test data
      9  */
     10 
     11 /***********************************************************************
     12  *
     13  * CINT Test Datatypes
     14  */
     15 
     16 #include "cint_config.h"
     17 #include "cint_porting.h"
     18 #include "cint_interpreter.h"
     19 #include "cint_internal.h"
     20 
     21 /*
     22  * Definitions for the test data
     23  */
     24 #if CINT_CONFIG_INCLUDE_LONGLONGS == 1
     25 
     26 #define CT_LONGLONG long long
     27 #define CT_ULONGLONG unsigned long long
     28 
     29 #else
     30 
     31 #define CT_LONGLONG int
     32 #define CT_ULONGLONG unsigned int
     33 
     34 #endif
     35 
     36 #if CINT_CONFIG_INCLUDE_DOUBLES == 1
     37 #define CT_DOUBLE double
     38 #else
     39 #define CT_DOUBLE int
     40 #endif
     41 
     42 #define _CT_STRINGIFY(t) #t
     43 #define CT_STRINGIFY(t) _CT_STRINGIFY(t)
     44 
     45 /*************************************************************
     46  *
     47  * Atomic Datatypes
     48  */
     49 
     50 /*
     51  * Implements a simple bitmap interface. 
     52  */
     53 
     54 typedef unsigned int ct_bitmap_t; 
     55 
     56 static int
     57 __ct_print_ct_bitmap_t(void* p, char* dst, int size, cint_atomic_format_t format)
     58 {
     59     unsigned int m = *((unsigned int*)p); 
     60     unsigned int i;
     61     
     62     switch(format)
     63         {
     64         case cintAtomicFormatCintPrintVariable:
     65         case cintAtomicFormatCintPrintf:
     66         default:
     67             {
     68                 cint_snprintf_ex(&dst, &size, "{ "); 
     69                 for(i = (1 << (sizeof(m)*8 - 1)); i != 1; i>>=1) {
     70                     cint_snprintf_ex(&dst, &size, "%d,", (m&i) ? 1 : 0); 
     71                 }
     72                 cint_snprintf_ex(&dst, &size, "%d }", m&1); 
     73             }   
     74         }
     75     return 0; 
     76 }
     77 
     78 static int
     79 __ct_assign_ct_bitmap_t(void* dst, const char* expr)
     80 {
     81     const char* s; 
     82     unsigned int bmap = 0; 
     83 
     84     for(s = expr; s && *s; s++) {
     85         if(*s == '1' || *s == '0') {
     86             bmap <<= 1; 
     87             bmap |= (*s) - '0'; 
     88         }
     89         else if(*s != ' ') {
     90             return CINT_E_BAD_EXPRESSION; 
     91         }
     92     }
     93     *((unsigned int*)dst) = bmap; 
     94     return CINT_E_NONE; 
     95 }
     96 
     97 
     98 static int
     99 __ct_print_ct_array_t(void* src, char* dst, int size, cint_atomic_format_t format)
    100 {
    101     unsigned int* a = (unsigned int*)src; 
    102     int i; 
    103     
    104     switch(format)
    105         {
    106         case cintAtomicFormatCintPrintVariable:
    107         case cintAtomicFormatCintPrintf:
    108         default:
    109             {
    110                 for(i = 0; i < 15; i++) {
    111                     cint_snprintf_ex(&dst, &size, "%d:", a[i]); 
    112                 }
    113                 cint_snprintf_ex(&dst, &size, "%d", a[i]); 
    114             }   
    115         }       
    116     return 0; 
    117 }     
    118 
    119 static int
    120 __ct_assign_ct_array_t(void* dst, const char* expr)
    121 {
    122     unsigned int* p = (unsigned int*)dst; 
    123     /* Don't care about expression, just for testing purposes */
    124     int i; 
    125     for(i = 0; i < 16; i++) {
    126         p[i] = i; 
    127     }
    128     return 0; 
    129 }
    130    
    131 
    132 
    133 /*
    134  * Atomic datatype description table
    135  */
    136 static cint_atomic_type_t __ct_atomics[] = 
    137     {        
    138         {
    139             "ct_bitmap_t", 
    140             sizeof(unsigned int), 
    141             0, 
    142             __ct_print_ct_bitmap_t, 
    143             __ct_assign_ct_bitmap_t, 
    144         },
    145         {
    146             "ct_array_t", 
    147             0, 
    148             CINT_ATOMIC_TYPE_F_CAP_ONLY, 
    149             __ct_print_ct_array_t, 
    150             __ct_assign_ct_array_t, 
    151         },             
    152         { NULL }, 
    153     }; 
    154 
    155 
    156 /*************************************************************
    157  * 
    158  * Enumerations
    159  */
    160 
    161 typedef enum ct_enum_e {
    162     ctEnum0 = 0, 
    163     ctEnum1,
    164     ctEnum2, 
    165     ctEnum3
    166 } ct_enum_t; 
    167 
    168 /*
    169  * Enum map
    170  */
    171 static cint_enum_map_t __ct_enum_map__ct_enum_t[] = 
    172 {
    173     { "ctEnum0", ctEnum0 },
    174     { "ctEnum1", ctEnum1 },
    175     { "ctEnum2", ctEnum2 },
    176     { "ctEnum3", ctEnum3 },
    177     { NULL }
    178 };
    179      
    180 /*
    181  * Enumeration datatype description table
    182  */
    183 static cint_enum_type_t __ct_enums[] =
    184 {   
    185     { "ct_enum_t", __ct_enum_map__ct_enum_t }, 
    186     { NULL }
    187 }; 
    188 
    189 
    190 
    191 /*************************************************************
    192  *
    193  * Structures
    194  */
    195 
    196 typedef struct ct_struct_s {
    197     char c;
    198     unsigned char uc; 
    199     short s;
    200     unsigned short us;
    201     int i; 
    202     unsigned int ui; 
    203     long l; 
    204     unsigned long ul; 
    205     CT_LONGLONG ll; 
    206     CT_ULONGLONG ull; 
    207     CT_DOUBLE d;     
    208     int* ip; 
    209     void* vp; 
    210 
    211     char cbuffer[16]; 
    212     int** pbuffer[8];
    213 
    214     ct_bitmap_t bitmap; 
    215 
    216 } ct_struct_t; 
    217     
    218 typedef struct ct_struct_simple_t {
    219     int x;
    220     ct_struct_t ct_struct; 
    221     ct_bitmap_t bitmap; 
    222     ct_struct_t ct_structs[2]; 
    223 } ct_struct_simple_t; 
    224 
    225 /*
    226  * Description of structure parameters
    227  */
    228 static cint_parameter_desc_t 
    229 __ct_struct_members__ct_struct_t[] = 
    230     {
    231         { "char", "c", 0, 0 }, 
    232         { "unsigned char", "uc", 0, 0 }, 
    233         { "short", "s", 0, 0 }, 
    234         { "unsigned short", "us", 0, 0 }, 
    235         { "int", "i", 0, 0 }, 
    236         { "unsigned int", "ui", 0, 0 }, 
    237         { "long", "l", 0, 0 }, 
    238         { "unsigned long", "ul", 0, 0 }, 
    239         { CT_STRINGIFY(CT_LONGLONG), "ll", 0, 0 }, 
    240         { CT_STRINGIFY(CT_ULONGLONG), "ull", 0, 0 }, 
    241         { CT_STRINGIFY(CT_DOUBLE), "d", 0, 0 }, 
    242         { "int", "ip", 1, 0 }, 
    243         { "void", "vp", 1, 0 }, 
    244         { "char", "cbuffer", 0, 16 }, 
    245         { "int", "pbuffer", 2, 8 }, 
    246         { "ct_bitmap_t", "bitmap", 0, 0 }, 
    247         
    248         { NULL }
    249     }; 
    250         
    251 static cint_parameter_desc_t 
    252 __ct_struct_members__ct_struct_simple_t[] =   
    253     {
    254         { "int", "x", 0, 0 }, 
    255         { "ct_struct_t", "ct_struct", 0, 0 }, 
    256         { "ct_bitmap_t", "bitmap", 0, 0 }, 
    257         { "ct_struct_t", "ct_structs", 0, 2 }, 
    258         
    259         { NULL }
    260     }; 
    261 
    262 /*
    263  * Member address handlers
    264  */
    265 static void*
    266 __ct_maddr__ct_struct_t(void* p, int mnum, cint_struct_type_t* parent)
    267 {
    268     void* rv;
    269     ct_struct_t* s = (ct_struct_t*) p;
    270 
    271     switch(mnum)
    272         {
    273         case 0: rv = &(s->c); break;
    274         case 1: rv = &(s->uc); break;
    275         case 2: rv = &(s->s); break;
    276         case 3: rv = &(s->us); break;
    277         case 4: rv = &(s->i); break;
    278         case 5: rv = &(s->ui); break;
    279         case 6: rv = &(s->l); break;
    280         case 7: rv = &(s->ul); break;
    281         case 8: rv = &(s->ll); break; 
    282         case 9: rv = &(s->ull); break; 
    283         case 10: rv = &(s->d); break; 
    284         case 11: rv = &(s->ip); break;
    285         case 12: rv = &(s->vp); break;
    286         case 13: rv = s->cbuffer; break;
    287         case 14: rv = s->pbuffer; break;
    288         case 15: rv = &(s->bitmap); break; 
    289         default: rv = NULL; break;
    290         }
    291 
    292     return rv;
    293 }
    294 
    295 static void*
    296 __ct_maddr__ct_struct_simple_t(void* p, int mnum, cint_struct_type_t* parent)
    297 {
    298     void* rv;
    299     ct_struct_simple_t* s = (ct_struct_simple_t*) p;
    300 
    301     switch(mnum)
    302         {
    303         case 0: rv = &(s->x); break; 
    304         case 1: rv = &(s->ct_struct); break; 
    305         case 2: rv = &(s->bitmap); break; 
    306         case 3: rv = s->ct_structs; break;      
    307         default: rv = NULL; break; 
    308         }
    309     return rv; 
    310 }
    311 
    312 
    313 /*
    314  * Structure datatype description table
    315  */
    316 static cint_struct_type_t __ct_structures[] = 
    317 {
    318     {
    319         "ct_struct_t", 
    320         sizeof(ct_struct_t), 
    321         __ct_struct_members__ct_struct_t,
    322         __ct_maddr__ct_struct_t
    323     }, 
    324     {
    325         "ct_struct_simple_t", 
    326         sizeof(ct_struct_simple_t), 
    327         __ct_struct_members__ct_struct_simple_t, 
    328         __ct_maddr__ct_struct_simple_t
    329     },
    330 
    331     { NULL }
    332 };
    333     
    334 
    335 /*************************************************************
    336  *
    337  * Functions
    338  */
    339 
    340 static void
    341 ct_void_void_function(void)
    342 {
    343     CINT_PRINTF("__ct_void_void_function\n"); 
    344 }
    345 
    346 static void
    347 ct_void_int_function(int x)
    348 {
    349     CINT_PRINTF("__ct_void_int_function: %d\n", x); 
    350 }
    351 
    352 static int
    353 ct_int_int_function(int x)
    354 {
    355     CINT_PRINTF("__ct_int_int_function: %d\n", x); 
    356     return 100; 
    357 }
    358 
    359 static ct_enum_t
    360 ct_kitchen_sink(char c, 
    361                   short s, 
    362                   int i, 
    363                   const char* str, 
    364                   ct_enum_t e, 
    365                   ct_bitmap_t b, 
    366                   ct_struct_t* sp)
    367 
    368 {
    369     char fbuffer[256]; 
    370 
    371     CINT_PRINTF("__ct_kitchen_sink ENTER\n"); 
    372     CINT_PRINTF("c=%d 0x%x\n", c, c); 
    373     CINT_PRINTF("s=%hd 0x%hx\n", s, s); 
    374     CINT_PRINTF("i=%d 0x%x\n", i, i); 
    375     CINT_PRINTF("str=%s\n", str); 
    376     CINT_PRINTF("e=%d\n", e); 
    377     CINT_PRINTF("b = "); 
    378 
    379     __ct_print_ct_bitmap_t(&b, fbuffer, sizeof(fbuffer), 0); 
    380     CINT_PRINTF("%s\n", fbuffer); 
    381     
    382     if(sp) {
    383         CINT_PRINTF("sp->bitmap = "); 
    384         __ct_print_ct_bitmap_t(&sp->bitmap, fbuffer, sizeof(fbuffer), 0); 
    385         CINT_PRINTF("%s\n", fbuffer); 
    386     }   
    387     CINT_PRINTF("__ct_kitchen_sink EXIT\n"); 
    388     return ctEnum1;
    389 }
    390 
    391 typedef void (*ct_callback0_f)(void); 
    392 typedef ct_enum_t (*ct_kitchen_sink_callback_f)(char, short, int, const char*, ct_enum_t, ct_bitmap_t, ct_struct_t*); 
    393 
    394 static void
    395 ct_function_callbacker0(int x, ct_callback0_f cb)
    396 {
    397     CINT_PRINTF("__ct_function_callbacker ENTER\n"); 
    398     CINT_PRINTF("x=%d\n", x); 
    399     if(cb) {
    400         cb(); 
    401     }   
    402     else {
    403         CINT_PRINTF("cb is NULL\n"); 
    404     }   
    405     CINT_PRINTF("__ct_function_callbacker EXIT\n"); 
    406 }       
    407 
    408 static ct_enum_t
    409 ct_kitchen_sink_callbacker(int x, ct_kitchen_sink_callback_f cb)
    410 {
    411     ct_enum_t rc = 0; 
    412     ct_struct_t sp; 
    413     CINT_MEMSET(&sp, 0, sizeof(sp)); 
    414     sp.bitmap = 0xA5; 
    415 
    416     CINT_PRINTF("__ct_kitchen_sink_callbacker ENTER\n"); 
    417     CINT_PRINTF("x = %d\n", x); 
    418     if(cb == NULL) {
    419         CINT_PRINTF("cb = NULL\n"); 
    420     }
    421     else {
    422         rc = cb(1, 2, 3, "4", 0, 0xA5, &sp); 
    423         CINT_PRINTF("rc = %d\n", rc); 
    424     }          
    425     CINT_PRINTF("__ct_kitchen_sink_callbacker EXIT\n"); 
    426     return rc; 
    427 }
    428 
    429 static void
    430 ct_compiled_callback0(void)
    431 {
    432     CINT_PRINTF("__ct_compiled_callback0 ENTER\n"); 
    433     CINT_PRINTF("__ct_compiled_callback0 EXIT\n"); 
    434 }
    435 
    436 static int __ct_event_handler1(void* cookie, cint_interpreter_event_t event)
    437 {
    438     CINT_PRINTF("event_handler1: event=%d cookie=%p\n", event, cookie); 
    439     return 0;         
    440 }
    441 static int __ct_event_handler2(void* cookie, cint_interpreter_event_t event)
    442 {
    443     CINT_PRINTF("event_handler2: event=%d cookie=%p\n", event, cookie); 
    444     return 0;         
    445 }
    446 
    447 static int __ct_init_handler1(void* cookie)
    448 {
    449     return 0;         
    450 }
    451 
    452 static int __ct_init_handler2(void* cookie)
    453 {
    454     return 0;         
    455 }
    456 
    457 static int __ct_init_handler3(void* cookie)
    458 {
    459     return 0;         
    460 }
    461 
    462 static void 
    463 ct_test_handlers(void)
    464 {
    465     CINT_PRINTF("START\n");
    466     /* event */
    467     cint_interpreter_event_register(__ct_event_handler1, (void*)1); 
    468     cint_interpreter_event(cintEventNone); 
    469     cint_interpreter_event_register(__ct_event_handler2, (void*)2); 
    470     cint_interpreter_event(cintEventNone); 
    471     cint_interpreter_event_unregister(__ct_event_handler1); 
    472     cint_interpreter_event(cintEventNone); 
    473     cint_interpreter_event_unregister(__ct_event_handler1); 
    474     cint_interpreter_event(cintEventNone); 
    475     cint_interpreter_event_unregister(__ct_event_handler2); 
    476     CINT_PRINTF("NO MORE EVENT HANDLERS\n"); 
    477     cint_interpreter_event(cintEventNone);
    478 
    479     /* init */
    480     cint_interpreter_initialize_register(__ct_init_handler1, (void*)1);
    481     cint_interpreter_initialize_register(__ct_init_handler2, (void*)2);
    482     cint_interpreter_initialize_register(__ct_init_handler3, NULL);
    483     cint_interpreter_initialize_unregister(__ct_init_handler2, NULL);
    484     cint_interpreter_initialize_unregister(__ct_init_handler2, (void*)2);
    485     cint_interpreter_initialize_unregister(__ct_init_handler3, NULL);
    486     cint_interpreter_initialize_unregister(__ct_init_handler1, (void*)1);
    487     cint_interpreter_initialize_unregister(__ct_init_handler1, (void*)1);
    488     cint_interpreter_initialize_unregister(NULL, NULL);
    489     CINT_PRINTF("NO MORE INIT HANDLERS\n"); 
    490     
    491     CINT_PRINTF("DONE\n"); 
    492 }       
    493 
    494 static int
    495 __ct_reset_handler(void* cookie, cint_interpreter_event_t event)
    496 {
    497     CINT_PRINTF("RESET HANDLER: cookie=%p, event=%d\n", cookie, event); 
    498     return 0; 
    499 }
    500 
    501 
    502 static void
    503 ct_install_reset_handler(void)
    504 {
    505     cint_interpreter_event_register(__ct_reset_handler, (void*)1); 
    506 }
    507 
    508 
    509 /*
    510  * Function Wrappers
    511  */
    512 CINT_FWRAPPER_CREATE_VP0(ct_install_reset_handler);
    513  
    514 CINT_FWRAPPER_CREATE_VP0(ct_test_handlers); 
    515 
    516 CINT_FWRAPPER_CREATE_VP0(ct_void_void_function); 
    517 
    518 CINT_FWRAPPER_CREATE_VP1(ct_void_int_function, 
    519                          int,int,x,0,0);
    520 
    521 CINT_FWRAPPER_CREATE_RP1(int,int,0,0,
    522                          ct_int_int_function,
    523                          int,int,x,0,0); 
    524 
    525 CINT_FWRAPPER_CREATE_RP7(ct_enum_t,ct_enum_t,0,0,
    526                          ct_kitchen_sink,
    527                          char,char,c,0,0,
    528                          short,short,s,0,0,
    529                          int,int,i,0,0,
    530                          char*,char,str,1,0,
    531                          ct_enum_t,ct_enum_t,e,0,0,
    532                          ct_bitmap_t,ct_bitmap_t,b,0,0,
    533                          ct_struct_t*,ct_struct_t,sp,1,0);
    534 
    535 CINT_FWRAPPER_CREATE_VP2(ct_function_callbacker0,
    536                          int,int,x,0,0,
    537                          ct_callback0_f,ct_callback0_f,cb,0,0);
    538 
    539 CINT_FWRAPPER_CREATE_VP0(ct_compiled_callback0);
    540 
    541 CINT_FWRAPPER_CREATE_RP2(ct_enum_t, ct_enum_t, 0, 0,
    542                          ct_kitchen_sink_callbacker,
    543                          int,int,x,0,0,
    544                          ct_kitchen_sink_callback_f,ct_kitchen_sink_callback_f,cb,0,0); 
    545 
    546 #define CT_BITMAP_MEMBER(bp,pos) ((bp) & (1<<pos))
    547 
    548 static int __CT_BITMAP_MEMBER(ct_bitmap_t* bp, int* pos)
    549 {
    550     return CT_BITMAP_MEMBER(*bp,*pos); 
    551 }
    552 
    553 CINT_FWRAPPER_CREATE_RP2(int,int,0,0,
    554                          __CT_BITMAP_MEMBER,
    555                          ct_bitmap_t*,ct_bitmap_t,bp,1,0,
    556                          int*,int,pos,1,0); 
    557     
    558 typedef int (*ct_void_parameter_callback_f)(void);
    559  
    560 static int
    561 __ct_void_callbacker(ct_void_parameter_callback_f test) {
    562     return test();
    563 }
    564  
    565 CINT_FWRAPPER_CREATE2_RP1(int, int, 0, 0,
    566                           __ct_void_callbacker,
    567                           ct_void_parameter_callback_f,
    568                           ct_void_parameter_callback_f,
    569                           test, 0, 0, CINT_PARAM_INOUT);
    570 
    571 /*
    572  * Function datatype description table
    573  */
    574 static cint_function_t __ct_functions[] = 
    575     {
    576         CINT_FWRAPPER_ENTRY(ct_install_reset_handler),
    577         CINT_FWRAPPER_ENTRY(ct_test_handlers), 
    578         CINT_FWRAPPER_ENTRY(ct_void_void_function), 
    579         CINT_FWRAPPER_ENTRY(ct_void_int_function),
    580         CINT_FWRAPPER_ENTRY(ct_int_int_function),
    581         CINT_FWRAPPER_ENTRY(ct_kitchen_sink),
    582         CINT_FWRAPPER_ENTRY(ct_function_callbacker0),
    583         CINT_FWRAPPER_ENTRY(ct_compiled_callback0),
    584         CINT_FWRAPPER_ENTRY(ct_kitchen_sink_callbacker),
    585         CINT_FWRAPPER_NENTRY("CT_BITMAP_MEMBER", __CT_BITMAP_MEMBER),
    586         CINT_FWRAPPER_NENTRY("ct_void_callbacker", __ct_void_callbacker),
    587         CINT_ENTRY_LAST
    588     }; 
    589 
    590 
    591 
    592 /*************************************************************
    593  * 
    594  * Function Pointers
    595  */
    596 static cint_function_pointer_t __ct_function_pointers[4]; 
    597 
    598 static void
    599 __ct_callback_handler0(void)
    600 {
    601     cint_interpreter_callback(__ct_function_pointers+0, 0, 0); 
    602 }
    603 
    604 static ct_enum_t
    605 __ct_kitchen_sink_callback(char c, 
    606                            short s, 
    607                            int i, 
    608                            const char* str, 
    609                            ct_enum_t e, 
    610                            ct_bitmap_t b, 
    611                            ct_struct_t* sp)
    612      
    613 {
    614     ct_enum_t rc; 
    615     cint_interpreter_callback(__ct_function_pointers+1, 
    616                               7, 1, 
    617                               &c, 
    618                               &s, 
    619                               &i, 
    620                               &str, 
    621                               &e, 
    622                               &b, 
    623                               &sp, 
    624                               &rc); 
    625     return rc; 
    626 }
    627 
    628 /*
    629  * Function callback descriptor table
    630  */
    631 CINT_FWRAPPER_PARAMS_VP0(__ct_callback_handler0); 
    632 
    633 static cint_parameter_desc_t __cint_parameters__ct_void_handler[] =
    634 {
    635     { "int", "r", 0, 0 },
    636     { NULL }
    637 };
    638 
    639 static int
    640 __ct_void_parameter_callback(void) {
    641     int ret;
    642     cint_interpreter_callback(&__ct_function_pointers[2], 0, 1, &ret);
    643     return ret;
    644 }
    645 
    646 static cint_function_pointer_t __ct_function_pointers[4] = 
    647     {
    648         {
    649             "ct_callback0_f", 
    650             (cint_fpointer_t) __ct_callback_handler0, 
    651             __cint_parameters____ct_callback_handler0,
    652         }, 
    653         {
    654             "ct_kitchen_sink_callback_f", 
    655             (cint_fpointer_t) __ct_kitchen_sink_callback, 
    656             __cint_parameters__ct_kitchen_sink, 
    657         }, 
    658         {
    659            "ct_void_parameter_callback_f",
    660             (cint_fpointer_t) __ct_void_parameter_callback,
    661            __cint_parameters__ct_void_handler
    662         },
    663         { NULL }
    664     };    
    665 
    666 
    667 /*************************************************************
    668  *
    669  * Iterators
    670  */
    671 cint_ast_t* 
    672 __CT_BITMAP_ITER_HANDLER(const char* name, cint_ast_t* arguments, cint_ast_t* statements)
    673 {
    674     cint_ast_t* _for; 
    675     cint_ast_t* _if; 
    676     cint_ast_t* _condition;
    677     cint_ast_t* arg1; 
    678 
    679     /*
    680      * We only take two arguments
    681      */
    682     if(cint_ast_count(arguments) != 2) {
    683         cint_ast_error(arguments, CINT_E_BAD_AST, "wrong number of arguments to %s() -- expected 2, received %d", 
    684                        name, cint_ast_count(arguments)); 
    685         return NULL;
    686     }   
    687     arg1 = arguments->next; 
    688 
    689     /*
    690      * This returns the following code tree:
    691      *
    692      * for(arg1 = 0; arg1 < 32; arg1++) {
    693      *    if(CT_BITMAP_MEMBER(arg0, arg1) 
    694      *       [statements]
    695      *
    696      * to simulator BCM_PBMP_ITER()
    697  */
    698     
    699 
    700     /* Function call "CT_BITMAP_MEMBER(arg0, arg1)" */
    701     _condition = cint_ast_function(cint_ast_identifier("CT_BITMAP_MEMBER"), arguments); 
    702               
    703     /* if(CT_BITMAP_MEMBER(arg0,arg1)) { statements } */
    704     _if = cint_ast_if(_condition, statements, 0); 
    705               
    706     /* for(arg1 = 0; arg1 < 32; arg1++) (condition) */
    707     _for = cint_ast_for( /* arg1 = 0 */       
    708                         cint_ast_operator(cintOpAssign,      
    709                                           arg1, 
    710                                           cint_ast_integer(0)), 
    711                         /* arg1 < 32 */
    712                         cint_ast_operator(cintOpLessThan, 
    713                                           arg1,
    714                                           cint_ast_integer(32)), 
    715 
    716                         /* arg1++ */
    717                         cint_ast_operator(cintOpAssign, 
    718                                           arg1, 
    719                                           cint_ast_operator(cintOpAdd, 
    720                                                             arg1, 
    721                                                             cint_ast_integer(1))),
    722 
    723                         /* statements */
    724                         _if); 
    725     
    726     return _for; 
    727 }
    728 
    729 static cint_custom_iterator_t  __ct_iterators[] = 
    730     {
    731         { "CT_BITMAP_ITER", __CT_BITMAP_ITER_HANDLER }, 
    732         { NULL }
    733     }; 
    734 
    735 /*************************************************************
    736  *
    737  * Macros
    738  */
    739 static cint_ast_t*
    740 __CT_IF_ERROR_RETURN_HANDLER(const char* name, cint_ast_t* arguments)
    741 {
    742     /* Inserts the following code:
    743        
    744     do { int __rv__; if ((__rv__ = (arguments)) < 0) return(__rv__); } while(0)
    745 
    746     */
    747     cint_ast_t* _while; 
    748     cint_ast_t* __rv__ = cint_ast_identifier("__rv__"); 
    749     cint_ast_t* _decl_rv = cint_ast_declaration(); 
    750     cint_ast_t* _if; 
    751 
    752     /* Declare __rv__ = (arguments) */
    753     _decl_rv->utype.declaration.type = cint_ast_type("int"); 
    754     _decl_rv->utype.declaration.pcount = 0; 
    755     _decl_rv->utype.declaration.num_dimension_initializers = 0;
    756     _decl_rv->utype.declaration.identifier = __rv__; 
    757     _decl_rv->utype.declaration.init = arguments; 
    758     
    759     _if = cint_ast_if(cint_ast_operator(cintOpLessThan, 
    760                                         __rv__, 
    761                                         cint_ast_integer(0)), 
    762                       cint_ast_return(__rv__), 
    763                       NULL); 
    764 
    765     /* Make the if statement come after the declaration */
    766     cint_ast_append(_decl_rv, _if); 
    767                       
    768     _while = cint_ast_while(/* while(0) */
    769                             cint_ast_integer(0), 
    770                             
    771                             /* statements */
    772                             _decl_rv, 
    773 
    774                             /* order */
    775                             1); 
    776     return _while; 
    777 }
    778     
    779     
    780     
    781 static cint_custom_macro_t __ct_macros[] = 
    782     {
    783         { "CT_IF_ERROR_RETURN", __CT_IF_ERROR_RETURN_HANDLER }, 
    784         
    785         { NULL }
    786     }; 
    787 
    788 /*************************************************************
    789  *
    790  * Typedefs
    791  */
    792 static cint_parameter_desc_t __ct_typedefs[] = 
    793     {
    794         { "void", "ct_voidp_t", 1, 0 }, 
    795         { "int", "ct_int_t", 0, 0 }, 
    796         { "ct_bitmap_t", "ct_bitmapp_t", 1, 0 }, 
    797         { "unsigned int", "ct_array_t", 0, 16 },
    798         { "unsigned int", "xct_array_t", 0, 16 },
    799         
    800         { NULL }, 
    801     }; 
    802 
    803 
    804 /*************************************************************
    805  * 
    806  * Constants
    807  */
    808 static cint_constants_t __ct_constants[] = 
    809     {
    810         { "ct_constant_db", 0xdeadbeef }, 
    811         { "ct_constant_null", 0 }, 
    812         { "ct_constant_cafe", 0xcafe }, 
    813         
    814         { NULL }
    815     }; 
    816 
    817 
    818 
    819 
    820 /*************************************************************
    821  *
    822  * Datatype definition and export 
    823  */
    824 
    825 cint_data_t cint_test_data = 
    826     {   
    827         __ct_atomics, 
    828         __ct_functions,
    829         __ct_structures, 
    830         __ct_enums, 
    831         __ct_typedefs, 
    832         __ct_constants,
    833         __ct_function_pointers, 
    834         __ct_iterators, 
    835         __ct_macros
    836     }; 
    837 
    838 
    839 CINT_LOAD_DATA(cint_test_data); 
    840 
    841 static int
    842 cint_test_data_init_handler(void *data)
    843 {
    844     cint_interpreter_add_atomics(cint_test_data.atomics); 
    845     cint_interpreter_add_data(&cint_test_data, NULL);
    846 
    847     return CINT_E_NONE;
    848 }
    849 
    850 int
    851 cint_test_data_init(void)
    852 {
    853     return
    854         cint_interpreter_initialize_register(cint_test_data_init_handler, NULL);
    855 }
    856 
    857 int
    858 cint_test_data_deinit(void)
    859 {
    860     return
    861         cint_interpreter_initialize_unregister(cint_test_data_init_handler, NULL);
    862 }