view core/src/Trace.bsv @ 55:d0db18cdeacc pygar svn.56

[svn r56] added submodule
author punk
date Sun, 09 May 2010 17:47:21 -0400
parents 91a1f76ddd62
children
line wrap: on
line source

2 import ClientServer::*;
3 import GetPut::*;
5 //----------------------------------------------------------------------
6 // ToString typeclass
7 //----------------------------------------------------------------------
9 typeclass Traceable#( type item_t );
10 function Action traceTiny( String loc, String traceTag, item_t item );
11 function Action traceFull( String loc, String traceTag, item_t item );
12 endtypeclass
14 instance Traceable#(String);
16 function Action traceTiny( String loc, String ttag, String str );
17 $fdisplay(stderr, " => %s:%s %s", loc, ttag, str );
18 endfunction
20 function Action traceFull( String loc, String ttag, String str );
21 $fdisplay(stderr, " => %s:%s %s", loc, ttag, str );
22 endfunction
24 endinstance
26 instance Traceable#(Bit#(n));
28 function Action traceTiny( String loc, String ttag, Bit#(n) b );
29 $fdisplay(stderr, " => %s:%s %x", loc, ttag, b );
30 endfunction
32 function Action traceFull( String loc, String ttag, Bit#(n) b );
33 $fdisplay(stderr, " => %s:%s %x", loc, ttag, b );
34 endfunction
36 endinstance
38 //----------------------------------------------------------------------
39 // Tracing interface wrappers
40 //----------------------------------------------------------------------
42 function Get#(item_t) traceGet( String locStr, String tagStr, Get#(item_t) g )
43 provisos ( Traceable#(item_t) );
44 return
45 (
46 interface Get
47 method ActionValue#(item_t) get();
48 item_t item <- g.get();
49 traceTiny(locStr, tagStr,item);
50 return item;
51 endmethod
52 endinterface
53 );
54 endfunction
56 function Put#(item_t) tracePut( String locStr, String tagStr, Put#(item_t) p )
57 provisos ( Traceable#(item_t) );
58 return
59 (
60 interface Put
61 method Action put( item_t item );
62 traceTiny(locStr, tagStr,item);
63 p.put(item);
64 endmethod
65 endinterface
66 );
67 endfunction
69 function Client#(req_t,resp_t) traceClient( String locStr, String reqTagStr, String respTagStr,
70 Client#(req_t,resp_t) c )
71 provisos ( Traceable#(req_t), Traceable#(resp_t) );
72 return
73 (
74 interface Client
75 interface Get request = traceGet(locStr, reqTagStr,c.request);
76 interface Put response = tracePut(locStr, respTagStr,c.response);
77 endinterface
78 );
79 endfunction
81 function Server#(req_t,resp_t) traceServer( String locStr, String reqTagStr, String respTagStr,
82 Server#(req_t,resp_t) c )
83 provisos ( Traceable#(req_t), Traceable#(resp_t) );
84 return
85 (
86 interface Server
87 interface Put request = tracePut(locStr, reqTagStr,c.request);
88 interface Get response = traceGet(locStr, respTagStr,c.response);
89 endinterface
90 );
91 endfunction