core.cc revision 4123
113996Sgiacomo.travaglini@arm.com/*
29525SAndreas.Sandberg@ARM.com * Copyright (c) 2006 The Regents of The University of Michigan
39525SAndreas.Sandberg@ARM.com * All rights reserved.
49525SAndreas.Sandberg@ARM.com *
59525SAndreas.Sandberg@ARM.com * Redistribution and use in source and binary forms, with or without
69525SAndreas.Sandberg@ARM.com * modification, are permitted provided that the following conditions are
79525SAndreas.Sandberg@ARM.com * met: redistributions of source code must retain the above copyright
89525SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer;
99525SAndreas.Sandberg@ARM.com * redistributions in binary form must reproduce the above copyright
109525SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer in the
119525SAndreas.Sandberg@ARM.com * documentation and/or other materials provided with the distribution;
129525SAndreas.Sandberg@ARM.com * neither the name of the copyright holders nor the names of its
139525SAndreas.Sandberg@ARM.com * contributors may be used to endorse or promote products derived from
149525SAndreas.Sandberg@ARM.com * this software without specific prior written permission.
159525SAndreas.Sandberg@ARM.com *
169525SAndreas.Sandberg@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179525SAndreas.Sandberg@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189525SAndreas.Sandberg@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199525SAndreas.Sandberg@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209525SAndreas.Sandberg@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219525SAndreas.Sandberg@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229525SAndreas.Sandberg@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239525SAndreas.Sandberg@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249525SAndreas.Sandberg@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259525SAndreas.Sandberg@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269525SAndreas.Sandberg@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279525SAndreas.Sandberg@ARM.com *
289525SAndreas.Sandberg@ARM.com * Authors: Nathan Binkert
299525SAndreas.Sandberg@ARM.com *          Steve Reinhardt
309525SAndreas.Sandberg@ARM.com */
319525SAndreas.Sandberg@ARM.com
329525SAndreas.Sandberg@ARM.com#include <iostream>
339525SAndreas.Sandberg@ARM.com#include <string>
349525SAndreas.Sandberg@ARM.com
359525SAndreas.Sandberg@ARM.com#include "base/callback.hh"
369525SAndreas.Sandberg@ARM.com#include "base/output.hh"
379525SAndreas.Sandberg@ARM.com
389525SAndreas.Sandberg@ARM.comusing namespace std;
399525SAndreas.Sandberg@ARM.com
4013591Sciro.santilli@arm.comvoid
4110749Smatt.evans@arm.comsetOutputDir(const string &dir)
429525SAndreas.Sandberg@ARM.com{
4313996Sgiacomo.travaglini@arm.com    simout.setDirectory(dir);
4413665Sandreas.sandberg@arm.com}
459525SAndreas.Sandberg@ARM.com
469525SAndreas.Sandberg@ARM.com/**
479525SAndreas.Sandberg@ARM.com * Queue of C++ callbacks to invoke on simulator exit.
489525SAndreas.Sandberg@ARM.com */
499525SAndreas.Sandberg@ARM.cominline CallbackQueue &
509525SAndreas.Sandberg@ARM.comexitCallbacks()
5114152Sgiacomo.travaglini@arm.com{
5214152Sgiacomo.travaglini@arm.com    static CallbackQueue theQueue;
5314152Sgiacomo.travaglini@arm.com    return theQueue;
549525SAndreas.Sandberg@ARM.com}
559525SAndreas.Sandberg@ARM.com
5613505Sgiacomo.travaglini@arm.com/**
5713505Sgiacomo.travaglini@arm.com * Register an exit callback.
5813505Sgiacomo.travaglini@arm.com */
5913505Sgiacomo.travaglini@arm.comvoid
6013505Sgiacomo.travaglini@arm.comregisterExitCallback(Callback *callback)
6113505Sgiacomo.travaglini@arm.com{
6213505Sgiacomo.travaglini@arm.com    exitCallbacks().add(callback);
6313505Sgiacomo.travaglini@arm.com}
6413505Sgiacomo.travaglini@arm.com
6514152Sgiacomo.travaglini@arm.com/**
6614152Sgiacomo.travaglini@arm.com * Do C++ simulator exit processing.  Exported to SWIG to be invoked
6714152Sgiacomo.travaglini@arm.com * when simulator terminates via Python's atexit mechanism.
6814152Sgiacomo.travaglini@arm.com */
6914152Sgiacomo.travaglini@arm.comvoid
7014152Sgiacomo.travaglini@arm.comdoExitCleanup()
7114152Sgiacomo.travaglini@arm.com{
7214152Sgiacomo.travaglini@arm.com    exitCallbacks().process();
7314152Sgiacomo.travaglini@arm.com    exitCallbacks().clear();
7414152Sgiacomo.travaglini@arm.com
7512739Sandreas.sandberg@arm.com    cout.flush();
7612739Sandreas.sandberg@arm.com}
7712739Sandreas.sandberg@arm.com