static void remove_obj(uint16_t object) { uint16_t parent = PARENT(object); if(parent != 0) { uint16_t child = CHILD(parent); /* Direct child */ if(child == object) { /* parent->child = parent->child->sibling */ SET_CHILD(parent, SIBLING(child)); } else { while(SIBLING(child) != object) { /* child = child->sibling */ child = SIBLING(child); } /* Now the sibling of child is the object to remove. */ /* child->sibling = child->sibling->sibling */ SET_SIBLING(child, SIBLING(SIBLING(child))); } /* object->parent = 0 */ SET_PARENT(object, 0); /* object->sibling = 0 */ SET_SIBLING(object, 0); } }
static memerr process_node(rewrite_sampler_accesses_context *ctx, node *n, essl_bool change_type) { if(_essl_ptrset_has(&ctx->visited, n)) { return MEM_OK; } if(_essl_node_is_texture_operation(n)) { node *sampler; node *swz; assert(change_type == ESSL_FALSE); ESSL_CHECK(sampler = GET_CHILD(n, 0)); ESSL_CHECK(swz = _essl_new_unary_expression(ctx->pool, EXPR_OP_SWIZZLE, sampler)); _essl_ensure_compatible_node(swz, sampler); swz->expr.u.swizzle = _essl_create_scalar_swizzle(0); SET_CHILD(n, 0, swz); ESSL_CHECK(process_node(ctx, sampler, ESSL_TRUE)); } if(change_type == ESSL_TRUE) { if(n->hdr.kind == EXPR_KIND_LOAD && _essl_type_is_or_has_sampler(n->hdr.type)) { ESSL_CHECK(n->hdr.type = _essl_get_type_with_given_vec_size(ctx->typestor_ctx, n->hdr.type, 4)); ESSL_CHECK(_essl_ptrset_insert(&ctx->visited, n)); return MEM_OK; } if (n->hdr.kind == EXPR_KIND_PHI) { phi_source *src; for (src = n->expr.u.phi.sources; src != 0; src = src->next) { ESSL_CHECK(process_node(ctx, src->source, change_type)); } }else { unsigned i; for (i = 0; i < GET_N_CHILDREN(n); ++i) { node *child = GET_CHILD(n, i); ESSL_CHECK(process_node(ctx, child, change_type)); } } ESSL_CHECK(n->hdr.type = _essl_get_type_with_given_vec_size(ctx->typestor_ctx, n->hdr.type, 4)); } ESSL_CHECK(_essl_ptrset_insert(&ctx->visited, n)); return MEM_OK; }
void FrGetLineFromUsb(void) { #define GETNEXTCHAR() LineFromUsb[i++] #define PEEKNEXTCHAR() LineFromUsb[i] #define SKIPNEXTCHAR() i++ #define LINE_HAS_CHAR() (i<LineFromUsbLen) unsigned char len,c,c2,n;//,txout_end; unsigned char i; if(!FrGotLineFromUsb) goto discard; //printf((const far rom char*)"FrGetLineFromUsb()\n"); //while(TXSTAbits.TRMT==0); //wait end of serial transmit FraiseStatus.TX_NEEDACK=0; FraiseStatus.TXCHAR=0; len=LineFromUsbLen; i=0; c=GETNEXTCHAR(); //1st byte = command (or hi nibble of address) //printf((const far rom char*)"parsing ; 1st char : %c\n",c); if(c=='#') { //printf((const far rom char*)"system command...\n"); //****************** system command , begining by '#': ********************** if(len<2) goto discard; c=GETNEXTCHAR(); //what is the command ? //printf((const far rom char*)"2nd char : %c\n",c); if(c=='S'){ // start device pulling if(len!=4) goto discard; //incorrect packet... c=GETNEXTCHAR(); c-='0';if (c>9) c-='A'-'9'-1; c2=GETNEXTCHAR(); c2-='0';if (c2>9) c2-='A'-'9'-1; if((c>15)||(c2>15)) goto discard; //invalid packet n=c2+(c<<4); if((n>0)&&(n<128)) { SET_CHILD(n); CLR_CHILDOK(n); if(MaxPolledChild<n) MaxPolledChild=n; } goto discard; } else if(c=='C'){ // stop device pulling if(len!=4) goto discard; //incorrect packet... c=GETNEXTCHAR(); c-='0';if (c>9) c-='A'-'9'-1; c2=GETNEXTCHAR(); c2-='0';if (c2>9) c2-='A'-'9'-1; if((c>15)||(c2>15)) goto discard; //invalid packet n=c2+(c<<4); if((n>0)&&(n<128)) { CLR_CHILDOK(n); CLR_CHILD(n); } goto discard; } else if(c=='i'){ printf((STRING)"s fraise init...\n"); FraiseInit(); goto discard; } else if(c=='L'){ //get log printf((STRING)"\ns fraise log :\n"); c2=0; printf((STRING)"FraiseState : %d ; FraiseStatus: %d\n",FraiseState,FraiseStatus); for(n=1;n<=MaxPolledChild;n++){ if (TST_CHILD(n)){ printf((STRING)"%d:%d ",n,TST_CHILDOK(n)!=0); if((++c2)%16==0) putchar('\n'); } } putchar('\n'); goto discard; //return; } else if(c=='F'){ //quit bootloader mode //INTCONbits.GIEL = 0; FraiseStatus.FBLDON=0; FraiseState=fIDLE; Serial_Init_None(); printf((STRING)"Quit bootloader mode.\n"); goto discard; //return; } else if(c=='V'){ //get version string printf(VERSION_STRING); goto discard; //return; } else if(c=='R') { //read id n=ee_read_byte(ID_EE_ADDRESS); printf ((STRING)"sID%c%c\n",HI_CHAR(n),LO_CHAR(n)); } else if(c=='W') { //write id c=GETNEXTCHAR(); c-='0';if (c>9) c-='A'-'9'-1; c2=GETNEXTCHAR(); c2-='0';if (c2>9) c2-='A'-'9'-1; if((c>15)||(c2>15)) goto discard; //invalid packet n=c2+(c<<4); ee_write_byte(ID_EE_ADDRESS,n); } else if(c=='E') { //echo while(LINE_HAS_CHAR()) { c=GETNEXTCHAR(); putchar(c); } putchar('\n'); } else if(c=='D') { //delay between each device polling (ms) if(len!=4) goto discard; //incorrect packet... c=GETNEXTCHAR(); c-='0';if (c>9) c-='A'-'9'-1; c2=GETNEXTCHAR(); c2-='0';if (c2>9) c2-='A'-'9'-1; if((c>15)||(c2>15)) goto discard; //invalid packet n=c2+(c<<4); PollDelay=n; } goto discard; //unknown system command ; discard packet. } else if(c=='!') { //****************** broadcast tx , begining by '!': ***************** len-=1; // discard '!' byte if(len<1) goto discard; FrTXPacketInit(0); c=PEEKNEXTCHAR(); //what is the command ? if(c=='B'||c=='I'||c=='N'||c=='R'||c=='P'||c=='F'){ FraiseStatus.TXCHAR=1; if(c=='F') { FraiseStatus.FBLDON=1; printf((STRING)"Enter bootloader mode.\n"); } else FraiseStatus.FBLDON=0; //printf((STRING)"Broadcast %c : len = %d.\n", c,(int)len); goto fill_packet; } if(c=='b'){ SKIPNEXTCHAR(); len-=1; // discard 'b' byte goto fill_packet; } goto discard; } if(FraiseStatus.FBLDON) { //putchar('\n'); //printf((STRING)"bl tx\n"); FrTXPacketInit(len+1); FrTXPacketData(c); while(LINE_HAS_CHAR()) FrTXPacketData(GETNEXTCHAR()); FrTXPacketClose(); FrTXtries=0; FrTXPacketLaunchBl(); goto discard; } //else //****************** normal master to device tx: //the 2 first bytes must be device id + 128 if it is a char packet: if(len<3) goto discard; //c=GETNEXTCHAR(); c-='0';if (c>9) c-='A'-'9'-1; c2=GETNEXTCHAR(); //if (c2=='\n') return; //incomplete packet... c2-='0';if (c2>9) c2-='A'-'9'-1; if((c>15)||(c2>15)) goto discard; //invalid id n=c2+(c<<4); if(n&128) FraiseStatus.TXCHAR=1; else FraiseStatus.TXCHAR=0; n&=127; if (n==0) goto discard; FrTXPacketInit(n); //printf((STRING)"tx to dev %d\n",n); len-=2; //remove the two id bytes FraiseStatus.TX_NEEDACK=1; fill_packet: if(FraiseStatus.TXCHAR) len|=128; else len>>=1; //if not TXCHAR, data len in serial stream will be half than at text input (e.g two text bytes "00" -> one null byte ) FrTXPacketData(len); if(FraiseStatus.TXCHAR) { while(LINE_HAS_CHAR()) FrTXPacketData(GETNEXTCHAR()); } else while(LINE_HAS_CHAR()) { c=GETNEXTCHAR(); c-='0';if (c>9) c-='A'-'9'-1; if(!LINE_HAS_CHAR()) goto discard; //incomplete... c2=GETNEXTCHAR(); c2-='0';if (c2>9) c2-='A'-'9'-1; if((c>15)||(c2>15)) goto discard; //invalid hex string c2+=(c<<4); FrTXPacketData(c2); } FrTXPacketClose(); //printf((STRING)"FrTXpacket_len=%d.\n",FrTXpacket_len); FrTXtries=0; FrTXPacketLaunch(); discard: LineFromUsbLen=0; FrGotLineFromUsb=0; return; }