int code_stmt(ASTNode stmt,int BASEREG){ switch(stmt->type){ case Block: code_block(stmt,BASEREG); break; case IfClause: code_ifclause(stmt,BASEREG); break; case AssignExp: code_assign(stmt,BASEREG); break; case NilStmt: stmt->codes.head=stmt->codes.tail=NULL; break; case WhileClause: code_whileclause(stmt,BASEREG); break; case FunctionCall: code_call(stmt,BASEREG); break; default: fprintf(stderr,"unsupported stmt\n"); } return 0; }
void goto_inlinet::replace_return( goto_programt &dest, const exprt &lhs, const exprt &constrain) { for(goto_programt::instructionst::iterator it=dest.instructions.begin(); it!=dest.instructions.end(); it++) { if(it->is_return()) { if(lhs.is_not_nil()) { goto_programt tmp; goto_programt::targett assignment=tmp.add_instruction(ASSIGN); const code_return2t &ret = to_code_return2t(it->code); code_assignt code_assign(lhs, migrate_expr_back(ret.operand)); // this may happen if the declared return type at the call site // differs from the defined return type if(code_assign.lhs().type()!= code_assign.rhs().type()) code_assign.rhs().make_typecast(code_assign.lhs().type()); migrate_expr(code_assign, assignment->code); assignment->location=it->location; assignment->local_variables=it->local_variables; assignment->function=it->location.get_function(); assert(constrain.is_nil()); // bp_constrain gumpf reomved dest.insert_swap(it, *assignment); it++; } else if(!is_nil_expr(it->code)) { // Encode evaluation of return expr, so that returns with pointer // derefs in them still get dereferenced, even when the result is // discarded. goto_programt tmp; goto_programt::targett expression=tmp.add_instruction(OTHER); expression->make_other(); expression->location=it->location; expression->function=it->location.get_function(); expression->local_variables=it->local_variables; const code_return2t &ret = to_code_return2t(it->code); expression->code = code_expression2tc(ret.operand); dest.insert_swap(it, *expression); it++; } it->make_goto(--dest.instructions.end()); } } }
symbol_exprt goto_convertt::make_compound_literal( const exprt &expr, goto_programt &dest) { const locationt location=expr.find_location(); symbolt new_symbol; symbolt *symbol_ptr; do { // The lifetime of compound literals is really that of // the block they are in. new_symbol.base_name="literal$"+i2string(++temporary_counter); new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name); new_symbol.is_lvalue=true; new_symbol.is_thread_local=false; new_symbol.is_static_lifetime=true; new_symbol.is_file_local=true; new_symbol.value=expr; new_symbol.type=expr.type(); new_symbol.location=location; } while(symbol_table.move(new_symbol, symbol_ptr)); // The value might depend on a variable, thus // generate code for this. symbol_exprt result=symbol_ptr->symbol_expr(); result.location()=location; code_assignt code_assign(result, expr); code_assign.location()=location; convert(code_assign, dest); return result; }
void goto_inlinet::replace_return( goto_programt &dest, const exprt &lhs, const exprt &constrain) { for(goto_programt::instructionst::iterator it=dest.instructions.begin(); it!=dest.instructions.end(); it++) { if(it->is_return()) { #if 0 if(lhs.is_not_nil()) { if(it->code.operands().size()!=1) { error().source_location=it->code.find_source_location(); str << "return expects one operand!"; warning_msg(); continue; } goto_programt tmp; goto_programt::targett assignment=tmp.add_instruction(ASSIGN); code_assignt code_assign(lhs, it->code.op0()); // this may happen if the declared return type at the call site // differs from the defined return type if(code_assign.lhs().type()!= code_assign.rhs().type()) code_assign.rhs().make_typecast(code_assign.lhs().type()); assignment->code=code_assign; assignment->source_location=it->source_location; assignment->function=it->function; if(constrain.is_not_nil() && !constrain.is_true()) { codet constrain(ID_bp_constrain); constrain.reserve_operands(2); constrain.move_to_operands(assignment->code); constrain.copy_to_operands(constrain); } dest.insert_before_swap(it, *assignment); it++; } else if(!it->code.operands().empty()) { goto_programt tmp; goto_programt::targett expression=tmp.add_instruction(OTHER); expression->code=codet(ID_expression); expression->code.move_to_operands(it->code.op0()); expression->source_location=it->source_location; expression->function=it->function; dest.insert_before_swap(it, *expression); it++; } it->make_goto(--dest.instructions.end()); #else if(lhs.is_not_nil()) { if(it->code.operands().size()!=1) { warning().source_location=it->code.find_source_location(); warning() << "return expects one operand!\n" << it->code.pretty() << eom; continue; } code_assignt code_assign(lhs, it->code.op0()); // this may happen if the declared return type at the call site // differs from the defined return type if(code_assign.lhs().type()!= code_assign.rhs().type()) code_assign.rhs().make_typecast(code_assign.lhs().type()); if(constrain.is_not_nil() && !constrain.is_true()) { codet constrain(ID_bp_constrain); constrain.reserve_operands(2); constrain.move_to_operands(code_assign); constrain.copy_to_operands(constrain); it->code=constrain; it->type=OTHER; } else { it->code=code_assign; it->type=ASSIGN; } it++; } else if(!it->code.operands().empty()) { codet expression(ID_expression); expression.move_to_operands(it->code.op0()); it->code=expression; it->type=OTHER; it++; } #endif } } }