Browse Source

Refactoring of tlm_target and extnesion of loggin system

* Refactoring of tlm_target to be used by reference and by inheritance
* sr_report has been added as well as a report handler to sysc::Logger
Eyck Jentzsch 2 years ago
parent
commit
187fd9b4ce

+ 6
- 0
.gitmodules View File

@@ -0,0 +1,6 @@
1
+[submodule "incl/sr_signal"]
2
+	path = incl/sr_signal
3
+	url = https://github.com/socrocket/sr_signal.git
4
+[submodule "incl/sr_report"]
5
+	path = incl/sr_report
6
+	url = https://github.com/socrocket/sr_report.git

+ 1
- 1
README.md View File

@@ -1,7 +1,7 @@
1 1
 SystemC-Components (SCC)
2 2
 ========================
3 3
 
4
-SCC is supposed to be a light weight productivity llibrary for SystemC and TLM 2.0 based modelling tasks.
4
+SCC is supposed to be a light weight productivity library for SystemC and TLM 2.0 based modeling tasks using C++11.
5 5
 * scv4tlm - Tracing TLM2 Sockets
6 6
 
7 7
   TLM2.0 compliant sockets which can be configured to trace transactions passing thru them using the SCV transaction recording facilities. The project is set-up to be used with Eclipse CDT and its build system

+ 1
- 1
incl/scv4tlm/tlm_gp_data_ext.h View File

@@ -18,7 +18,7 @@
18 18
 #define TLM_GP_DATA_EXT_H_
19 19
 
20 20
 #include "tlm_gp_data.h"
21
-#include "scv.h"
21
+#include <scv.h>
22 22
 
23 23
 template<>
24 24
 class scv_extensions<tlm::tlm_command> : public scv_enum_base<tlm::tlm_command> {

+ 1
- 0
incl/sr_report

@@ -0,0 +1 @@
1
+Subproject commit fe45ef8a9b85dd4145834ea353c890d3406feda4

+ 1
- 0
incl/sr_signal

@@ -0,0 +1 @@
1
+Subproject commit 0c893066815c1397c73e95abbc86e2b9952b32ad

+ 15
- 0
incl/sysc/core/sc_logic_7.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * sc_logic_7.h
3 18
  *

incl/scv4tlm/initiator_mixin.h → incl/sysc/initiator_mixin.h View File

@@ -1,11 +1,28 @@
1
-#ifndef __INITIATOR_MIXIN_H__
2
-#define __INITIATOR_MIXIN_H__
3
-
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+#ifndef _SYSC_INITIATOR_MIXIN_H__
18
+#define _SYSC_INITIATOR_MIXIN_H__
19
+
20
+#include "utilities.h"
4 21
 #include <tlm>
5 22
 #include <functional>
6 23
 #include <sstream>
7 24
 
8
-namespace scv4tlm {
25
+namespace sysc {
9 26
 
10 27
 template<typename BASE_TYPE, typename TYPES = tlm::tlm_base_protocol_types>
11 28
 class initiator_mixin: public BASE_TYPE {
@@ -91,4 +108,4 @@ private:
91 108
 
92 109
 }
93 110
 
94
-#endif
111
+#endif //_SYSC_INITIATOR_MIXIN_H__

+ 0
- 38
incl/sysc/logging.h View File

@@ -1,38 +0,0 @@
1
-/*
2
- * logging.h
3
- *
4
- *  Created on: Nov 24, 2016
5
- *      Author: developer
6
- */
7
-
8
-#ifndef INCL_SYSC_LOGGING_H_
9
-#define INCL_SYSC_LOGGING_H_
10
-
11
-#include <util/logging.h>
12
-#include <systemc>
13
-
14
-namespace logging {
15
-template <typename T>
16
-class ScLog: public Log<T>{
17
-public:
18
-    ScLog(){};
19
-    std::ostringstream& Get(LogLevel level = info){
20
-        this->os << "- " << NowTime();
21
-        this->os << " " << Log<T>::ToString(level) << " - ["<<sc_core::sc_time_stamp()<<"] ";
22
-        Log<T>::getLastLogLevel()=level;
23
-        return this->os;
24
-    };
25
-};
26
-
27
-class FILELOG_DECLSPEC ScLogger : public ScLog<Output2FILE> {};
28
-
29
-#undef LOG
30
-#define LOG(level) \
31
-    if (level > FILELOG_MAX_LEVEL) ;\
32
-    else if (level > logging::Logger::ReportingLevel() || !logging::Output2FILE::Stream()) ; \
33
-    else logging::ScLogger().Get(level)
34
-
35
-
36
-}
37
-
38
-#endif /* INCL_SYSC_LOGGING_H_ */

+ 19
- 4
incl/sysc/memory.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * memory.h
3 18
  *
@@ -5,14 +20,14 @@
5 20
  *      Author: eyck
6 21
  */
7 22
 
8
-#ifndef SYSC_AVR_MEMORY_H_
9
-#define SYSC_AVR_MEMORY_H_
23
+#ifndef _SYSC_MEMORY_H_
24
+#define _SYSC_MEMORY_H_
10 25
 
11 26
 // Needed for the simple_target_socket
12 27
 #define SC_INCLUDE_DYNAMIC_PROCESSES
13 28
 
14 29
 #include "utilities.h"
15
-#include "logging.h"
30
+#include <util/logging.h>
16 31
 #include <tlm.h>
17 32
 #include <tlm_utils/simple_target_socket.h>
18 33
 
@@ -95,4 +110,4 @@ int memory<SIZE,BUSWIDTH,LOG_ACCESS>::handle_operation(tlm::tlm_generic_payload&
95 110
 
96 111
 }  // namespace sysc
97 112
 
98
-#endif /* SYSC_AVR_MEMORY_H_ */
113
+#endif /* _SYSC_MEMORY_H_ */

+ 19
- 6
incl/sysc/register.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * register.h
3 18
  *
@@ -5,14 +20,12 @@
5 20
  *      Author: developer
6 21
  */
7 22
 
8
-#ifndef SYSC_REGISTER_H_
9
-#define SYSC_REGISTER_H_
10
-
11
-#include <systemc>
23
+#ifndef _SYSC_REGISTER_H_
24
+#define _SYSC_REGISTER_H_
12 25
 
26
+#include "utilities.h"
13 27
 #include "resetable.h"
14 28
 #include "resource_access_if.h"
15
-#include "traceable.h"
16 29
 
17 30
 #include <functional>
18 31
 #include <limits>
@@ -143,4 +156,4 @@ struct sc_register_masked: public sc_register<DATATYPE> {
143 156
 };
144 157
 }
145 158
 
146
-#endif /* SYSC_REGISTER_H_ */
159
+#endif /* _SYSC_REGISTER_H_ */

+ 69
- 0
incl/sysc/report.h View File

@@ -0,0 +1,69 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+/*
17
+ * logging.h
18
+ *
19
+ *  Created on: Nov 24, 2016
20
+ *      Author: developer
21
+ */
22
+
23
+#ifndef _SYSC_REPORT_H_
24
+#define _SYSC_REPORT_H_
25
+
26
+#include <util/logging.h>
27
+#include <sysc/utilities.h>
28
+#include <sysc/utils/sc_report.h>
29
+#include <sstream>
30
+#include <iomanip>
31
+
32
+
33
+namespace sysc {
34
+
35
+void init_logging();
36
+
37
+template <typename T>
38
+class Log: public logging::Log<T>{
39
+public:
40
+    Log(){};
41
+
42
+    std::ostringstream& get(logging::log_level level = logging::info){
43
+        this->os << /*"- " <<*/ logging::now_time();
44
+        this->os << " " << logging::Log<T>::to_string(level) << " - ["<<std::setw(16)<<sc_core::sc_time_stamp()<<"] ";
45
+        logging::Log<T>::get_last_log_level()=level;
46
+        return this->os;
47
+    };
48
+
49
+};
50
+
51
+class FILELOG_DECLSPEC Logger : public Log<logging::Output2FILE> {
52
+    static std::once_flag once;
53
+public:
54
+    static logging::log_level& reporting_level(){
55
+        std::call_once(once, [](){ init_logging();});
56
+        return logging::Log<logging::Output2FILE>::reporting_level();
57
+    }
58
+};
59
+
60
+}
61
+
62
+#undef LOG
63
+#define LOG(level) \
64
+        if (level > FILELOG_MAX_LEVEL) ;\
65
+        else if (level > logging::Logger::reporting_level() || !logging::Output2FILE::stream()) ; \
66
+        else sysc::Logger().get(level)
67
+
68
+
69
+#endif /* _SYSC_REPORT_H_ */

+ 19
- 4
incl/sysc/resetable.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * resettable.h
3 18
  *
@@ -5,11 +20,11 @@
5 20
  *      Author: developer
6 21
  */
7 22
 
8
-#ifndef SYSC_RESETTABLE_H_
9
-#define SYSC_RESETTABLE_H_
23
+#ifndef _SYSC_RESETTABLE_H_
24
+#define _SYSC_RESETTABLE_H_
10 25
 
11
-#include <vector>
12 26
 #include "resource_access_if.h"
27
+#include <vector>
13 28
 
14 29
 namespace sysc {
15 30
 
@@ -36,4 +51,4 @@ protected:
36 51
 
37 52
 } /* namespace sysc */
38 53
 
39
-#endif /* SYSC_RESETTABLE_H_ */
54
+#endif /* _SYSC_RESETTABLE_H_ */

+ 18
- 3
incl/sysc/resource_access_if.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * resource_access_if.h
3 18
  *
@@ -5,8 +20,8 @@
5 20
  *      Author: developer
6 21
  */
7 22
 
8
-#ifndef SYSC_RESOURCE_ACCESS_IF_H_
9
-#define SYSC_RESOURCE_ACCESS_IF_H_
23
+#ifndef _SYSC_RESOURCE_ACCESS_IF_H_
24
+#define _SYSC_RESOURCE_ACCESS_IF_H_
10 25
 
11 26
 #include <cstddef>
12 27
 #include <cstdint>
@@ -27,4 +42,4 @@ struct resource_access_if {
27 42
 
28 43
 }
29 44
 
30
-#endif /* SYSC_RESOURCE_ACCESS_IF_H_ */
45
+#endif /* _SYSC_RESOURCE_ACCESS_IF_H_ */

+ 23
- 8
incl/sysc/router.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * router.h
3 18
  *
@@ -5,19 +20,19 @@
5 20
  *      Author: eyck
6 21
  */
7 22
 
8
-#ifndef SYSC_AVR_ROUTER_H_
9
-#define SYSC_AVR_ROUTER_H_
23
+#ifndef _SYSC_ROUTER_H_
24
+#define _SYSC_ROUTER_H_
10 25
 
11
-#include "util/range_lut.h"
26
+#include <util/range_lut.h>
12 27
 #include "utilities.h"
13 28
 // pragmas to disable the deprecated warnings for SystemC headers
14 29
 #pragma GCC diagnostic push
15 30
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
16
-#include "tlm.h"
31
+#include <tlm.h>
17 32
 #include <scv4tlm/tlm_rec_initiator_socket.h>
18 33
 #include <scv4tlm/tlm_rec_target_socket.h>
19
-#include <scv4tlm/initiator_mixin.h>
20
-#include <scv4tlm/target_mixin.h>
34
+#include <sysc/initiator_mixin.h>
35
+#include <sysc/target_mixin.h>
21 36
 #include <sysc/utils/sc_vector.h>
22 37
 #pragma GCC diagnostic pop
23 38
 #include <limits>
@@ -26,8 +41,8 @@ namespace sysc {
26 41
 
27 42
 template<unsigned BUSWIDTH = 32>
28 43
 struct router: sc_core::sc_module {
29
-    using intor_sckt  = scv4tlm::initiator_mixin<scv4tlm::tlm_rec_initiator_socket<BUSWIDTH>>;
30
-    using target_sckt = scv4tlm::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>>;
44
+    using intor_sckt  = sysc::initiator_mixin<scv4tlm::tlm_rec_initiator_socket<BUSWIDTH>>;
45
+    using target_sckt = sysc::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>>;
31 46
 
32 47
     sc_core::sc_vector<target_sckt> target;
33 48
     sc_core::sc_vector<intor_sckt>  initiator;

incl/scv4tlm/target_mixin.h → incl/sysc/target_mixin.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 #ifndef __TARGET_MIXIN_H__
2 17
 #define __TARGET_MIXIN_H__
3 18
 
@@ -5,12 +20,11 @@
5 20
 #  define SC_INCLUDE_DYNAMIC_PROCESSES
6 21
 #endif
7 22
 
8
-#include <systemc>
9
-#include <tlm>
10
-#include "tlm_utils/peq_with_get.h"
23
+#include <sysc/utilities.h>
24
+#include <tlm_utils/peq_with_get.h>
11 25
 #include <sstream>
12 26
 
13
-namespace scv4tlm {
27
+namespace sysc {
14 28
 
15 29
 template<typename base_type, typename TYPES = tlm::tlm_base_protocol_types>
16 30
 class target_mixin: public base_type {

incl/sysc/tlmtarget.h → incl/sysc/tlm_target.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * tlmtarget.h
3 18
  *
@@ -5,13 +20,13 @@
5 20
  *      Author: developer
6 21
  */
7 22
 
8
-#ifndef SYSC_TLMTARGET_H_
9
-#define SYSC_TLMTARGET_H_
23
+#ifndef _SYSC_TLM_TARGET_H_
24
+#define _SYSC_TLM_TARGET_H_
10 25
 
11 26
 #include <util/range_lut.h>
12 27
 #include "resource_access_if.h"
13 28
 #include <scv4tlm/tlm_rec_target_socket.h>
14
-#include <scv4tlm/target_mixin.h>
29
+#include <sysc/target_mixin.h>
15 30
 #include <array>
16 31
 
17 32
 namespace sysc {
@@ -28,12 +43,16 @@ struct tlm_target {
28 43
 
29 44
     tlm_target(sc_core::sc_time& clock);
30 45
 
31
-    scv4tlm::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>> socket;
46
+    sysc::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>> socket;
32 47
 
33 48
     void b_tranport_cb(tlm::tlm_generic_payload&, sc_core::sc_time&);
34 49
 
35 50
     unsigned int tranport_dbg_cb(tlm::tlm_generic_payload&);
36 51
 
52
+    void addResource(resource_access_if& i, uint64_t base_addr, uint64_t size){
53
+        socket_map.addEntry(&i, base_addr, size);
54
+    }
55
+
37 56
 protected:
38 57
     sc_core::sc_time& clk;
39 58
     util::range_lut<resource_access_if*> socket_map;
@@ -86,7 +105,7 @@ inline sysc::tlm_target<BUSWIDTH>::tlm_target(sc_core::sc_time& clock)
86 105
 
87 106
 template<unsigned int BUSWIDTH>
88 107
 void sysc::tlm_target<BUSWIDTH>::b_tranport_cb(tlm::tlm_generic_payload& gp, sc_core::sc_time& delay) {
89
-    resource_access_if* ra = socket_map.getEntry(gp.get_address());
108
+    auto* ra = socket_map.getEntry(gp.get_address());
90 109
     if(ra){
91 110
         if(gp.get_data_length()==ra->size() && gp.get_byte_enable_ptr()==0 && gp.get_data_length()==gp.get_streaming_width()){
92 111
             if(gp.get_command()== tlm::TLM_READ_COMMAND){
@@ -107,7 +126,7 @@ void sysc::tlm_target<BUSWIDTH>::b_tranport_cb(tlm::tlm_generic_payload& gp, sc_
107 126
 
108 127
 template<unsigned int BUSWIDTH>
109 128
 unsigned int sysc::tlm_target<BUSWIDTH>::tranport_dbg_cb(tlm::tlm_generic_payload& gp) {
110
-    resource_access_if* ra = socket_map.getEntry(gp.get_address());
129
+    auto* ra = socket_map.getEntry(gp.get_address());
111 130
     if(ra){
112 131
         if(gp.get_data_length()==ra->size() && gp.get_byte_enable_ptr()==0 && gp.get_data_length()==gp.get_streaming_width()){
113 132
             if(gp.get_command()== tlm::TLM_READ_COMMAND){
@@ -122,4 +141,4 @@ unsigned int sysc::tlm_target<BUSWIDTH>::tranport_dbg_cb(tlm::tlm_generic_payloa
122 141
     return 0;
123 142
 }
124 143
 
125
-#endif /* SYSC_TLMTARGET_H_ */
144
+#endif /* _SYSC_TLM_TARGET_H_ */

+ 18
- 3
incl/sysc/traceable.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * tracable.h
3 18
  *
@@ -5,8 +20,8 @@
5 20
  *      Author: developer
6 21
  */
7 22
 
8
-#ifndef SYSC_TRACABLE_H_
9
-#define SYSC_TRACABLE_H_
23
+#ifndef _SYSC_TRACABLE_H_
24
+#define _SYSC_TRACABLE_H_
10 25
 
11 26
 namespace sc_core {
12 27
     class sc_trace_file;
@@ -22,4 +37,4 @@ public:
22 37
 
23 38
 } /* namespace sysc */
24 39
 
25
-#endif /* SYSC_TRACABLE_H_ */
40
+#endif /* _SYSC_TRACABLE_H_ */

+ 19
- 4
incl/sysc/tracer.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * tracer.h
3 18
  *
@@ -5,13 +20,13 @@
5 20
  *      Author: developer
6 21
  */
7 22
 
8
-#ifndef SYSC_TRACER_H_
9
-#define SYSC_TRACER_H_
23
+#ifndef _SYSC_TRACER_H_
24
+#define _SYSC_TRACER_H_
10 25
 
26
+#include "utilities.h"
11 27
 #ifdef WITH_SCV
12 28
 #include <scv.h>
13 29
 #endif
14
-#include <systemc>
15 30
 #include <vector>
16 31
 #include <string>
17 32
 
@@ -40,4 +55,4 @@ protected:
40 55
 
41 56
 } /* namespace sysc */
42 57
 
43
-#endif /* SYSC_TRACER_H_ */
58
+#endif /* _SYSC_TRACER_H_ */

+ 19
- 11
incl/sysc/utilities.h View File

@@ -1,3 +1,18 @@
1
+/*******************************************************************************
2
+ * Copyright 2016 MINRES Technologies GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1 16
 /*
2 17
  * utilities.h
3 18
  *
@@ -5,8 +20,8 @@
5 20
  *      Author: eyck
6 21
  */
7 22
 
8
-#ifndef SYSC_UTILITIES_H_
9
-#define SYSC_UTILITIES_H_
23
+#ifndef _SYSC_UTILITIES_H_
24
+#define _SYSC_UTILITIES_H_
10 25
 
11 26
 #include "traceable.h"
12 27
 
@@ -17,14 +32,7 @@
17 32
 #pragma GCC diagnostic pop
18 33
 
19 34
 #define NAMED(X,...) X(#X,##__VA_ARGS__)
20
-#define MOD(X) X(#X)
21
-#define MOD_A(X,...) X(#X,__VA_ARGS__)
22
-#define ATTR(X) X(#X)
23
-#define SCPIN(X) X(#X)
24
-#define SCPIN_A(X,...) X(#X,__VA_ARGS__)
25
-#define SIG(X) X(#X)
26
-#define SIG_A(X,...) X(#X,__VA_ARGS__)
27
-#define SOCKET(X) X(#X)
35
+#define NAMEDD(T,X,...) X(new T(#X,##__VA_ARGS__))
28 36
 
29 37
 #define TRACE_VAR(F, X)    sc_core::sc_trace(F, X, std::string(this->name())+"." #X)
30 38
 #define TRACE_ARR(F, X, I) sc_core::sc_trace(F, X[I], (std::string(this->name())+"." #X "("+std::to_string(I)+")").c_str());
@@ -51,4 +59,4 @@ inline sc_core::sc_time operator"" _ps  ( unsigned long long val ){return sc_cor
51 59
 inline sc_core::sc_time operator"" _fs  ( long double val )       {return sc_core::sc_time(val, sc_core::SC_FS);}
52 60
 inline sc_core::sc_time operator"" _fs  ( unsigned long long val ){return sc_core::sc_time(double(val), sc_core::SC_FS);}
53 61
 
54
-#endif /* SYSC_UTILITIES_H_ */
62
+#endif /* _SYSC_UTILITIES_H_ */

+ 204
- 0
incl/util/logging.h View File

@@ -0,0 +1,204 @@
1
+/*******************************************************************************
2
+ * Copyright (C) 2017, MINRES Technologies GmbH
3
+ * All rights reserved.
4
+ * 
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ * 
8
+ * 1. Redistributions of source code must retain the above copyright notice,
9
+ *    this list of conditions and the following disclaimer.
10
+ * 
11
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ *    this list of conditions and the following disclaimer in the documentation
13
+ *    and/or other materials provided with the distribution.
14
+ * 
15
+ * 3. Neither the name of the copyright holder nor the names of its contributors
16
+ *    may be used to endorse or promote products derived from this software
17
+ *    without specific prior written permission.
18
+ * 
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ * POSSIBILITY OF SUCH DAMAGE.
30
+ * 
31
+ * Contributors:
32
+ *       eyck@minres.com - initial API and implementation
33
+ ******************************************************************************/
34
+
35
+#ifndef _UTIL_LOGGING_H_
36
+#define _UTIL_LOGGING_H_
37
+
38
+#include <sstream>
39
+#include <string>
40
+#include <vector>
41
+#include <iterator>
42
+#include <cstring>
43
+#include <mutex>
44
+#include <stdio.h>
45
+#include <sys/time.h>
46
+
47
+#define LEVELS(FOO) FOO(none) FOO(fatal) FOO(error) FOO(warning) FOO(info) FOO(debug) FOO(trace)
48
+#define DO_DESCRIPTION(e)  #e,
49
+#define DO_ENUM(e)  e,
50
+
51
+namespace logging {
52
+
53
+static const char * const buffer[] = { LEVELS(DO_DESCRIPTION)};
54
+enum log_level { LEVELS(DO_ENUM) };
55
+
56
+inline std::string now_time();
57
+
58
+template <typename T>
59
+class Log{
60
+public:
61
+	Log(){};
62
+    virtual ~Log(){
63
+		os << std::endl;
64
+		T::output(os.str());
65
+		//TODO: use a more specific exception
66
+		if(get_last_log_level() == fatal) throw std::exception();
67
+	};
68
+    std::ostringstream& get(log_level level = info){
69
+		os << "- " << now_time();
70
+		os << " " << to_string(level) << ": ";
71
+		get_last_log_level()=level;
72
+		return os;
73
+	};
74
+public:
75
+    static log_level& reporting_level(){
76
+		static log_level reportingLevel = warning;
77
+		return reportingLevel;
78
+	}
79
+    static std::string to_string(log_level level){
80
+		return std::string(get_log_level_cstr()[level]);
81
+	};
82
+    static log_level from_string(const std::string& level) {
83
+		for(unsigned int i=none; i<=trace; i++)
84
+			if(!strncasecmp(level.c_str(), (const char*)(get_log_level_cstr()+i), strlen((const char*)get_log_level_cstr()+i))) return i;
85
+		Log<T>().Get(warning) << "Unknown logging level '" << level << "'. Using INFO level as default.";
86
+		return info;
87
+	}
88
+
89
+protected:
90
+    log_level& get_last_log_level(){
91
+		static log_level level = trace;
92
+		return level;
93
+	}
94
+	static const char* const * get_log_level_cstr(){
95
+		return buffer;
96
+	};
97
+    std::ostringstream os;
98
+private:
99
+    Log(const Log&);
100
+    Log& operator =(const Log&);
101
+};
102
+
103
+struct Output2FILE {
104
+    static FILE*& stream(){
105
+		static FILE* pStream = stderr;
106
+		return pStream;
107
+	}
108
+    static void output(const std::string& msg){
109
+        static std::mutex mtx;
110
+        std::lock_guard<std::mutex> lock(mtx);
111
+		FILE* pStream = stream();
112
+		if (!pStream) return;
113
+		fprintf(pStream, "%s", msg.c_str());
114
+		fflush(pStream);
115
+	}
116
+};
117
+
118
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
119
+#   if defined (BUILDING_FILELOG_DLL)
120
+#       define FILELOG_DECLSPEC   __declspec (dllexport)
121
+#   elif defined (USING_FILELOG_DLL)
122
+#       define FILELOG_DECLSPEC   __declspec (dllimport)
123
+#   else
124
+#       define FILELOG_DECLSPEC
125
+#   endif // BUILDING_DBSIMPLE_DLL
126
+#else
127
+#   define FILELOG_DECLSPEC
128
+#endif // _WIN32
129
+
130
+class FILELOG_DECLSPEC Logger : public Log<Output2FILE> {};
131
+//typedef Log<Output2FILE> Logger;
132
+
133
+#ifndef FILELOG_MAX_LEVEL
134
+#define FILELOG_MAX_LEVEL logging::trace
135
+#endif
136
+
137
+#define LOG(level) \
138
+    if (level > FILELOG_MAX_LEVEL) ;\
139
+    else if (level > logging::Logger::reporting_level() || !logging::Output2FILE::stream()) ; \
140
+    else logging::Logger().get(level)
141
+
142
+#if defined(WIN32)
143
+
144
+#include <windows.h>
145
+
146
+inline std::string now_time(){
147
+    const int MAX_LEN = 200;
148
+    char buffer[MAX_LEN];
149
+    if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, "HH':'mm':'ss", buffer, MAX_LEN) == 0)
150
+        return "Error in now_time()";
151
+    char result[100] = {0};
152
+    static DWORD first = GetTickCount();
153
+    std::sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
154
+    return result;
155
+}
156
+
157
+#else
158
+
159
+inline std::string now_time(){
160
+    char buffer[11];
161
+    time_t t;
162
+    time(&t);
163
+    tm r = {0};
164
+    strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r));
165
+    struct timeval tv;
166
+    gettimeofday(&tv, 0);
167
+    char result[100] = {0};
168
+    sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000);
169
+    return result;
170
+}
171
+
172
+#endif //WIN32
173
+// a print function for a vector
174
+template<typename  T>
175
+std::ostream& operator<< (std::ostream& stream, const std::vector<T>& vector)  {
176
+	copy(vector.begin(), vector.end(), std::ostream_iterator<T>(stream, ","));
177
+	return stream;
178
+}
179
+
180
+} // namespace
181
+#undef LEVELS
182
+#undef CAT
183
+
184
+#ifndef NDEBUG
185
+#   define ASSERT(condition, message) \
186
+    do { \
187
+        if (! (condition)) { \
188
+        	logging::Logger().Get(logging::fatal) << "Assertion `" #condition "` failed in " << __FILE__ << " line " << __LINE__ << ": " << message << std::endl; \
189
+            std::terminate(); \
190
+        } \
191
+    } while (false)
192
+#else
193
+#   define ASSERT(condition, message) do { } while (false)
194
+#endif
195
+
196
+#define CHECK(condition, message) \
197
+do { \
198
+	if (! (condition)) { \
199
+		logging::Logger().Get(logging::fatal) << "Check of `" #condition "` failed in " << __FILE__ << " line " << __LINE__ << ": " << message << std::endl; \
200
+		std::terminate(); \
201
+	} \
202
+} while (false)
203
+
204
+#endif /* _UTIL_LOGGING_H_ */

+ 1
- 0
incl/util/range_lut.h View File

@@ -38,6 +38,7 @@
38 38
 #include <map>
39 39
 #include <stdexcept>
40 40
 #include <string>
41
+#include <sstream>
41 42
 #include <iostream>
42 43
 #include <iomanip>
43 44
 #include <exception>

+ 3
- 1
src/CMakeLists.txt View File

@@ -4,6 +4,8 @@ set(LIB_SOURCES
4 4
     sc_logic_7.cpp
5 5
     tracer.cpp
6 6
     utilities.cpp
7
+    report.cpp
8
+    ${PROJECT_SOURCE_DIR}/incl/sr_report/sr_report.cpp
7 9
 )
8 10
 
9 11
 if(SCV_FOUND)   
@@ -18,6 +20,6 @@ set(LIBRARY_NAME sc-components)
18 20
 
19 21
 # Define the library
20 22
 add_library(${LIBRARY_NAME} ${LIB_SOURCES})
21
-# Make sure the compiler can find include files for our Hello library
23
+# Make sure the compiler can find include files for our library
22 24
 # when other libraries or executables link to Hello
23 25
 target_include_directories (sc-components PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../incl)

+ 72
- 0
src/report.cpp View File

@@ -0,0 +1,72 @@
1
+/*
2
+ * report.cpp
3
+ *
4
+ *  Created on: 19.09.2017
5
+ *      Author: ubuntu
6
+ */
7
+
8
+#include <sysc/report.h>
9
+#include <sr_report/sr_report.h>
10
+
11
+using namespace sc_core;
12
+
13
+static const std::string compose_message(const sc_report& rep){
14
+    std::stringstream os;
15
+    sr_report *srr = dynamic_cast<sr_report *>(const_cast<sc_report *>(&rep));
16
+    if(srr) {
17
+        for(std::vector<v::pair>::const_iterator iter = srr->pairs.begin(); iter!=srr->pairs.end(); iter++) {
18
+            os << '['<<iter->name << ':';
19
+            switch(iter->type) {
20
+            case v::pair::INT32:  os << std::hex << std::setfill('0') << "0x" << std::setw(8) << boost::any_cast<int32_t>(iter->data); break;
21
+            case v::pair::UINT32: os << std::hex << std::setfill('0') << "0x" << std::setw(8) << boost::any_cast<uint32_t>(iter->data); break;
22
+            case v::pair::INT64:  os << std::hex << std::setfill('0') << "0x" << std::setw(16) << boost::any_cast<int64_t>(iter->data); break;
23
+            case v::pair::UINT64: os << std::hex << std::setfill('0') << "0x" << std::setw(16) << boost::any_cast<uint64_t>(iter->data); break;
24
+            case v::pair::STRING: os << boost::any_cast<std::string>(iter->data).c_str(); break;
25
+            case v::pair::BOOL:   os << (boost::any_cast<bool>(iter->data)? "true" : "false"); break;
26
+            case v::pair::DOUBLE: os << boost::any_cast<double>(iter->data); break;
27
+            case v::pair::TIME:   os << boost::any_cast<sc_core::sc_time>(iter->data).to_string(); break;
28
+            default:              os << boost::any_cast<int32_t>(iter->data);
29
+            }
30
+            os << ']';
31
+        }
32
+        os<<' ';
33
+    }
34
+    if ( rep.get_id() >= 0 )
35
+        os << "("<< "IWEF"[rep.get_severity()] << rep.get_id() << ") ";
36
+    os << rep.get_msg_type();
37
+    if( *rep.get_msg() )
38
+        os << ": " << rep.get_msg();
39
+    if( rep.get_severity() > SC_INFO ){
40
+        char line_number_str[16];
41
+        os <<  "(file: " << rep.get_file_name() << ":" << rep.get_line_number()<<")";
42
+        sc_simcontext* simc = sc_get_curr_simcontext();
43
+        if( simc && sc_is_running() ){
44
+            const char* proc_name = rep.get_process_name();
45
+            if( proc_name )
46
+                os <<   "(process: " << proc_name << " @ " << rep.get_time().to_string()<<")";
47
+        }
48
+    }
49
+    return os.str();
50
+}
51
+
52
+static void report_handler(const sc_report& rep, const sc_actions& actions){
53
+    const logging::log_level map[] = {logging::info, logging::warning, logging::error, logging::fatal};
54
+    if ( actions & SC_DISPLAY )
55
+        LOG(map[rep.get_severity()]) << compose_message(rep);
56
+    //    if ( (actions & SC_LOG) && log_file_name ) {
57
+    //        if ( !log_stream ) log_stream = new ::std::ofstream(log_file_name); // ios::trunc
58
+    //        *log_stream << rep.get_time() << ": " << my_report_compose_message(rep) << ::std::endl;
59
+    //    }
60
+    if ( actions & SC_STOP )
61
+        sc_stop();
62
+    if ( actions & SC_ABORT )
63
+        abort();
64
+    if ( actions & SC_THROW )
65
+        throw rep;
66
+}
67
+
68
+void sysc::init_logging(){
69
+    sc_report_handler::set_handler(report_handler);
70
+}
71
+
72
+std::once_flag sysc::Logger::once;

+ 1
- 0
src/tracer.cpp View File

@@ -65,6 +65,7 @@ tracer::~tracer() {
65 65
 
66 66
 void tracer::descend(const std::vector<sc_object*>& objects) {
67 67
 	for(auto obj: objects){
68
+	    const char* name = obj->name();
68 69
 		traceable* t = dynamic_cast<traceable*>(obj);
69 70
 		if(t) t->trace(trf);
70 71
 		const char* kind = obj->kind();