If you are using Windows there are several tools for recovering music from your iPhone, they were covered in this answer:
Once you get iTunes reinstalled, before you do anything else, turn off all syncing. Then use iTunes to backup the phone.
Once you know you have the phone backed up, then you can setup your sync for contacts etc and let iTunes sync the data from your phone back to iTunes and the apps you have chosen to sync the data to.
When you reinstall your computer you need to make sure you tell iTunes not to manage your music automatically until you have copied the music back into the iTunes library. Otherwise if you aren't careful iTunes will delete all the music on your phone.