CORBA::Boolean TIDorb::core::typecode::StructTypeCode::equal(CORBA::TypeCode_ptr tc) const { if (!ComplexTypeCode::equal(tc)) return false; if (!m_exhaustive_equal) return true; try { CORBA::ULong length = m_members->length(); if (length != tc->member_count()) return false; for (CORBA::ULong i = 0; i < length; i++) { if (strcmp(member_name(i), tc->member_name(i))) return false; if (! member_type(i)->equal(tc->member_type(i))) return false; } // allright return true; } catch (const CORBA::TypeCode::BadKind& bk) { return false; } catch (const CORBA::TypeCode::Bounds& bn) { return false; } }
void UnionTypeCode::dump (ostream& output) const { CORBA::ULong length = m_members->length(); output << "[TYPECODE]{union (" << length << " members) "; ComplexTypeCode::dump_params(output); output << " {"; TypeCodeImpl* my_member_type; CORBA::Any* my_member_label; for (CORBA::ULong i = 0; i < length; i++) { output << " case "; my_member_label =&(((*m_members)[i]).label); my_member_label->delegate().dump(output); output<< ": " << member_name(i) << " -> "; my_member_type = (TypeCodeImpl*)((CORBA::TypeCode_ptr)(*m_members)[i].type); my_member_type->dump(output); output << " | "; } output << '}'; }
static void write_struct(CTX *ctx, struct ir_struct_type *st, char *name) { assert(ctx->writing_types); wf(ctx, "struct %s;", name); wf(ctx, "typedef struct %s %s;", name, name); // Make sure all types are written out first. for (int n = 0; n < st->members_count; n++) { struct ir_struct_member *m = st->members[n]; def_type(ctx, m->type); } set_loc(ctx, st->loc); wf(ctx, "struct %s {", name); indent_in(ctx); for (int n = 0; n < st->members_count; n++) { struct ir_struct_member *m = st->members[n]; struct name_temp t; char *mname = member_name(m, &t); set_loc(ctx, m->loc); wf(ctx, "%s %s;", def_type(ctx, m->type), mname); } indent_out(ctx); wf(ctx, "};"); set_no_loc(ctx); }
static void write_inst(CTX *ctx, struct ir_inst *in, bool inner) { if (in->comment) P(ctx, " /* COMMENT: %s */ ", in->comment); // @ALL ir_opcode switch (in->op) { case IR_OP_NOP: break; case IR_OP_COPY: P(ctx, "%s", R0); break; case IR_OP_GOTO: P(ctx, "goto B%d", BR(in, 0)); break; case IR_OP_BRANCH: P(ctx, "if (%s) goto B%d; else goto B%d", R0, BR(in, 1), BR(in, 0)); break; case IR_OP_RET: if (type_is_void(inst_getuse(in, 0)->result_type)) { P(ctx, "return"); } else { P(ctx, "return %s", R0); } break; case IR_OP_ABORT: P(ctx, "abort()"); break; case IR_OP_GETARG: P(ctx, "A%d", in->struct_member->index); break; case IR_OP_READ_VAR: P(ctx, "V%d", in->var->index); break; case IR_OP_WRITE_VAR: P(ctx, "V%d = %s", in->var->index, R0); break; case IR_OP_VAR_PTR: P(ctx, "&V%d", in->var->index); break; case IR_OP_GET_STRUCT_MEMBER_PTR: { struct name_temp t; P(ctx, "&(%s->%s)", R0, member_name(in->struct_member, &t)); break; } case IR_OP_CONSTRUCT_STRUCT: { if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{"); print_reads(ctx, in, 0); P(ctx, "}"); break; } case IR_OP_GET_STRUCT_MEMBER: { struct name_temp t; P(ctx, "%s.%s", R0, member_name(in->struct_member, &t)); break; } case IR_OP_SET_STRUCT_MEMBER: { //struct name_temp t; //bstr name = member_name(in->struct_member, &t); //P(ctx, "%s; %s.%.*s = %s", R0, in->write, BSTR_P(name), R1); abort(); break; } case IR_OP_MAKE_CLOSURE: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{ (void*)%s, %s }", R0, R1); break; case IR_OP_GET_CLOSURE_FN: P(ctx, "(%s) %s.fn", type(ctx, in->result_type), R0); break; case IR_OP_GET_CLOSURE_CTX: P(ctx, "%s.ctx", R0); break; case IR_OP_CONSTRUCT_SLICE: case IR_OP_SLICE: case IR_OP_SLICE_COPY: case IR_OP_SLICE_SET: assert(false); //TODO case IR_OP_GET_SLICE_LENGTH: P(ctx, "%s.len", R0); break; case IR_OP_GET_SLICE_PTR: P(ctx, "(%s)%s.ptr", type(ctx, in->result_type), R0); break; case IR_OP_GET_SLICE_ITEM_PTR: P(ctx, "(assert(%s < %s.len), ((%s)%s.ptr) + %s)", R1, R0, type(ctx, in->result_type), R0, R1); break; case IR_OP_CONSTRUCT_ARRAY: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{ {"); print_reads(ctx, in, 0); P(ctx, "} }"); break; case IR_OP_ARRAY_TO_SLICE: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{ &%s->a[0], %d }", R0, type_array_get_dimension (type_unptr(inst_getuse(in, 0)->result_type))); break; case IR_OP_READ_PTR: P(ctx, "*%s", R0); break; case IR_OP_WRITE_PTR: P(ctx, "*%s = %s", R0, R1); break; case IR_OP_LOAD_CONST: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); write_const(ctx, *in->const_value); break; case IR_OP_FN_PTR: P(ctx, "%s", def_fn(ctx, in->fn)); break; case IR_OP_CALL: { P(ctx, "%s(", def_fn(ctx, in->fn)); print_reads(ctx, in, 0); P(ctx, ")"); break; } case IR_OP_CALL_PTR: { P(ctx, "%s(", R0); print_reads(ctx, in, 1); P(ctx, ")"); break; } case IR_OP_NEG: P(ctx, "-%s", R0); break; case IR_OP_NOT: if (in->result_type.type == IR_TYPE_tbool) { // C promotes the bool to a larger integer, "~" won't work. P(ctx, "!%s", R0); } else { P(ctx, "~%s", R0); } break; case IR_OP_CONV_INT_SIGN: case IR_OP_CONV_INT_EXT: case IR_OP_CONV_INT_TRUNC: case IR_OP_CONV_TO_G_PTR: case IR_OP_CONV_FROM_G_PTR: P(ctx, "(%s)%s", type(ctx, in->result_type), R0); break; case IR_OP_ADD: case IR_OP_SUB: case IR_OP_MUL: case IR_OP_DIV: case IR_OP_MOD: case IR_OP_AND: case IR_OP_OR: case IR_OP_XOR: case IR_OP_SHIFT_R: case IR_OP_SHIFT_L: case IR_OP_EQ: case IR_OP_NOT_EQ: case IR_OP_CMP_LT: case IR_OP_CMP_GT: case IR_OP_CMP_LT_EQ: case IR_OP_CMP_GT_EQ: { // C integer promotion makes it hard to avoid the cast here. P(ctx, "(%s)(%s %s %s)", type(ctx, in->result_type), R0, optable[in->op], R1); break; } // not applicable case IR_OP_UPVAL_PTR: case IR_OP_UPVAL_CONTEXT: case IR_OP_PHI: assert(false); default: assert(false); } }
void local_SSAt::assign_rec( const exprt &lhs, const exprt &rhs, const exprt &guard, locationt loc) { const typet &type=ns.follow(lhs.type()); if(is_symbol_struct_member(lhs, ns)) { if(type.id()==ID_struct) { // need to split up const struct_typet &struct_type=to_struct_type(type); const struct_typet::componentst &components=struct_type.components(); for(struct_typet::componentst::const_iterator it=components.begin(); it!=components.end(); it++) { member_exprt new_lhs(lhs, it->get_name(), it->type()); member_exprt new_rhs(rhs, it->get_name(), it->type()); assign_rec(new_lhs, new_rhs, guard, loc); } return; } ssa_objectt lhs_object(lhs, ns); const std::set<ssa_objectt> &assigned= assignments.get(loc); if(assigned.find(lhs_object)!=assigned.end()) { exprt ssa_rhs=read_rhs(rhs, loc); const symbol_exprt ssa_symbol=name(lhs_object, OUT, loc); equal_exprt equality(ssa_symbol, ssa_rhs); nodes[loc].equalities.push_back(equality); } } else if(lhs.id()==ID_index) { const index_exprt &index_expr=to_index_expr(lhs); exprt ssa_array=index_expr.array(); exprt new_rhs=with_exprt(ssa_array, index_expr.index(), rhs); assign_rec(index_expr.array(), new_rhs, guard, loc); } else if(lhs.id()==ID_member) { // These are non-flattened struct or union members. const member_exprt &member_expr=to_member_expr(lhs); const exprt &compound=member_expr.struct_op(); const typet &compound_type=ns.follow(compound.type()); if(compound_type.id()==ID_union) { union_exprt new_rhs(member_expr.get_component_name(), rhs, compound.type()); assign_rec(member_expr.struct_op(), new_rhs, guard, loc); } else if(compound_type.id()==ID_struct) { exprt member_name(ID_member_name); member_name.set(ID_component_name, member_expr.get_component_name()); with_exprt new_rhs(compound, member_name, rhs); assign_rec(compound, new_rhs, guard, loc); } } else if(lhs.id()==ID_complex_real) { assert(lhs.operands().size()==1); const exprt &op=lhs.op0(); const complex_typet &complex_type=to_complex_type(op.type()); exprt imag_op=unary_exprt(ID_complex_imag, op, complex_type.subtype()); complex_exprt new_rhs(rhs, imag_op, complex_type); assign_rec(op, new_rhs, guard, loc); } else if(lhs.id()==ID_complex_imag) { assert(lhs.operands().size()==1); const exprt &op=lhs.op0(); const complex_typet &complex_type=to_complex_type(op.type()); exprt real_op=unary_exprt(ID_complex_real, op, complex_type.subtype()); complex_exprt new_rhs(real_op, rhs, complex_type); assign_rec(op, new_rhs, guard, loc); } else if(lhs.id()==ID_if) { const if_exprt &if_expr=to_if_expr(lhs); assign_rec(if_expr.true_case(), rhs, and_exprt(guard, if_expr.cond()), loc); assign_rec(if_expr.false_case(), rhs, and_exprt(guard, not_exprt(if_expr.cond())), loc); } else if(lhs.id()==ID_byte_extract_little_endian || lhs.id()==ID_byte_extract_big_endian) { const byte_extract_exprt &byte_extract_expr=to_byte_extract_expr(lhs); exprt new_lhs=byte_extract_expr.op(); exprt new_rhs=byte_extract_exprt( byte_extract_expr.id(), rhs, byte_extract_expr.offset(), new_lhs.type()); assign_rec(new_lhs, new_rhs, guard, loc); } else throw "UNKNOWN LHS: "+lhs.id_string(); }