📄 genop.cc
字号:
*the_type = longtype; else if (immed_fits(result_value, unsignedlong)) *the_type = unsignedlong; else if (immed_fits(result_value, longlong)) *the_type = longlong; else *the_type = unsignedlonglong; } else if (u_suffix) { if (immed_fits(result_value, unsignedtype)) *the_type = unsignedtype; else if (immed_fits(result_value, unsignedlong)) *the_type = unsignedlong; else *the_type = unsignedlonglong; } else { if (radix == 10) { if (immed_fits(result_value, inttype)) *the_type = inttype; else if (immed_fits(result_value, longtype)) *the_type = longtype; else if (immed_fits(result_value, unsignedlong)) *the_type = unsignedlong; else if (immed_fits(result_value, longlong)) *the_type = longlong; else *the_type = unsignedlonglong; } else { if (immed_fits(result_value, inttype)) *the_type = inttype; else if (immed_fits(result_value, unsignedtype)) *the_type = unsignedtype; else if (immed_fits(result_value, longtype)) *the_type = longtype; else if (immed_fits(result_value, unsignedlong)) *the_type = unsignedlong; else if (immed_fits(result_value, longlong)) *the_type = longlong; else *the_type = unsignedlonglong; } } if (!immed_fits(result_value, *the_type)) { warning("overflow in constant `%s'\n", C_intconst); eval_status status = fit_immed(&result_value, *the_type); assert(status == EVAL_OVERFLOW); } } return result_value; }extern immed immed_and_type_for_C_floatconst(char *C_floatconst, type_node **the_type) { char *follow = (char *)cp; assert(follow > C_floatconst); --follow; type_node *result_type; if ((*follow == 'f') || (*follow == 'F')) result_type = floattype; else if ((*follow == 'l') || (*follow == 'L')) result_type = longdouble; else result_type = doubletype; if (the_type != NULL) *the_type = result_type; assert(result_type->op() == TYPE_FLOAT); if (native_floating_arithmetic_ok((base_type *)result_type)) { double double_value = 0; follow = C_floatconst; double_value = strtod(C_floatconst, NULL); return immed(double_value); } else { char *mantissa = new char[((char *)cp - C_floatconst) + 1]; i_integer additional_exponent(0); follow = C_floatconst; char *follow_mantissa = mantissa; while ((*follow >= '0') && (*follow <= '9')) { *follow_mantissa = *follow; ++follow_mantissa; ++additional_exponent; ++follow; } if (*follow == '.') { ++follow; while ((*follow >= '0') && (*follow <= '9')) { *follow_mantissa = *follow; ++follow_mantissa; ++follow; } } while ((follow_mantissa > mantissa) && (*(follow_mantissa - 1) == '0')) --follow_mantissa; *follow_mantissa = 0; follow_mantissa = mantissa; while (*follow_mantissa == '0') { ++follow_mantissa; --additional_exponent; } i_integer exponent(0); if ((*follow == 'e') || (*follow == 'E')) { ++follow; exponent.read(follow); } exponent += (additional_exponent - 1); unsigned long exponent_length = exponent.written_length().c_unsigned_long(); char *result_string = new char[strlen(follow_mantissa) + exponent_length + 8]; char *follow_result = result_string; if (*follow_mantissa == 0) { *follow_result = '0'; } else { *follow_result = *follow_mantissa; ++follow_mantissa; } ++follow_result; *follow_result = '.'; ++follow_result; if (*follow_mantissa == 0) { *follow_result = '0'; ++follow_result; } else { while (*follow_mantissa != 0) { *follow_result = *follow_mantissa; ++follow_result; ++follow_mantissa; } } *follow_result = 'e'; ++follow_result; if (!exponent.is_negative()) { *follow_result = '+'; ++follow_result; } exponent.write(follow_result); immed result_value = immed(im_extended_float, result_string); delete[] result_string; delete[] mantissa; return result_value; } }static void side_effect_list(tree_node_list *the_list, tree_node_list_e *position, operand the_operand) { assert(the_list != NULL); tree_node_list *side_effects = reduce_to_side_effects(the_operand); if (side_effects != NULL) { the_list->insert_before(side_effects, position); delete side_effects; } }static void written_and_not_read(sym_node_list *sym_list, tree_node_list *node_list) { assert(sym_list != NULL); if (node_list == NULL) return; tree_node_list_iter the_iter(node_list); while (!the_iter.is_empty()) { tree_node *this_node = the_iter.step(); switch (this_node->kind()) { case TREE_INSTR: { tree_instr *this_tree_instr = (tree_instr *)this_node; instruction *this_instr = this_tree_instr->instr(); assert(this_instr != NULL); prune_out_reads(sym_list, this_instr); operand destination = this_instr->dst_op(); if (!destination.is_symbol()) break; sym_node *this_symbol = destination.symbol(); assert(this_symbol != NULL); if (this_symbol->is_userdef()) break; if (sym_list->lookup(this_symbol) == NULL) sym_list->append(this_symbol); break; } case TREE_IF: { tree_if *the_if = (tree_if *)this_node; written_and_not_read(sym_list, the_if->header()); written_and_not_read(sym_list, the_if->then_part()); written_and_not_read(sym_list, the_if->else_part()); break; } default: /* * This should never happen since this function should only be * called on lists of instructions and tree_if's. */ assert(FALSE); } } }static void find_temps_read_once(sym_node_list *sym_list, tree_node_list *node_list) { sym_node_list read_multiple; prune_once_read_on_node_list(sym_list, &read_multiple, node_list); while (!read_multiple.is_empty()) { sym_node_list_e *this_element = read_multiple.head(); read_multiple.remove(this_element); delete this_element; } }static void prune_once_read_on_node_list(sym_node_list *read_once, sym_node_list *read_multiple, tree_node_list *node_list) { read_once_data read_data; read_data.read_once = read_once; read_data.read_multiple = read_multiple; node_list->map(&prune_once_read_on_node, &read_data); }static void prune_once_read_on_node(tree_node *the_node, void *data) { assert(the_node != NULL); if (!the_node->is_instr()) return; tree_instr *the_tree_instr = (tree_instr *)the_node; the_tree_instr->instr_map(&prune_once_read_on_instr, data); }static void prune_once_read_on_instr(instruction *the_instr, void *data) { assert(the_instr != NULL); assert(data != NULL); read_once_data *read_data = (read_once_data *)data; unsigned num_srcs = the_instr->num_srcs(); for (unsigned src_num = 0; src_num < num_srcs; ++src_num) { operand source = the_instr->src_op(src_num); if (source.is_symbol()) { var_sym *the_var = source.symbol(); if (!the_var->is_userdef()) { sym_node_list_e *the_element = read_data->read_multiple->lookup(the_var); if (the_element == NULL) { the_element = read_data->read_once->lookup(the_var); if (the_element == NULL) { read_data->read_once->append(the_var); } else { read_data->read_once->remove(the_element); delete the_element; read_data->read_multiple->append(the_var); } } } } } if (the_instr->opcode() == io_ldc) { in_ldc *the_ldc = (in_ldc *)the_instr; immed value = the_ldc->value(); if (value.is_symbol()) { sym_node *the_symbol = value.symbol(); if (!the_symbol->is_userdef()) { remove_sym_from_list(read_data->read_once, the_symbol); read_data->read_multiple->append(the_symbol); } } } }static void remove_sym_from_list(sym_node_list *the_list, sym_node *symbol) { assert(symbol != NULL); sym_node_list_e *the_element = the_list->lookup(symbol); if (the_element != NULL) { the_list->remove(the_element); delete the_element; return; } }static void attempt_combination(sym_node_list *read_once, tree_node_list *node_list) { assert(read_once != NULL); assert(node_list != NULL); tree_node_list_iter node_iter(node_list); while (!node_iter.is_empty()) { tree_node *first_node = node_iter.step(); assert(first_node != NULL); if (!first_node->is_instr()) continue; tree_instr *first_instr_node = (tree_instr *)first_node; instruction *first_instr = first_instr_node->instr(); assert(first_instr != NULL); if (node_iter.is_empty()) break; tree_node *second_node = node_iter.peek(); assert(second_node != NULL); if (!second_node->is_instr()) continue; tree_instr *second_instr_node = (tree_instr *)second_node; instruction *second_instr = second_instr_node->instr(); assert(second_instr != NULL); operand first_destination = first_instr->dst_op(); if (!first_destination.is_symbol())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -