observers.cpp revision 12855
16899SN/A/*****************************************************************************
26899SN/A
36899SN/A  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
46899SN/A  more contributor license agreements.  See the NOTICE file distributed
56899SN/A  with this work for additional information regarding copyright ownership.
66899SN/A  Accellera licenses this file to you under the Apache License, Version 2.0
76899SN/A  (the "License"); you may not use this file except in compliance with the
86899SN/A  License.  You may obtain a copy of the License at
96899SN/A
106899SN/A    http://www.apache.org/licenses/LICENSE-2.0
116899SN/A
126899SN/A  Unless required by applicable law or agreed to in writing, software
136899SN/A  distributed under the License is distributed on an "AS IS" BASIS,
146899SN/A  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156899SN/A  implied.  See the License for the specific language governing
166899SN/A  permissions and limitations under the License.
176899SN/A
186899SN/A *****************************************************************************/
196899SN/A
206899SN/A#define SC_ENABLE_OBSERVERS
216899SN/A#define SC_INCLUDE_FX
226899SN/A#include "systemc.h"
236899SN/A
246899SN/A#if SC_CPLUSPLUS < 201103L
256899SN/A# define override /* empty */
266899SN/A#endif // SC_CPLUSPLUS >= 201103L
276899SN/A
286899SN/Atemplate<typename Observed, typename Base>
296899SN/Aclass observer: public Base {
307632SBrad.Beckmann@amd.com    virtual void construct(const Observed&) override {
318232Snate@binkert.org        std::cout << "construct" << std::endl;
327053SN/A    }
336899SN/A    virtual void destruct(const Observed&) override {
346899SN/A        std::cout << "destruct" << std::endl;
356899SN/A    }
367053SN/A    virtual void read(const Observed&) override {
377053SN/A        std::cout << "read" << std::endl;
387053SN/A    }
398932SBrad.Beckmann@amd.com    virtual void write(const Observed&) override {
408932SBrad.Beckmann@amd.com        std::cout << "write" << std::endl;
418932SBrad.Beckmann@amd.com    }
426899SN/A};
437053SN/A
446899SN/Atemplate<typename T, typename Observed, typename Base>
457053SN/Avoid observe(char const *name) {
467053SN/A    std::cout << std::endl;
477053SN/A    std::cout << name << std::endl;
487053SN/A
498164Snilay@cs.wisc.edu    observer<Observed, Base> o;
507053SN/A    T value(&o);
516899SN/A
526899SN/A    std::cout << "to_short  "; value.to_short();
537053SN/A    std::cout << "to_ushort "; value.to_ushort();
547053SN/A    std::cout << "to_int    "; value.to_int();
556899SN/A    std::cout << "to_uint   "; value.to_uint();
567053SN/A    std::cout << "to_long   "; value.to_long();
577053SN/A    std::cout << "to_ulong  "; value.to_ulong();
586899SN/A    std::cout << "to_int64  "; value.to_int64();
597053SN/A    std::cout << "to_uint64 "; value.to_uint64();
607053SN/A    std::cout << "to_float  "; value.to_float();
617053SN/A    std::cout << "to_double "; value.to_double();
627053SN/A}
636899SN/A
648184Ssomayeh@cs.wisc.eduint sc_main(int, char *[]) {
658184Ssomayeh@cs.wisc.edu    observe<sc_fxval, sc_fxval, sc_dt::sc_fxval_observer>("sc_fxval");
668184Ssomayeh@cs.wisc.edu    observe<sc_fxval_fast, sc_fxval_fast, sc_dt::sc_fxval_fast_observer>("sc_fxval_fast");
678184Ssomayeh@cs.wisc.edu    observe<sc_fixed<1, 2>, sc_fxnum, sc_dt::sc_fxnum_observer>("sc_fixed");
687053SN/A    observe<sc_fixed_fast<3, 4>, sc_fxnum_fast, sc_dt::sc_fxnum_fast_observer>("sc_fixed_fast");
697053SN/A    observe<sc_ufixed<5, 6>, sc_fxnum, sc_dt::sc_fxnum_observer>("sc_ufixed");
707053SN/A    observe<sc_ufixed_fast<7, 8>, sc_fxnum_fast, sc_dt::sc_fxnum_fast_observer>("sc_ufixed_fast");
717053SN/A
727053SN/A    return 0;
737053SN/A}
747053SN/A