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
pull/6/head
Eyck Jentzsch 2 years ago
parent
commit
187fd9b4ce
24 changed files with 595 additions and 100 deletions
  1. +6
    -0
      .gitmodules
  2. +1
    -1
      README.md
  3. +1
    -1
      incl/scv4tlm/tlm_gp_data_ext.h
  4. +1
    -0
      incl/sr_report
  5. +1
    -0
      incl/sr_signal
  6. +15
    -0
      incl/sysc/core/sc_logic_7.h
  7. +22
    -5
      incl/sysc/initiator_mixin.h
  8. +0
    -38
      incl/sysc/logging.h
  9. +19
    -4
      incl/sysc/memory.h
  10. +19
    -6
      incl/sysc/register.h
  11. +69
    -0
      incl/sysc/report.h
  12. +19
    -4
      incl/sysc/resetable.h
  13. +18
    -3
      incl/sysc/resource_access_if.h
  14. +23
    -8
      incl/sysc/router.h
  15. +18
    -4
      incl/sysc/target_mixin.h
  16. +26
    -7
      incl/sysc/tlm_target.h
  17. +18
    -3
      incl/sysc/traceable.h
  18. +19
    -4
      incl/sysc/tracer.h
  19. +19
    -11
      incl/sysc/utilities.h
  20. +204
    -0
      incl/util/logging.h
  21. +1
    -0
      incl/util/range_lut.h
  22. +3
    -1
      src/CMakeLists.txt
  23. +72
    -0
      src/report.cpp
  24. +1
    -0
      src/tracer.cpp

+ 6
- 0
.gitmodules View File

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

+ 1
- 1
README.md View File

@ -1,7 +1,7 @@
SystemC-Components (SCC)
========================
SCC is supposed to be a light weight productivity llibrary for SystemC and TLM 2.0 based modelling tasks.
SCC is supposed to be a light weight productivity library for SystemC and TLM 2.0 based modeling tasks using C++11.
* scv4tlm - Tracing TLM2 Sockets
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 @@
#define TLM_GP_DATA_EXT_H_
#include "tlm_gp_data.h"
#include "scv.h";
#include <scv.h>;
template<>
class scv_extensions<tlm::tlm_command> : public scv_enum_base<tlm::tlm_command> {

+ 1
- 0
incl/sr_report

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

+ 1
- 0
incl/sr_signal

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

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

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

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

@ -1,11 +1,28 @@
#ifndef __INITIATOR_MIXIN_H__
#define __INITIATOR_MIXIN_H__
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#ifndef _SYSC_INITIATOR_MIXIN_H__
#define _SYSC_INITIATOR_MIXIN_H__
#include "utilities.h"
#include <tlm>
#include <functional>
#include <sstream>
namespace scv4tlm {
namespace sysc {
template<typename BASE_TYPE, typename TYPES = tlm::tlm_base_protocol_types>
class initiator_mixin: public BASE_TYPE {
@ -91,4 +108,4 @@ private:
}
#endif
#endif //_SYSC_INITIATOR_MIXIN_H__

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

@ -1,38 +0,0 @@
/*
* logging.h
*
* Created on: Nov 24, 2016
* Author: developer
*/
#ifndef INCL_SYSC_LOGGING_H_
#define INCL_SYSC_LOGGING_H_
#include <util/logging.h>
#include <systemc>
namespace logging {
template <typename T>
class ScLog: public Log<T>{
public:
ScLog(){};
std::ostringstream& Get(LogLevel level = info){
this->os << "- " << NowTime();
this->os << " " << Log<T>::ToString(level) << " - ["<<sc_core::sc_time_stamp()<<"] ";
Log<T>::getLastLogLevel()=level;
return this->os;
};
};
class FILELOG_DECLSPEC ScLogger : public ScLog<Output2FILE> {};
#undef LOG
#define LOG(level) \
if (level > FILELOG_MAX_LEVEL) ;\
else if (level > logging::Logger::ReportingLevel() || !logging::Output2FILE::Stream()) ; \
else logging::ScLogger().Get(level)
}
#endif /* INCL_SYSC_LOGGING_H_ */

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

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
* memory.h
*
@ -5,14 +20,14 @@
* Author: eyck
*/
#ifndef SYSC_AVR_MEMORY_H_
#define SYSC_AVR_MEMORY_H_
#ifndef _SYSC_MEMORY_H_
#define _SYSC_MEMORY_H_
// Needed for the simple_target_socket
#define SC_INCLUDE_DYNAMIC_PROCESSES
#include "utilities.h"
#include &#34;logging.h";
#include &lt;util/logging.h>;
#include <tlm.h>
#include <tlm_utils/simple_target_socket.h>
@ -95,4 +110,4 @@ int memory::handle_operation(tlm::tlm_generic_payload&
} // namespace sysc
#endif /* SYSC_AVR_MEMORY_H_ */
#endif /* _SYSC_MEMORY_H_ */

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

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

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

@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
* logging.h
*
* Created on: Nov 24, 2016
* Author: developer
*/
#ifndef _SYSC_REPORT_H_
#define _SYSC_REPORT_H_
#include <util/logging.h>
#include <sysc/utilities.h>
#include <sysc/utils/sc_report.h>
#include <sstream>
#include <iomanip>
namespace sysc {
void init_logging();
template <typename T>
class Log: public logging::Log<T>{
public:
Log(){};
std::ostringstream& get(logging::log_level level = logging::info){
this->os << /*"- " <<*/ logging::now_time();
this->os << " " << logging::Log<T>::to_string(level) << " - ["<<std::setw(16)<<sc_core::sc_time_stamp()<<"] ";
logging::Log<T>::get_last_log_level()=level;
return this->os;
};
};
class FILELOG_DECLSPEC Logger : public Log<logging::Output2FILE> {
static std::once_flag once;
public:
static logging::log_level& reporting_level(){
std::call_once(once, [](){ init_logging();});
return logging::Log<logging::Output2FILE>::reporting_level();
}
};
}
#undef LOG
#define LOG(level) \
if (level > FILELOG_MAX_LEVEL) ;\
else if (level > logging::Logger::reporting_level() || !logging::Output2FILE::stream()) ; \
else sysc::Logger().get(level)
#endif /* _SYSC_REPORT_H_ */

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

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
* resettable.h
*
@ -5,11 +20,11 @@
* Author: developer
*/
#ifndef SYSC_RESETTABLE_H_
#define SYSC_RESETTABLE_H_
#ifndef _SYSC_RESETTABLE_H_
#define _SYSC_RESETTABLE_H_
#include <vector>
#include "resource_access_if.h"
#include <vector>
namespace sysc {
@ -36,4 +51,4 @@ protected:
} /* namespace sysc */
#endif /* SYSC_RESETTABLE_H_ */
#endif /* _SYSC_RESETTABLE_H_ */

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

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

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

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
* router.h
*
@ -5,19 +20,19 @@
* Author: eyck
*/
#ifndef SYSC_AVR_ROUTER_H_
#define SYSC_AVR_ROUTER_H_
#ifndef _SYSC_ROUTER_H_
#define _SYSC_ROUTER_H_
#include &#34;util/range_lut.h";
#include &lt;util/range_lut.h>;
#include "utilities.h"
// pragmas to disable the deprecated warnings for SystemC headers
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include &#34;tlm.h";
#include &lt;tlm.h>;
#include <scv4tlm/tlm_rec_initiator_socket.h>
#include <scv4tlm/tlm_rec_target_socket.h>
#include <scv4tlm/initiator_mixin.h>
#include <scv4tlm/target_mixin.h>
#include <sysc/initiator_mixin.h>
#include <sysc/target_mixin.h>
#include <sysc/utils/sc_vector.h>
#pragma GCC diagnostic pop
#include <limits>
@ -26,8 +41,8 @@ namespace sysc {
template<unsigned BUSWIDTH = 32>
struct router: sc_core::sc_module {
using intor_sckt = scv4tlm::initiator_mixin<scv4tlm::tlm_rec_initiator_socket<BUSWIDTH>>;
using target_sckt = scv4tlm::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>>;
using intor_sckt = sysc::initiator_mixin<scv4tlm::tlm_rec_initiator_socket<BUSWIDTH>>;
using target_sckt = sysc::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>>;
sc_core::sc_vector<target_sckt> target;
sc_core::sc_vector<intor_sckt> initiator;

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

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

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

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
* tlmtarget.h
*
@ -5,13 +20,13 @@
* Author: developer
*/
#ifndef SYSC_TLMTARGET_H_
#define SYSC_TLMTARGET_H_
#ifndef _SYSC_TLM_TARGET_H_
#define _SYSC_TLM_TARGET_H_
#include <util/range_lut.h>
#include "resource_access_if.h"
#include <scv4tlm/tlm_rec_target_socket.h>
#include <scv4tlm/target_mixin.h>
#include <sysc/target_mixin.h>
#include <array>
namespace sysc {
@ -28,12 +43,16 @@ struct tlm_target {
tlm_target(sc_core::sc_time& clock);
scv4tlm::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>> socket;
sysc::target_mixin<scv4tlm::tlm_rec_target_socket<BUSWIDTH>> socket;
void b_tranport_cb(tlm::tlm_generic_payload&, sc_core::sc_time&);
unsigned int tranport_dbg_cb(tlm::tlm_generic_payload&);
void addResource(resource_access_if& i, uint64_t base_addr, uint64_t size){
socket_map.addEntry(&i, base_addr, size);
}
protected:
sc_core::sc_time& clk;
util::range_lut<resource_access_if*> socket_map;
@ -86,7 +105,7 @@ inline sysc::tlm_target::tlm_target(sc_core::sc_time& clock)
template<unsigned int BUSWIDTH>
void sysc::tlm_target<BUSWIDTH>::b_tranport_cb(tlm::tlm_generic_payload& gp, sc_core::sc_time& delay) {
resource_access_if* ra = socket_map.getEntry(gp.get_address());
auto* ra = socket_map.getEntry(gp.get_address());
if(ra){
if(gp.get_data_length()==ra->size() && gp.get_byte_enable_ptr()==0 && gp.get_data_length()==gp.get_streaming_width()){
if(gp.get_command()== tlm::TLM_READ_COMMAND){
@ -107,7 +126,7 @@ void sysc::tlm_target::b_tranport_cb(tlm::tlm_generic_payload& gp, sc_
template<unsigned int BUSWIDTH>
unsigned int sysc::tlm_target<BUSWIDTH>::tranport_dbg_cb(tlm::tlm_generic_payload& gp) {
resource_access_if* ra = socket_map.getEntry(gp.get_address());
auto* ra = socket_map.getEntry(gp.get_address());
if(ra){
if(gp.get_data_length()==ra->size() && gp.get_byte_enable_ptr()==0 && gp.get_data_length()==gp.get_streaming_width()){
if(gp.get_command()== tlm::TLM_READ_COMMAND){
@ -122,4 +141,4 @@ unsigned int sysc::tlm_target::tranport_dbg_cb(tlm::tlm_generic_payloa
return 0;
}
#endif /* SYSC_TLMTARGET_H_ */
#endif /* _SYSC_TLM_TARGET_H_ */

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

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

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

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
* tracer.h
*
@ -5,13 +20,13 @@
* Author: developer
*/
#ifndef SYSC_TRACER_H_
#define SYSC_TRACER_H_
#ifndef _SYSC_TRACER_H_
#define _SYSC_TRACER_H_
#include "utilities.h"
#ifdef WITH_SCV
#include <scv.h>
#endif
#include <systemc>
#include <vector>
#include <string>
@ -40,4 +55,4 @@ protected:
} /* namespace sysc */
#endif /* SYSC_TRACER_H_ */
#endif /* _SYSC_TRACER_H_ */

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

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2016 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
* utilities.h
*
@ -5,8 +20,8 @@
* Author: eyck
*/
#ifndef SYSC_UTILITIES_H_
#define SYSC_UTILITIES_H_
#ifndef _SYSC_UTILITIES_H_
#define _SYSC_UTILITIES_H_
#include "traceable.h"
@ -17,14 +32,7 @@
#pragma GCC diagnostic pop
#define NAMED(X,...) X(#X,##__VA_ARGS__)
#define MOD(X) X(#X)
#define MOD_A(X,...) X(#X,__VA_ARGS__)
#define ATTR(X) X(#X)
#define SCPIN(X) X(#X)
#define SCPIN_A(X,...) X(#X,__VA_ARGS__)
#define SIG(X) X(#X)
#define SIG_A(X,...) X(#X,__VA_ARGS__)
#define SOCKET(X) X(#X)
#define NAMEDD(T,X,...) X(new T(#X,##__VA_ARGS__))
#define TRACE_VAR(F, X) sc_core::sc_trace(F, X, std::string(this->name())+"." #X)
#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
inline sc_core::sc_time operator"" _fs ( long double val ) {return sc_core::sc_time(val, sc_core::SC_FS);}
inline sc_core::sc_time operator"" _fs ( unsigned long long val ){return sc_core::sc_time(double(val), sc_core::SC_FS);}
#endif /* SYSC_UTILITIES_H_ */
#endif /* _SYSC_UTILITIES_H_ */

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

@ -0,0 +1,204 @@
/*******************************************************************************
* Copyright (C) 2017, MINRES Technologies GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* eyck@minres.com - initial API and implementation
******************************************************************************/
#ifndef _UTIL_LOGGING_H_
#define _UTIL_LOGGING_H_
#include <sstream>
#include <string>
#include <vector>
#include <iterator>
#include <cstring>
#include <mutex>
#include <stdio.h>
#include <sys/time.h>
#define LEVELS(FOO) FOO(none) FOO(fatal) FOO(error) FOO(warning) FOO(info) FOO(debug) FOO(trace)
#define DO_DESCRIPTION(e) #e,
#define DO_ENUM(e) e,
namespace logging {
static const char * const buffer[] = { LEVELS(DO_DESCRIPTION)};
enum log_level { LEVELS(DO_ENUM) };
inline std::string now_time();
template <typename T>
class Log{
public:
Log(){};
virtual ~Log(){
os << std::endl;
T::output(os.str());
//TODO: use a more specific exception
if(get_last_log_level() == fatal) throw std::exception();
};
std::ostringstream& get(log_level level = info){
os << "- " << now_time();
os << " " << to_string(level) << ": ";
get_last_log_level()=level;
return os;
};
public:
static log_level& reporting_level(){
static log_level reportingLevel = warning;
return reportingLevel;
}
static std::string to_string(log_level level){
return std::string(get_log_level_cstr()[level]);
};
static log_level from_string(const std::string& level) {
for(unsigned int i=none; i<=trace; i++)
if(!strncasecmp(level.c_str(), (const char*)(get_log_level_cstr()+i), strlen((const char*)get_log_level_cstr()+i))) return i;
Log<T>().Get(warning) << "Unknown logging level '" << level << "'. Using INFO level as default.";
return info;
}
protected:
log_level& get_last_log_level(){
static log_level level = trace;
return level;
}
static const char* const * get_log_level_cstr(){
return buffer;
};
std::ostringstream os;
private:
Log(const Log&);
Log& operator =(const Log&);
};
struct Output2FILE {
static FILE*& stream(){
static FILE* pStream = stderr;
return pStream;
}
static void output(const std::string& msg){
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
FILE* pStream = stream();
if (!pStream) return;
fprintf(pStream, "%s", msg.c_str());
fflush(pStream);
}
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined (BUILDING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllexport)
# elif defined (USING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllimport)
# else
# define FILELOG_DECLSPEC
# endif // BUILDING_DBSIMPLE_DLL
#else
# define FILELOG_DECLSPEC
#endif // _WIN32
class FILELOG_DECLSPEC Logger : public Log<Output2FILE> {};
//typedef Log<Output2FILE> Logger;
#ifndef FILELOG_MAX_LEVEL
#define FILELOG_MAX_LEVEL logging::trace
#endif
#define LOG(level) \
if (level > FILELOG_MAX_LEVEL) ;\
else if (level > logging::Logger::reporting_level() || !logging::Output2FILE::stream()) ; \
else logging::Logger().get(level)
#if defined(WIN32)
#include <windows.h>
inline std::string now_time(){
const int MAX_LEN = 200;
char buffer[MAX_LEN];
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, "HH':'mm':'ss", buffer, MAX_LEN) == 0)
return "Error in now_time()";
char result[100] = {0};
static DWORD first = GetTickCount();
std::sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
return result;
}
#else
inline std::string now_time(){
char buffer[11];
time_t t;
time(&t);
tm r = {0};
strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r));
struct timeval tv;
gettimeofday(&tv, 0);
char result[100] = {0};
sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000);
return result;
}
#endif //WIN32
// a print function for a vector
template<typename T>
std::ostream& operator<< (std::ostream& stream, const std::vector<T>& vector) {
copy(vector.begin(), vector.end(), std::ostream_iterator<T>(stream, ","));
return stream;
}
} // namespace
#undef LEVELS
#undef CAT
#ifndef NDEBUG
# define ASSERT(condition, message) \
do { \
if (! (condition)) { \
logging::Logger().Get(logging::fatal) << "Assertion `" #condition "` failed in " << __FILE__ << " line " << __LINE__ << ": " << message << std::endl; \
std::terminate(); \
} \
} while (false)
#else
# define ASSERT(condition, message) do { } while (false)
#endif
#define CHECK(condition, message) \
do { \
if (! (condition)) { \
logging::Logger().Get(logging::fatal) << "Check of `" #condition "` failed in " << __FILE__ << " line " << __LINE__ << ": " << message << std::endl; \
std::terminate(); \
} \
} while (false)
#endif /* _UTIL_LOGGING_H_ */

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

@ -38,6 +38,7 @@
#include <map>
#include <stdexcept>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <exception>

+ 3
- 1
src/CMakeLists.txt View File

@ -4,6 +4,8 @@ set(LIB_SOURCES
sc_logic_7.cpp
tracer.cpp
utilities.cpp
report.cpp
${PROJECT_SOURCE_DIR}/incl/sr_report/sr_report.cpp
)
if(SCV_FOUND)
@ -18,6 +20,6 @@ set(LIBRARY_NAME sc-components)
# Define the library
add_library(${LIBRARY_NAME} ${LIB_SOURCES})
# Make sure the compiler can find include files for our Hello library
# Make sure the compiler can find include files for our library
# when other libraries or executables link to Hello
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 @@
/*
* report.cpp
*
* Created on: 19.09.2017
* Author: ubuntu
*/
#include <sysc/report.h>
#include <sr_report/sr_report.h>
using namespace sc_core;
static const std::string compose_message(const sc_report& rep){
std::stringstream os;
sr_report *srr = dynamic_cast<sr_report *>(const_cast<sc_report *>(&rep));
if(srr) {
for(std::vector<v::pair>::const_iterator iter = srr->pairs.begin(); iter!=srr->pairs.end(); iter++) {
os << '['<<iter->name << ':';
switch(iter->type) {
case v::pair::INT32: os << std::hex << std::setfill('0') << "0x" << std::setw(8) << boost::any_cast<int32_t>(iter->data); break;
case v::pair::UINT32: os << std::hex << std::setfill('0') << "0x" << std::setw(8) << boost::any_cast<uint32_t>(iter->data); break;
case v::pair::INT64: os << std::hex << std::setfill('0') << "0x" << std::setw(16) << boost::any_cast<int64_t>(iter->data); break;
case v::pair::UINT64: os << std::hex << std::setfill('0') << "0x" << std::setw(16) << boost::any_cast<uint64_t>(iter->data); break;
case v::pair::STRING: os << boost::any_cast<std::string>(iter->data).c_str(); break;
case v::pair::BOOL: os << (boost::any_cast<bool>(iter->data)? "true" : "false"); break;
case v::pair::DOUBLE: os << boost::any_cast<double>(iter->data); break;
case v::pair::TIME: os << boost::any_cast<sc_core::sc_time>(iter->data).to_string(); break;
default: os << boost::any_cast<int32_t>(iter->data);
}
os << ']';
}
os<<' ';
}
if ( rep.get_id() >= 0 )
os << "("<< "IWEF"[rep.get_severity()] << rep.get_id() << ") ";
os << rep.get_msg_type();
if( *rep.get_msg() )
os << ": " << rep.get_msg();
if( rep.get_severity() > SC_INFO ){
char line_number_str[16];
os << "(file: " << rep.get_file_name() << ":" << rep.get_line_number()<<")";
sc_simcontext* simc = sc_get_curr_simcontext();
if( simc && sc_is_running() ){
const char* proc_name = rep.get_process_name();
if( proc_name )
os << "(process: " << proc_name << " @ " << rep.get_time().to_string()<<")";
}
}
return os.str();
}
static void report_handler(const sc_report& rep, const sc_actions& actions){
const logging::log_level map[] = {logging::info, logging::warning, logging::error, logging::fatal};
if ( actions & SC_DISPLAY )
LOG(map[rep.get_severity()]) << compose_message(rep);
// if ( (actions & SC_LOG) && log_file_name ) {
// if ( !log_stream ) log_stream = new ::std::ofstream(log_file_name); // ios::trunc
// *log_stream << rep.get_time() << ": " << my_report_compose_message(rep) << ::std::endl;
// }
if ( actions & SC_STOP )
sc_stop();
if ( actions & SC_ABORT )
abort();
if ( actions & SC_THROW )
throw rep;
}
void sysc::init_logging(){
sc_report_handler::set_handler(report_handler);
}
std::once_flag sysc::Logger::once;

+ 1
- 0
src/tracer.cpp View File

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

Loading…
Cancel
Save