/** * depth-first search begins at (x, y) and explores adjacent, * accessible rooms recursively until (goal_x, goal_y) is found. * if program is compiled with macro FULL, prints out the entire * path traversed, including backtracking. * otherwise, prints visited rooms that are part of the final * route in reverse. */ int dfs(int x, int y, int goal_x, int goal_y, FILE *file) { if (x == goal_x && y == goal_y) { fprintf(file, "%d, %d\n", x, y); return 1; // if current (x, y) is goal, return true } Room *r = &maze[y][x]; // pointer to room at (x, y) in maze #ifdef FULL fprintf(file, "%d, %d\n", x, y); #endif r->visited = 1; // set visited to true int dir; for(dir = 0; dir < 4; ++dir) { // for each direction int neighbor_x = x + calculate_offset(dir, 'x'); int neighbor_y = y + calculate_offset(dir, 'y'); Room *neighbor = &maze[neighbor_y][neighbor_x]; if (!r->connections[dir] && !neighbor->visited) { if (dfs(neighbor_x, neighbor_y, goal_x, goal_y, file)) { #ifndef FULL fprintf(file, "%d, %d\n", x, y); #endif return 1; // if recursive call returns true, return true } else { #ifdef FULL fprintf(file, "%d, %d\n", x, y); #endif } } } return 0; // dead end, return false }
static void new_condition (segment_info *v, gfc_equiv *eq1, gfc_equiv *eq2) { HOST_WIDE_INT offset1, offset2; segment_info *a; offset1 = calculate_offset (eq1->expr); offset2 = calculate_offset (eq2->expr); a = get_segment_info (eq2->expr->symtree->n.sym, v->offset + offset1 - offset2); current_segment = add_segments (current_segment, a); }
static void confirm_condition (segment_info *s1, gfc_equiv *eq1, segment_info *s2, gfc_equiv *eq2) { HOST_WIDE_INT offset1, offset2; offset1 = calculate_offset (eq1->expr); offset2 = calculate_offset (eq2->expr); if (s1->offset + offset1 != s2->offset + offset2) gfc_error ("Inconsistent equivalence rules involving '%s' at %L and " "'%s' at %L", s1->sym->name, &s1->sym->declared_at, s2->sym->name, &s2->sym->declared_at); }
static int do_cmp(clockid_t clkid, int cmdc, char *cmdv[]) { struct timespec ts, rta, rtb; int64_t sys_offset, delay = 0, offset; uint64_t sys_ts; if (SYSOFF_SUPPORTED == sysoff_measure(CLOCKID_TO_FD(clkid), 9, &sys_offset, &sys_ts, &delay)) { pr_notice( "offset from CLOCK_REALTIME is %"PRId64"ns\n", sys_offset); return 0; } memset(&ts, 0, sizeof(ts)); memset(&ts, 0, sizeof(rta)); memset(&ts, 0, sizeof(rtb)); if (clock_gettime(CLOCK_REALTIME, &rta) || clock_gettime(clkid, &ts) || clock_gettime(CLOCK_REALTIME, &rtb)) { pr_err("cmp: failed clock reads: %s\n", strerror(errno)); return -1; } offset = calculate_offset(&rta, &ts, &rtb); pr_notice( "offset from CLOCK_REALTIME is approximately %"PRId64"ns\n", offset); return 0; }
/* filter records according to conditions in a heap file return 0: record gets filtered off return 1: record meets the conditions */ int filter(void *record, COND *con, int conditions, HFILE *hf){ int i; for (i=0;i<conditions;i++){ // prepare parameters for function *compare int offset = calculate_offset(hf->schema, con[i].field); int column = (con[i].field)-1; int function_num = hf->schema_array[column]; int field_length = atoi((hf->schema[column])+1); // compare the value in condition clause with corresponding field in records int result = (*compare[function_num])(record, offset, con[i].value, field_length); if (!strcmp(con[i].op,"=") && result !=0) return 0; else if (!strcmp(con[i].op,">") && result <=0) return 0; else if (!strcmp(con[i].op,"<") && result >=0) return 0; else if (!strcmp(con[i].op,">=") && result <0) return 0; else if (!strcmp(con[i].op,"<=") && result >0) return 0; else if (!strcmp(con[i].op,"<>") && result ==0) return 0; } return 1; }
ObjectIcon::ObjectIcon(const std::string& name, const std::string& icon) : object_name(name), surface(Surface::create(icon)), offset() { calculate_offset(); }
/*store regs on stack before func call*/ void push_stack(){ int total_offset = calculate_offset(); int offset = 0; fprintf(fp, "\taddi $sp, $sp, -%d\n", total_offset); int i; //store s_regs for variable for (i = 0; i < S_REG_NUM; ++i){ if(s_reg[i].used){ fprintf(fp, "\tsw %s, %d($sp)\n", s_reg[i].name, offset); offset += 4; } } //store t_regs for constant for (i = 0; i < T_REG_NUM - 1; ++i){ if(t_reg[i].used){ fprintf(fp, "\tsw %s, %d($sp)\n", t_reg[i].name, offset); offset += 4; } } //store ra for return address fprintf(fp, "\tsw $ra, %d($sp)\n", offset); assert((total_offset - offset) == 4); }
ObjectIcon::ObjectIcon(std::string name, std::string icon) : object_name(name), surface(), offset() { surface = Surface::create(icon); calculate_offset(); }
int invdist_circular_nomem(struct genome_struct *g1, struct genome_struct *g2, int num_genes) { int offset; offset = calculate_offset(g1, g2, num_genes); return (invdist_noncircular_nomem(g1, g2, offset, num_genes)); }
/* unichromosomal reversal distance, linear Uses same parameter list as function of same name in GRAPPA _v versions: graphstats return structure included (used to be "verbose option is included") */ int invdist_circular(struct genome_struct *g1, struct genome_struct *g2, int num_genes, distmem_t *distmem) { int offset; offset = calculate_offset(g1, g2, num_genes); return invdist_noncircular(g1, g2, offset, num_genes, distmem); }
ObjectIcon::ObjectIcon(const ReaderMapping& reader) : object_name(), surface(), offset() { std::string icon = "images/engine/icons/supertux.png"; reader.get("class", object_name); reader.get("icon", icon); surface = Surface::create(icon); calculate_offset(); }
Camera::Camera (CameraGroup &cg_, boost::property_tree::ptree pt_) : cg (cg_), pt (pt_) { auto pd = pt.get_child ("physical-dimensions"); physical_dimensions = parse_physical_dimensions (); viewport = parse_viewport (); offset = calculate_offset (); port = Port::dimensioned_centered (pd.get<double>("width"), pd.get<double>("height")); Port::Matrix m (CGAL::TRANSLATION, K::Vector_3 (offset)); port.m = m * port.m; }
/* Retrieve from the data manager file */ static ssize_t _read(dm_item_t item, unsigned char index, void *buf, size_t count) { unsigned char buffer[k_sector_size]; int len, offset; /* Get the offset for this item */ offset = calculate_offset(item, index); /* If item type or index out of range, return error */ if (offset < 0) { return -1; } /* Make sure the caller hasn't asked for more data than we can handle */ if (count > DM_MAX_DATA_SIZE) { return -1; } /* Read the prefix and data */ len = -1; if (lseek(g_task_fd, offset, SEEK_SET) == offset) { len = read(g_task_fd, buffer, count + DM_SECTOR_HDR_SIZE); } /* Check for read error */ if (len < 0) { return -1; } /* A zero length entry is a empty entry */ if (len == 0) { buffer[0] = 0; } /* See if we got data */ if (buffer[0] > 0) { /* We got more than requested!!! */ if (buffer[0] > count) { return -1; } /* Looks good, copy it to the caller's buffer */ memcpy(buf, buffer + DM_SECTOR_HDR_SIZE, buffer[0]); } /* Return the number of bytes of caller data read */ return buffer[0]; }
static int _clear(dm_item_t item) { int i, result = 0; /* Get the offset of 1st item of this type */ int offset = calculate_offset(item, 0); /* Check for item type out of range */ if (offset < 0) { return -1; } /* Clear all items of this type */ for (i = 0; (unsigned)i < g_per_item_max_index[item]; i++) { char buf[1]; if (lseek(g_task_fd, offset, SEEK_SET) != offset) { result = -1; break; } /* Avoid SD flash wear by only doing writes where necessary */ if (read(g_task_fd, buf, 1) < 1) { break; } /* If item has length greater than 0 it needs to be overwritten */ if (buf[0]) { if (lseek(g_task_fd, offset, SEEK_SET) != offset) { result = -1; break; } buf[0] = 0; if (write(g_task_fd, buf, 1) != 1) { result = -1; break; } } offset += k_sector_size; } /* Make sure data is actually written to physical media */ fsync(g_task_fd); return result; }
/* write to the data manager file */ static ssize_t _write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buf, size_t count) { unsigned char buffer[k_sector_size]; size_t len; int offset; /* Get the offset for this item */ offset = calculate_offset(item, index); /* If item type or index out of range, return error */ if (offset < 0) { return -1; } /* Make sure caller has not given us more data than we can handle */ if (count > DM_MAX_DATA_SIZE) { return -1; } /* Write out the data, prefixed with length and persistence level */ buffer[0] = count; buffer[1] = persistence; buffer[2] = 0; buffer[3] = 0; if (count > 0) { memcpy(buffer + DM_SECTOR_HDR_SIZE, buf, count); } count += DM_SECTOR_HDR_SIZE; len = -1; /* Seek to the right spot in the data manager file and write the data item */ if (lseek(g_task_fd, offset, SEEK_SET) == offset) if ((len = write(g_task_fd, buffer, count)) == count) { fsync(g_task_fd); /* Make sure data is written to physical media */ } /* Make sure the write succeeded */ if (len != count) { return -1; } /* All is well... return the number of user data written */ return count - DM_SECTOR_HDR_SIZE; }
/* Generating code for expression */ int print_expr(Expr expr, int reg, char* proc_id) { int curr_reg = reg; int next_reg; int ID_type; int ID_type2; switch (expr->kind) { Type ID_type; int stackNo; case EXPR_ID: ID_type = getType(proc_id,expr->id); stackNo = getStackSlotNum(proc_id, expr->id); printf("load r%d, %d\n", curr_reg,stackNo); if(isRef(proc_id, expr->id)) printf("load_indirect r%d, r%d\n", curr_reg ,curr_reg); break; case EXPR_CONST: print_constant(expr->constant, curr_reg); break; case EXPR_BINOP: ID_type = getExprType(expr->e1, proc_id); ID_type2 = getExprType(expr->e2, proc_id); curr_reg = print_expr(expr->e1, curr_reg, proc_id); next_reg = print_expr(expr->e2, curr_reg + 1, proc_id); print_binop_string(expr->binop, curr_reg, next_reg, ID_type, ID_type2); break; case EXPR_RELOP: ID_type = getExprType(expr->e1, proc_id); ID_type2 = getExprType(expr->e2, proc_id); curr_reg = print_expr(expr->e1, curr_reg, proc_id); next_reg = print_expr(expr->e2, curr_reg + 1, proc_id); print_relop_string(expr->relop, curr_reg, next_reg, ID_type, ID_type2); break; case EXPR_UNOP: ID_type = getExprType(expr->e1, proc_id); print_unop_string(expr->unop, curr_reg, ID_type); break; case EXPR_ARRAY: curr_reg = calculate_offset(expr->es, curr_reg, expr->id, proc_id); break; } return curr_reg; }
/* Print array assignments */ void print_assign_array(Assign assign, Exprs expr, char* proc_id) { // calculate offset printf("#assignment\n"); Type ID_type; ID_type = getExprType(assign.expr, proc_id); int reg = print_expr(assign.expr, 0, proc_id); int next_reg = reg+1; if (ID_type == INT_ARRAY_TYPE || ID_type == FLOAT_ARRAY_TYPE || ID_type == BOOL_ARRAY_TYPE){ printf("load_indirect r%d, r%d\n", next_reg, reg); next_reg = next_reg+1; } next_reg = calculate_offset(expr, next_reg, assign.id, proc_id); printf("store_indirect r%d, r%d\n", next_reg, next_reg-1); }
/* read in array */ void print_read_array(Stmt stmt, char* proc_id) { printf("# read\n"); Type ID_type; ID_type = getType(proc_id,stmt->info.array.id); switch (ID_type){ case BOOL_ARRAY_TYPE: printf("call_builtin read_bool"); printf("\n"); break; case INT_ARRAY_TYPE: printf("call_builtin read_int \n"); //with a function break; case FLOAT_ARRAY_TYPE: printf("call_builtin read_real \n"); //with a function break; } int reg = calculate_offset(stmt->info.array.exprs, 1, stmt->info.array.id, proc_id); printf("store_indirect r%d, r0\n", reg); printf("\n"); }
/*** process_file * This function is the main input file processing loop. It takes the instruction string in ASM and turns it into * machine code. First, the op-code and corresponding funct are determined and then the register names are read in and processed. * The offset and jsec values are determined using other functions. ***/ struct instruction* process_file(struct instruction *inst, FILE *input) { char string[BUFFER_SIZE]; //note that the current instruction address is tracked. this is for use with branching and jumps. int op, r1, r2, r3, funct, offset, jsec, address=0x4000; while(fscanf(input, "%s", string) != EOF) { if (check_for_label(string) == 1) { fscanf(input, "%s", string); } set_op_funct(&op, &funct, string); if (op == 0) //add, sub, and, or, slt, sltu { fscanf(input, "%s", string); r3 = get_reg(string); fscanf(input, "%s", string); r1 = get_reg(string); fscanf(input, "%s", string); r2 = get_reg(string); offset = 0; jsec = 0; } else if (op == 2) //j { r1 = 0; r2 = 0; r3 = 0; offset = 0; fscanf(input, "%s", string); jsec = find_label_address(inst, strcat(string,":")); } else if (op == 4) //beq { fscanf(input, "%s", string); r1 = get_reg(string); fscanf(input, "%s", string); r2 = get_reg(string); r3 = 0; fscanf(input, "%s", string); offset = calculate_offset(address, find_label_address(inst, strcat(string,":"))); jsec = 0; } else if (op == 8) //addi { fscanf(input, "%s", string); r1 = get_reg(string); fscanf(input, "%s", string); r2 = get_reg(string); r3 = 0; fscanf(input, "%d", &offset); jsec = 0; } else if (op == 10 || op == 11) //slti, sltiu { fscanf(input, "%s", string); r2 = get_reg(string); fscanf(input, "%s", string); r1 = get_reg(string); r3 = 0; fscanf(input, "%d", &offset); jsec = 0; } else if (op == 15) //lui { fscanf(input, "%s", string); r1 = 0; r2 = get_reg(string); r3 = 0; fscanf(input, "%d", &offset); jsec = 0; } else if (op == 35 || op == 43) //lw, sw { fscanf(input, "%s", string); r2 = get_reg(string); fscanf(input, "%s", string); int offset, reg; get_mem_offset_and_word_reg(string, &offset, ®); r1 = reg; r3 = 0; offset = offset; jsec = 0; } inst = modify_ll_node(inst, address, op, r1, r2, r3, funct, offset, jsec); address += 0x4; //the current address is incremented by 4 after every instruction is processed } return inst; }
void refresh_display(void) { int n; scope_disp_t *disp; scope_vert_t *vert; scope_horiz_t *horiz; int depth; double pixels_per_div, pixels_per_sec, overall_record_length; double screen_center_time, screen_start_time, screen_end_time; /* cancel any pending refresh request */ ctrl_usr->display_refresh_timer = 0; /* set pointers */ disp = &(ctrl_usr->disp); vert = &(ctrl_usr->vert); horiz = &(ctrl_usr->horiz); /* get window pointer */ disp->win = disp->drawing->window; if (disp->win == NULL) { /* window isn't visible yet, do nothing */ printf("refresh_display(): win = NULL, bailing!\n"); return; } /* create drawing context if needed */ if (disp->context == NULL) { disp->context = gdk_gc_new(disp->win); } /* get window dimensions */ gdk_window_get_geometry(disp->win, NULL, NULL, &(disp->width), &(disp->height), &depth); /* calculate horizontal params that depend on width */ pixels_per_div = disp->width * 0.1; pixels_per_sec = pixels_per_div / horiz->disp_scale; disp->pixels_per_sample = pixels_per_sec * horiz->sample_period; overall_record_length = horiz->sample_period * ctrl_shm->rec_len; screen_center_time = overall_record_length * horiz->pos_setting; screen_start_time = screen_center_time - (5.0 * horiz->disp_scale); disp->horiz_offset = screen_start_time * pixels_per_sec; disp->start_sample = screen_start_time / horiz->sample_period; if (disp->start_sample < 0) { disp->start_sample = 0; } screen_end_time = screen_center_time + (5.0 * horiz->disp_scale); disp->end_sample = (screen_end_time / horiz->sample_period) + 1; if (disp->end_sample > ctrl_shm->rec_len - 1) { disp->end_sample = ctrl_shm->rec_len - 1; } { GdkRectangle rect = {0, 0, disp->width, disp->height}; GdkRegion *region = gdk_region_rectangle(&rect); gdk_window_begin_paint_region(disp->drawing->window, region); gdk_region_destroy(region); } DRAWING = 1; clear_display_window(); draw_grid(); /* calculate offsets for AC-offset channels */ for (n = 0; n < 16; n++) { if (vert->chan_enabled[n]) calculate_offset(n); } /* draw baselines first */ for (n = 0; n < 16; n++) { if ((vert->chan_enabled[n]) && (n + 1 != vert->selected)) { draw_baseline(n + 1, FALSE); } } if (vert->chan_enabled[vert->selected - 1]) { draw_baseline(vert->selected, TRUE); } /* Draw trigger line */ if (vert->chan_enabled[ctrl_shm->trig_chan - 1]) { draw_triggerline(ctrl_shm->trig_chan, ctrl_shm->trig_chan == vert->selected); } conflict_reset(disp->height); /* draw non-highlighted waveforms next */ for (n = 0; n < 16; n++) { if ((vert->chan_enabled[n]) && (vert->data_offset[n] >= 0) && (n + 1 != vert->selected)) { draw_waveform(n + 1, FALSE); } } /* draw highlighted waveform last */ if ((vert->chan_enabled[vert->selected - 1]) && (vert->data_offset[vert->selected - 1] >= 0)) { draw_waveform(vert->selected, TRUE); } update_readout(); gdk_window_end_paint(disp->drawing->window); }
void print_write_expr(Expr expr, int depth, char* proc_id) { switch (expr->kind) { int ID_type = 0; int ID_type2 = 0; int stackNo; int reg; int reg1; case EXPR_ID: //Get the type and stack number from symbol table ID_type = getType(proc_id,expr->id); stackNo = getStackSlotNum(proc_id, expr->id); printf("load r0, %d\n", stackNo); switch (ID_type){ case BOOL_TYPE: printf("\n"); printf("call_builtin print_bool"); //with a function printf("\n"); break; case INT_TYPE: printf("call_builtin print_int \n"); //with a function break; case FLOAT_TYPE: printf("call_builtin print_real \n"); //with a function break; } break; case EXPR_CONST: print_write_constant(expr->constant); break; case EXPR_BINOP: reg = print_expr(expr->e1, 0, proc_id); reg1 = print_expr(expr->e2, 1, proc_id); ID_type = getExprType(expr->e1, proc_id); ID_type2 = getExprType(expr->e2, proc_id); print_binop_string(expr->binop, reg, reg1, ID_type, ID_type2); if ((ID_type + ID_type2) >= 3){ printf("call_builtin print_real \n"); } else if ((ID_type + ID_type2) == 2){ printf("call_builtin print_int \n"); } else{ printf("call_builtin print_bool \n"); } break; case EXPR_RELOP: reg = print_expr(expr->e1, 0, proc_id); reg1 = print_expr(expr->e2, 1, proc_id); ID_type = getExprType(expr->e1, proc_id); ID_type2 = getExprType(expr->e2, proc_id); print_relop_string(expr->relop, reg, reg1, ID_type, ID_type2); printf("call_builtin print_bool \n"); break; case EXPR_UNOP: reg = print_expr(expr->e1, 0, proc_id); ID_type = getExprType(expr->e1, proc_id); print_unop_string(expr->unop, reg, ID_type); if (ID_type == 2){ printf("call_builtin print_real \n"); } else if (ID_type == 1 ){ printf("call_builtin print_int \n"); } else{ printf("call_builtin print_bool \n"); } break; case EXPR_ARRAY: ID_type = getExprType(expr, proc_id); reg = calculate_offset(expr->es, 1, expr->id, proc_id); printf("load_indirect r0, r%d\n", reg); if (ID_type == FLOAT_ARRAY_TYPE){ printf("call_builtin print_real \n"); } else if (ID_type == INT_ARRAY_TYPE){ printf("call_builtin print_int \n"); } else{ printf("call_builtin print_bool \n"); } break; } }