📄 main.cc
字号:
parent_instr->set_src_op(src_num, operand(loaded_var)); } else { in_rrr *new_copy = new in_rrr(io_cpy, loaded_var->type(), operand(), operand(loaded_var)); replace_instruction(the_load, new_copy); } delete the_load; } break; } case io_str: { in_rrr *the_store = (in_rrr *)the_instr; var_sym *stored_var; boolean is_var = is_simple_var_addr(the_store->dst_addr_op(), &stored_var); if (is_var) { operand data_op = the_store->src2_op(); data_op.remove(); instruction *new_instr; if (data_op.is_expr()) { new_instr = data_op.instr(); } else { new_instr = new in_rrr(io_cpy, stored_var->type(), operand(), data_op); } replace_instruction(the_store, new_instr); new_instr->set_dst(operand(stored_var)); delete the_store; } break; } case io_memcpy: { in_rrr *the_memcopy = (in_rrr *)the_instr; var_sym *loaded_var; boolean load_is_var = is_simple_var_addr(the_memcopy->src_addr_op(), &loaded_var); var_sym *stored_var; boolean store_is_var = is_simple_var_addr(the_memcopy->dst_addr_op(), &stored_var); if (load_is_var && store_is_var) { in_rrr *new_copy = new in_rrr(io_cpy, loaded_var->type(), operand(), operand(loaded_var)); replace_instruction(the_memcopy, new_copy); new_copy->set_dst(operand(stored_var)); delete the_memcopy; } else if (load_is_var) { operand dst_addr = the_memcopy->dst_addr_op(); dst_addr.remove(); in_rrr *new_store = new in_rrr(io_str, type_void, operand(), dst_addr, operand(loaded_var)); replace_instruction(the_memcopy, new_store); delete the_memcopy; } else if (store_is_var) { operand src_addr = the_memcopy->src_addr_op(); src_addr.remove(); in_rrr *new_load = new in_rrr(io_lod, stored_var->type(), operand(), src_addr); replace_instruction(the_memcopy, new_load); new_load->set_dst(operand(stored_var)); delete the_memcopy; } break; } default: break; } }static void deallocate_operand(operand to_go) { if (!to_go.is_expr()) return; instruction *the_instr = to_go.instr(); assert(the_instr != NULL); delete the_instr; }static operand build_offset_operand(array_type *the_array_type, int num_dimensions) { array_type *follow_array = the_array_type; operand result = const_op(immed(0), type_ptr_diff); int dim_num = 0; while (dim_num < num_dimensions) { operand upper_op = operand_from_array_bound(follow_array->upper_bound()); operand lower_op = operand_from_array_bound(follow_array->lower_bound()); result *= ((upper_op - lower_op.clone()) + 1); result += lower_op; type_node *next_type = follow_array->elem_type(); assert(next_type != NULL); if (!next_type->is_array()) return result; follow_array = (array_type *)next_type; ++dim_num; } return result; }static char *last_field(immed_list *field_immeds) { char *result = NULL; immed_list_iter the_iter(field_immeds); while (!the_iter.is_empty()) { immed value = the_iter.step(); if (!value.is_string()) return NULL; result = value.string(); } return result; }static char *guess_base_var_name(in_array *the_array) { if (the_array == NULL) return NULL; operand index = the_array->index(0); if (!index.is_instr()) return NULL; instruction *index_instr = index.instr(); assert(index_instr != NULL); while (index_instr->opcode() == io_cvt) { in_rrr *the_cvt = (in_rrr *)index_instr; index = the_cvt->src_op(); if (!index.is_instr()) return NULL; index_instr = index.instr(); assert(index_instr != NULL); } /* skip multiplication done for character strings */ if (index_instr->opcode() == io_mul) { in_rrr *the_div = (in_rrr *)index_instr; index = the_div->src1_op(); if (!index.is_instr()) return NULL; index_instr = index.instr(); assert(index_instr != NULL); } while (index_instr->opcode() == io_cvt) { in_rrr *the_cvt = (in_rrr *)index_instr; index = the_cvt->src_op(); if (!index.is_instr()) return NULL; index_instr = index.instr(); assert(index_instr != NULL); } if (index_instr->opcode() != io_sub) return NULL; in_rrr *the_sub = (in_rrr *)index_instr; operand subtracted = the_sub->src2_op(); while (subtracted.is_expr() && (subtracted.instr()->opcode() == io_cvt)) { in_rrr *the_cvt = (in_rrr *)(subtracted.instr()); subtracted = the_cvt->src_op(); } if (!subtracted.is_symbol()) return NULL; var_sym *the_symbol = subtracted.symbol(); if (the_symbol == NULL) return NULL; char *sym_name = the_symbol->name(); if (sym_name == NULL) return NULL; char *suffix = strstr(sym_name, "_offset"); if (suffix == NULL) return NULL; if (strcmp(suffix, "_offset") != 0) return NULL; char *result = new char[suffix - sym_name + 1]; strncpy(result, sym_name, suffix - sym_name); result[suffix - sym_name] = 0; return result; }/* * This function takes the operand ``original'' and breaks it up into * *op_a and *op_b such that * * *op_a + (the_var * (*op_b)) = original * * with as much of the operand as possible in *op_b. */static void linear_form(operand *op_a, operand *op_b, operand original, var_sym *the_var) { type_node *the_type = original.type(); switch (original.kind()) { case OPER_NULL: { *op_a = operand(); *op_b = operand(); break; } case OPER_SYM: { if (original.symbol() == the_var) { *op_a = const_op(immed(0), the_type); *op_b = const_op(immed(1), the_type); } else { *op_a = original; *op_b = const_op(immed(0), the_type); } break; } case OPER_INSTR: { instruction *the_instr = original.instr(); assert(the_instr != NULL); switch(the_instr->opcode()) { case io_cpy: case io_cvt: { in_rrr *the_rrr = (in_rrr *)the_instr; assert(the_rrr->src2_op().is_null()); operand source1 = the_rrr->src1_op(); source1.remove(); delete the_rrr; linear_form(op_a, op_b, source1, the_var); break; } case io_add: { in_rrr *the_rrr = (in_rrr *)the_instr; operand source1 = the_rrr->src1_op(); source1.remove(); operand source2 = the_rrr->src2_op(); source2.remove(); delete the_rrr; operand op_a1, op_a2, op_b1, op_b2; linear_form(&op_a1, &op_b1, source1, the_var); linear_form(&op_a2, &op_b2, source2, the_var); *op_a = (op_a1 + op_a2); *op_b = (op_b1 + op_b2); break; } case io_sub: { in_rrr *the_rrr = (in_rrr *)the_instr; operand source1 = the_rrr->src1_op(); source1.remove(); operand source2 = the_rrr->src2_op(); source2.remove(); delete the_rrr; operand op_a1, op_a2, op_b1, op_b2; linear_form(&op_a1, &op_b1, source1, the_var); linear_form(&op_a2, &op_b2, source2, the_var); *op_a = (op_a1 - op_a2); *op_b = (op_b1 - op_b2); break; } case io_neg: { in_rrr *the_rrr = (in_rrr *)the_instr; assert(the_rrr->src2_op().is_null()); operand source1 = the_rrr->src1_op(); source1.remove(); delete the_rrr; operand op_a1, op_b1; linear_form(&op_a1, &op_b1, source1, the_var); *op_a = -op_a1; *op_b = -op_b1; break; } case io_mul: { in_rrr *the_rrr = (in_rrr *)the_instr; operand source1 = the_rrr->src1_op(); source1.remove(); operand source2 = the_rrr->src2_op(); source2.remove(); delete the_rrr; operand op_a1, op_a2, op_b1, op_b2; linear_form(&op_a1, &op_b1, source1, the_var); linear_form(&op_a2, &op_b2, source2, the_var); if (is_zero(op_b1)) { nullify_operand(&op_b1); *op_a = (op_a1.clone() * op_a2); *op_b = (op_b2 * op_a1); } else if (is_zero(op_b2)) { nullify_operand(&op_b2); *op_a = (op_a2.clone() * op_a1); *op_b = (op_b1 * op_a2); } else { operand new_a1 = op_a1.clone(); operand new_a2 = op_a2.clone(); operand new_b1 = op_b1.clone(); operand new_b2 = op_b2.clone(); *op_a = (op_a1 * op_a2); *op_b = ((new_b1 * new_a2) + (new_a1 * new_b2) + (operand(the_var) * op_b1 * op_b2)); } break; } case io_lsl: { in_rrr *the_rrr = (in_rrr *)the_instr; operand source2 = the_rrr->src2_op(); if (source2.is_expr()) { instruction *source_2_instr = source2.instr(); assert(source_2_instr != NULL); if (source_2_instr->opcode() == io_ldc) { in_ldc *the_ldc = (in_ldc *)source_2_instr; immed value = the_ldc->value(); if (value.is_integer()) { int shift_amount = value.integer(); if ((shift_amount >= 0) && (shift_amount < (int)sizeof(int))) { operand source1 = the_rrr-
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -