Fix a bug of output stream error of mapping file

Previously we open and close the mapping file many times. This may cause
a bug if we use the stdout as the mapping file output. We now open the
mapping file in the runOnModule() function and pass the raw_ostream to
the mapping funtion/file functions.