int32_t CodeBuilder::addop_const(Op opcode,std::string& t_const) { int arg = add_const(t_const); if (arg < 0) return 0; return addop_i(opcode, arg); }
static char * mul_const (BtorMemMgr * mm, const char *a, const char *b) { char *result, *and, *add, *shift; int i, j, len; assert (mm != NULL); assert (a != NULL); assert (b != NULL); assert (strlen (a) == strlen (b)); assert ((int) strlen (a) > 0); assert (is_valid_const_3vl (a)); assert (is_valid_const_3vl (b)); len = (int) strlen (a); result = btor_int_to_const (mm, 0, len); for (i = len - 1; i >= 0; i--) { BTOR_NEWN (mm, and, len + 1); for (j = 0; j < len; j++) and[j] = BTOR_AND_CONST_3VL (a[j], b[i]); and[len] = '\0'; shift = btor_sll_n_bits_const (mm, and, len - 1 - i); add = add_const (mm, result, shift); btor_delete_const (mm, result); btor_delete_const (mm, and); btor_delete_const (mm, shift); result = add; } return result; }
char * btor_add_const_3vl (BtorMemMgr * mm, const char *a, const char *b) { assert (mm != NULL); assert (a != NULL); assert (b != NULL); assert (strlen (a) == strlen (b)); assert ((int) strlen (a) > 0); assert (is_valid_const_3vl (a)); assert (is_valid_const_3vl (b)); return add_const (mm, a, b); }
static void init_symbols() { memset(symbol_table, 0, sizeof(symbol_table)); // add the standard math library functions add_built_in("acos", acos); add_built_in("asin", asin); add_built_in("atan", atan); add_built_in("atan2", atan2); add_built_in("cos", cos); add_built_in("cosh", cosh); add_built_in("sin", sin); add_built_in("sinh", sinh); add_built_in("tan", tan); add_built_in("tanh", tanh); add_built_in("exp", exp); add_built_in("log", log); add_built_in("log10", log10); add_built_in("exp2", exp2); #ifdef HAVE_LOG2 add_built_in("log2", log2); #endif add_built_in("pow", pow); add_built_in("sqrt", sqrt); add_built_in("cbrt", cbrt); add_built_in("hypot", hypot); add_built_in("ceil", ceil); add_built_in("abs", fabs); add_built_in("fabs", fabs); add_built_in("floor", floor); add_built_in("mod", fmod); add_built_in("fmod", fmod); // add the constants pi and PI add_const("pi", M_PI); add_const("PI", M_PI); }
static void init_symbols() { memset(symbol_table, 0, sizeof(symbol_table)); // add the standard math library functions add_built_in("acos", (void*) acos, 1); add_built_in("asin", (void*) asin, 1); add_built_in("atan", (void*) atan, 1); add_built_in("atan2", (void*) atan2, 2); add_built_in("cos", (void*) cos, 1); add_built_in("cosh", (void*) cosh, 1); add_built_in("sin", (void*) sin, 1); add_built_in("sinh", (void*) sinh, 1); add_built_in("tan", (void*) tan, 1); add_built_in("tanh", (void*) tanh, 1); add_built_in("exp", (void*) exp, 1); add_built_in("log", (void*) log, 1); add_built_in("log10", (void*) log10, 1); add_built_in("exp2", (void*) exp2, 1); #ifdef HAVE_LOG2 add_built_in("log2", (void*) log2, 1); #endif add_built_in("pow", (void*) pow, 2); add_built_in("sqrt", (void*) sqrt, 1); add_built_in("cbrt", (void*) cbrt, 1); add_built_in("hypot", (void*) hypot, 2); add_built_in("ceil", (void*) ceil, 1); add_built_in("abs", (void*) fabs, 1); add_built_in("fabs", (void*) fabs, 1); add_built_in("floor", (void*) floor, 1); add_built_in("mod", (void*) fmod, 2); add_built_in("fmod", (void*) fmod, 2); // add the constants pi and PI add_const("pi", M_PI); add_const("PI", M_PI); }
//-------------------------------------------------------------------------- static tid_t get_class_struct_flags_enum() { static const char enum_name[] = "ClassFlags"; enum_t id = get_enum(enum_name); if ( id != BADNODE ) return id; id = add_enum(BADADDR, enum_name, hexflag()); set_enum_bf(id, true); add_const(id, "CLASSF_HAS_DEFAULT", (1<<0), (1<<0)); add_const(id, "CLASSF_MASTER_CLASS", (1<<1), (1<<1)); add_const(id, "CLASSF_VARIANT_CLASS", (1<<2), (1<<2)); add_const(id, "CLASSF_DISCARD_ON_SAVE", (1<<3), (1<<3)); add_const(id, "CLASSF_NEVER_SAVED", (1<<4), (1<<4)); add_const(id, "CLASSF_HAS_RELOC", (1<<5), (1<<5)); add_const(id, "CLASSF_C_HANDLERS", (1<<6), (1<<6)); return id; }
//Parser of file. registers* parser_file(FILE* program) { registers* pointers; file_header1* fh1; file_header2* fh2; function_header1* mh1; function_header2* mh2; char *string_buffer, *substring; size_t size; int current_offset = 0; int entry_offset = 0; char load_entry = 0; uint i; //Reading of the first part of file-header. fh1 = (file_header1*)malloc(sizeof(file_header1)); size = fread(fh1, sizeof(file_header1), 1, program); if (SUCCESS != size || fh1->signature != SIGNATURE) program_crash(wrng_file); //Creation of the constant pool. pointers = (registers*)malloc(sizeof(registers)); pointers->pool = pool_create(); //Reading of constants. if (fh1->count_constant != 0) { string_buffer = (char*)malloc(fh1->size_of_constant); size = fread(string_buffer, fh1->size_of_constant, 1, program); if (SUCCESS != size) program_crash(wrng_file); substring = string_buffer; for (i = 1; i <= fh1->count_constant; i++) { add_const(i, pointers->pool, substring); substring += strlen(substring) + 1; } free(string_buffer); } //Reading of the second part of file-header. fh2 = (file_header2*)malloc(sizeof(file_header2)); size = fread(fh2, sizeof(file_header2), 1, program); if (size != SUCCESS) program_crash(wrng_file); pointers->count_functions = fh2->count_function; //Initialization of some registers. pointers->table = (function_table*)malloc(sizeof(function_table) * fh2->count_function); pointers->ctxsp = pointers->ctx_bottom = (context_t*)malloc(sizeof(context_t) * FRAMES); pointers->byte_code = NULL; //Reading of functions. mh1 = (function_header1*)malloc(sizeof(function_header1)); mh2 = (function_header2*)malloc(sizeof(function_header2)); for (i = 0; i < fh2->count_function; i++) { size = fread(mh1, sizeof(function_header1), 1, program); if ((SUCCESS != size) & fseek(program, mh1->size_of_sign, SEEK_CUR)) program_crash(wrng_file); size = fread(mh2, sizeof(function_header2), 1, program); if (SUCCESS != size) program_crash(wrng_file); pointers->byte_code = (function)realloc(pointers->byte_code, current_offset + mh1->size_of_byte_code); size = fread((pointers->byte_code + current_offset), mh1->size_of_byte_code, 1, program); if (SUCCESS != size) program_crash(wrng_file); //Initialization of function metadata. (pointers->table + i)->id = mh2->id; (pointers->table + i)->offset = current_offset; (pointers->table + i)->locals = mh2->count_of_locals; (pointers->table + i)->args = mh2->count_of_arguments; (pointers->table + i)->ctx = NULL; //If this function is an entry point to program... if (mh2->id == fh2->entry_point_id) { load_entry = SUCCESS; entry_offset = current_offset; pointers->current_function = (pointers->table + i); pointers->ctxsp->locals = (stack_t*)malloc(sizeof(stack_t) * mh2->count_of_locals); pointers->ctxsp->previous_ctx = NULL; pointers->ctxsp->previous_function = NULL; pointers->ctxsp->return_address = NULL; pointers->current_function->ctx = pointers->ctxsp; //Now this function ready for execution. } current_offset += mh1->size_of_byte_code; } if (load_entry != SUCCESS) program_crash(no_entr_funct); pointers->ip = pointers->byte_code + entry_offset; free(fh1); free(fh2); free(mh1); free(mh2); fclose(program); return pointers; }
type add_cv( const type &type_ ) { return add_volatile( add_const( type_ ) ); }
void *op_brick_add(t_brick *brick) { t_context *C = ctx_get(); t_node *node = NULL; t_block *block; t_set *set; // store scene_store(C->scene,1); char *name=brick->id.name; if(is(name,"frame")) node = add_slider_int(C,"frame",&C->app->frame); else if(is(name,"timer")) node = add_slider_float(C,"timer",&C->app->timer); else if(is(name,"timer low")) node = add_slider_float(C,"timer low",&C->app->timer_add_low); else if(is(name,"=")) node = add_operator_double(C,"="); else if(is(name,">")) node = add_operator_double(C,">"); else if(is(name,"<")) node = add_operator_double(C,"<"); else if(is(name,"if")) node = add_if(C); else if(is(name,"mod")) node = add_operator_double(C,"mod"); else if(is(name,"x")) node = add_maths(C,"x"); else if(is(name,"+")) node = add_maths(C,"+"); else if(is(name,"++")) node = add_plusplus(C); else if(is(name,"switch")) node = add_switch(C,"switch",NULL,NULL); else if(is(name,"clone")) node = add_clone(C); else if(is(name,"pipe")) node = add_pipe(C); else if(is(name,"sec")) node = add_slider_int(C,"sec",&C->app->clock->sec); else if(is(name,"min")) node = add_slider_int(C,"min",&C->app->clock->min); else if(is(name,"int")) node = add_slider_int(C,"int",NULL); else if(is(name,"float")) node = add_slider_float(C,"float",NULL); else if(is(name,"10")) node = add_multiplier(C,"10"); else if(is(name,"100")) node = add_multiplier(C,"100"); else if(is(name,".1")) node = add_multiplier(C,".1"); else if(is(name,".01")) node = add_multiplier(C,".01"); else if(is(name,".001")) node = add_multiplier(C,".001"); else if(is(name,"msec")) node = add_slider_int(C,"msec",&C->app->clock->msec); else if(is(name,"cos")) node = add_operator_single(C,"cos",op_cos); else if(is(name,"sin")) node = add_operator_single(C,"sin",op_sin); else if(is(name,"cam_eye_x")) node = add_slider_camera(C,"eye x"); else if(is(name,"cam_eye_y")) node = add_slider_camera(C,"eye y"); else if(is(name,"cam_eye_z")) node = add_slider_camera(C,"eye z"); else if(is(name,"cam_pos_x")) node = add_slider_camera(C,"pos x"); else if(is(name,"cam_pos_y")) node = add_slider_camera(C,"pos y"); else if(is(name,"cam_pos_z")) node = add_slider_camera(C,"pos z"); else if(is(name,"cam_rot_xy")) node = add_slider_float_custom(C,"cam rot xy",op_camera_rotate_xy); else if(is(name,"cam_rot_z")) node = add_slider_float_custom(C,"cam rot z",op_camera_rotate_z); else if(is(name,"pos x")) node = add_slider_object(C,"pos x"); else if(is(name,"pos y")) node = add_slider_object(C,"pos y"); else if(is(name,"pos z")) node = add_slider_object(C,"pos z"); else if(is(name,"rot x")) node = add_slider_object(C,"rot x"); else if(is(name,"rot y")) node = add_slider_object(C,"rot y"); else if(is(name,"rot z")) node = add_slider_object(C,"rot z"); else if(is(name,"scl x")) node = add_slider_object(C,"scl x"); else if(is(name,"scl y")) node = add_slider_object(C,"scl y"); else if(is(name,"scl z")) node = add_slider_object(C,"scl z"); else if(is(name,"red")) node = add_slider_object(C,"red"); else if(is(name,"green")) node = add_slider_object(C,"green"); else if(is(name,"blue")) node = add_slider_object(C,"blue"); else if(is(name,"color")) node = add_slider_object(C,"color"); else if(is(name,"faces")) node = add_slider_object(C,"faces"); else if(is(name,"alpha")) node = add_slider_object(C,"alpha"); else if(is(name,"label")) node = add_label(C,"label"); else if(is(name,"get")) node = add_get(C); else if(is(name,"rewind")) node = add_trigger_always(C,"rewind",op_rewind); else if(is(name,"not")) node = add_slider_int_custom(C,"not",NULL,op_not); else if(is(name,"mouse_x")) node = add_slider_int(C,"mouse x",&C->app->mouse->x); else if(is(name,"mouse_y")) node = add_slider_int(C,"mouse y",&C->app->mouse->y); else if(is(name,"keyboard")) node = add_slider_char(C,"keyboard",&C->app->keyboard->key_pressed); else if(is(name,"rnd")) node = add_slider_int_custom(C,"rnd",NULL,op_rnd); else if(is(name,"neg")) node = add_slider_int_custom(C,"neg",NULL,op_neg); else if(is(name,"abs")) node = add_slider_int_custom( C, "abs", NULL, op_abs); else if(is(name,"last?")) node = add_switch(C,"last?",NULL,op_is_last); else if(is(name,"for")) node = add_for(C); else if(is(name,"vector 3d")) node = add_vector_3d(C); else if(is(name,"vector 2d")) node = add_vector_2d(C); else if(is(name,"bang")) node = add_slider_int_custom(C,"bang",NULL,op_bang); else if(is(name,"quit")) node = add_trigger_always(C,"quit",op_do_quit); else if(is(name,"const")) node = add_const(C); else if(is(name,"and")) node = add_maths(C,"and"); else if(is(name,"stack")) node = add_stack(C); else if(is(name,"mesh")) node = add_slider_object(C,"mesh"); else if(is(name,"vertex")) node = add_brick_mesh(C,"vertex"); else if(is(name,"edges")) node = add_brick_mesh(C,"edges"); else if(is(name,"case")) node = add_case(C,"switch"); // Store scene_store(C->scene,0); term_log("+ brick"); // Switch Desk if(!C->ui->show_sets) show_sets(C); if( node) { block = node->data; set = block->set; set_setup( set); } return NULL; }
void do_inc_ex(int type) { int end; int i; INTPTR_T j; int num; int nb_tile; char label[NAMESIZE]; char label2[NAMESIZE]; char str[NAMESIZE+32]; struct { char fname[FILENAMESIZE]; INTPTR_T arg[5]; } tiles[16]; if(!match("(")) { error("missing '('"); kill_line(); return; } readstr(); /* read the label name */ strcpy(label, litq2); strcpy(label2, litq2); strcpy(str, "__data__"); for(i = (int)strlen(label2), j = 0; i < NAMEMAX; i++) label2[i] = str[j++]; label2[i] = '\0'; addglb(label2, ARRAY, CINT, 0, EXTERN); addglb(label, ARRAY, CINT, 0, EXTERN); if(!match(",")) { error("comma missing"); kill_line(); return; } end = 0; num = 0; nb_tile = 0; while (!end) { // if (match("\\")); if(!readqstr()) { error("not a file name"); kill_line(); return; } if(!match(",")) { error("comma missing"); kill_line(); return; } strcpy(tiles[num].fname, litq2); for (i = 0; i < 5; i++) { // if (match("\\")); if(!number(&tiles[num].arg[i])) { error("not a number"); kill_line(); return; } if (match(")")) { if (i == 4) { kill_line(); end = 1; break; } else { error("arg missing"); kill_line(); return; } } if(!match(",")) { error("comma missing"); kill_line(); return; } while((ch() == ' ') || (ch() == '\t')) gch(); if (ch() == '\0') { error("arg missing"); kill_line(); return; } } nb_tile += tiles[num].arg[2] * tiles[num].arg[3]; num++; if (num == 16) { if(!end) { error("too many args (max 16 files)"); kill_line(); return; } } } /* create const array to hold extra infos */ new_const(); const_val[const_val_idx++] = const_data_idx; /* number of tile */ sprintf(str, "%i", nb_tile); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = const_data_idx; /* tile size */ sprintf(str, "%i", type); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = const_data_idx; /* tile bank */ sprintf(str, "BANK(_%s)", label2); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = const_data_idx; /* tile addr */ sprintf(str, " _%s", label2); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = -(litptr + 1024); /* pal idx table addr */ add_const(CINT); /* create pal idx table */ for(i = 0; i < num; i++) { j = tiles[i].arg[2] * tiles[i].arg[3]; while (j) { j--; if (litptr < LITMAX) litq[litptr++] = (tiles[i].arg[4] << 4); } } /* dump incchr/tile cmds */ ol(".data"); if (type == 8) ol(".dw $0800"); else ol(".dw $1000"); prefix(); outstr(label2); outstr(":\n"); for(i = 0; i < num; i++) { if (type == 8) ot(".incchr \""); else ot(".inctile \""); outstr(tiles[i].fname); outstr("\""); for (j = 0; j < 4; j++) { outstr(","); outdec(tiles[i].arg[j]); } newl(); } ol(".code"); kill_line(); }