Annotation of capa/capa51/pProj/capaMapExpr.c, revision 1.1
1.1 ! albertel 1: /* ========================================================================== */
! 2: /* capaMapExpr.c created by Isaac Tsai */
! 3: /* 1998, 1999 copyrighted by Isaac Tsai */
! 4: /* */
! 5: /* this is the main code to handle /MAP() function call in capa */
! 6: #include <stdio.h>
! 7: #include <string.h>
! 8: #include <math.h>
! 9:
! 10: #include "capaParser.h"
! 11: #include "capaToken.h"
! 12: #include "ranlib.h"
! 13:
! 14:
! 15:
! 16: /* |>|===============================================================|<| */
! 17: int
! 18: do_map(seed, varp, argp, argc, dir)
! 19: char *seed; ArgNode_t *varp; ArgNode_t *argp; int argc; int dir;
! 20: {
! 21: long orig_gen, current_gen, seed1, seed2;
! 22: long *idx_array, *ridx_array;
! 23: int idx, val;
! 24: Symbol val_array[ONE_K];
! 25: ArgNode_t *tmpArgp;
! 26:
! 27:
! 28: for(idx=0,tmpArgp=argp;idx<argc;idx++) {
! 29: switch( FIRST_ARGTYPE(tmpArgp) ) {
! 30: case I_VAR:
! 31: case I_CONSTANT:
! 32: (val_array[idx]).s_type = I_VAR;
! 33: (val_array[idx]).s_int = FIRST_ARGINT(tmpArgp); break;
! 34: case R_VAR:
! 35: case R_CONSTANT:
! 36: (val_array[idx]).s_type = R_VAR;
! 37: (val_array[idx]).s_real = FIRST_ARGREAL(tmpArgp); break;
! 38: case S_VAR:
! 39: case S_CONSTANT:
! 40: (val_array[idx]).s_type = S_VAR;
! 41: (val_array[idx]).s_str = strsave(FIRST_ARGSTR(tmpArgp)); break;
! 42: default:
! 43: return -1;
! 44: break;
! 45: }
! 46: tmpArgp = (tmpArgp->a_next);
! 47: }
! 48: idx_array = (long *)capa_malloc(sizeof(long), argc);
! 49: for(idx=0;idx<argc;idx++) idx_array[idx] = idx;
! 50: gscgn(GET_GENERATOR, &orig_gen);
! 51: current_gen = PERMUTATION_G;
! 52: gscgn(SET_GENERATOR, ¤t_gen);
! 53: phrtsd(seed, &seed1, &seed2);
! 54: setsd(seed1, seed2);
! 55: genprm(idx_array, (long)argc);
! 56: if(dir == REVERSE_MAP) {
! 57: ridx_array = (long *)capa_malloc(sizeof(long), argc);
! 58: for(idx=0;idx<argc;idx++) {
! 59: ridx_array[ idx_array[idx] ] = idx;
! 60: }
! 61: for(idx=0;idx<argc;idx++) {
! 62: idx_array[idx] = ridx_array[idx];
! 63: }
! 64: capa_mfree((char *)ridx_array);
! 65: }
! 66: for(idx=0,tmpArgp=varp;idx<argc;idx++) {
! 67: val = idx_array[idx];
! 68: switch( FIRST_ARGTYPE(tmpArgp) ) {
! 69: case IDENTIFIER:
! 70: case I_VAR: case I_CONSTANT:
! 71: case R_VAR: case R_CONSTANT: break;
! 72: case S_VAR: case S_CONSTANT: capa_mfree((char *)FIRST_ARGSTR(tmpArgp)); break;
! 73: }
! 74: FIRST_ARGTYPE(tmpArgp) = (val_array[val]).s_type;
! 75:
! 76: switch( val_array[val].s_type ) {
! 77: case I_VAR: FIRST_ARGINT(tmpArgp) = (val_array[val]).s_int; break;
! 78: case R_VAR: FIRST_ARGREAL(tmpArgp) = (val_array[val]).s_real; break;
! 79: case S_VAR: FIRST_ARGSTR(tmpArgp) = (val_array[val]).s_str; break;
! 80: }
! 81: tmpArgp = tmpArgp->a_next;
! 82: }
! 83: gscgn(SET_GENERATOR, &orig_gen);
! 84: capa_mfree((char *)idx_array);
! 85: return (0);
! 86: }
! 87:
! 88:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>