Browse Source

cleanup of cmake files and small corrections to infra structure

Eyck Jentzsch 1 year ago
parent
commit
cf3dc1b962
4 changed files with 293 additions and 7 deletions
  1. 0
    6
      cmake/FindSystemC.cmake
  2. 291
    0
      cmake/FindVerilator.cmake
  3. 1
    1
      incl/scc/tlm_target.h
  4. 1
    0
      incl/scc/utilities.h

+ 0
- 6
cmake/FindSystemC.cmake View File

@@ -155,16 +155,10 @@ FIND_PATH(CCI_LIBRARY_DIRS
155 155
 
156 156
 if(SystemC_FOUND)
157 157
         set(SystemC_LIBRARIES systemc)
158
-        message(STATUS "SystemC header files are taken from ${SystemC_INCLUDE_DIRS}")
159
-        message(STATUS "SystemC library is taken from ${SystemC_LIBRARY_DIRS}")
160 158
         if(SCV_FOUND)
161 159
             set(SCV_LIBRARIES scv)
162
-            message(STATUS "SCV header files are taken from ${SCV_INCLUDE_DIRS}")
163
-            message(STATUS "SCV library is taken from ${SCV_LIBRARY_DIRS}")
164 160
         endif(SCV_FOUND)
165 161
         if(CCI_FOUND)
166 162
             set(CCI_LIBRARIES cciapi)
167
-            message(STATUS "CCI header files are taken from ${CCI_INCLUDE_DIRS}")
168
-            message(STATUS "CCI library is taken from ${CCI_LIBRARY_DIRS}")
169 163
         endif()
170 164
 endif(SystemC_FOUND)

+ 291
- 0
cmake/FindVerilator.cmake View File

@@ -0,0 +1,291 @@
1
+# Copyright 2018 Tymoteusz Blazejczyk
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+#     http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS,
11
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+# See the License for the specific language governing permissions and
13
+# limitations under the License.
14
+
15
+#.rst:
16
+# FindVerilator
17
+# --------
18
+#
19
+# Find Verilator
20
+#
21
+# ::
22
+#
23
+#   VERILATOR_EXECUTABLE    - Verilator
24
+#   VERILATOR_FOUND         - true if Verilator found
25
+
26
+if (COMMAND _find_verilator)
27
+    return()
28
+endif()
29
+
30
+function(verilator_target_compile_options target)
31
+    set(options "")
32
+
33
+    if (CMAKE_SYSTEM_NAME MATCHES CYGWIN)
34
+        list(APPEND options -std=gnu++11)
35
+    else()
36
+        list(APPEND options -std=c++11)
37
+    endif()
38
+
39
+    list(APPEND options -fPIC)
40
+
41
+    if (LTO)
42
+        list(APPEND options -flto)
43
+    endif()
44
+
45
+    if (LOGIC_WARNINGS_INTO_ERRORS)
46
+        list(APPEND options -Werror)
47
+    endif()
48
+
49
+    if (CMAKE_BUILD_TYPE MATCHES "Release" OR NOT CMAKE_BUILD_TYPE)
50
+        list(APPEND options
51
+            -O2
52
+            -s
53
+            -DNDEBUG
54
+            -fdata-sections
55
+            -ffunction-sections
56
+        )
57
+    elseif (CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
58
+        list(APPEND options
59
+            -Os
60
+            -DNDEBUG
61
+            -fdata-sections
62
+            -ffunction-sections
63
+        )
64
+    elseif (CMAKE_BUILD_TYPE MATCHES "Coverage")
65
+        list(APPEND options
66
+            -O0
67
+            -g
68
+            --coverage
69
+        )
70
+    endif()
71
+
72
+    list(APPEND options
73
+        -fstrict-aliasing
74
+        -pedantic
75
+        -Wall
76
+        -Wcast-qual
77
+        -Wcomments
78
+        -Wconversion
79
+        -Wctor-dtor-privacy
80
+        -Wdisabled-optimization
81
+        -Wendif-labels
82
+        -Wenum-compare
83
+        -Wfloat-equal
84
+        -Wformat=2
85
+        -Wformat-nonliteral
86
+        -Winit-self
87
+        -Winvalid-pch
88
+        -Wlogical-op
89
+        -Wmissing-declarations
90
+        -Wmissing-include-dirs
91
+        -Wno-long-long
92
+        -Wnon-virtual-dtor
93
+        -Wold-style-cast
94
+        -Woverloaded-virtual
95
+        -Wpacked
96
+        -Wparentheses
97
+        -Wpointer-arith
98
+        #-Wredundant-decls
99
+        -Wshadow
100
+        -Wsign-conversion
101
+        -Wsign-promo
102
+        -Wstack-protector
103
+        -Wstrict-null-sentinel
104
+        -Wstrict-overflow=2
105
+        -Wsuggest-attribute=noreturn
106
+        -Wswitch-default
107
+        -Wswitch-enum
108
+        -Wundef
109
+        -Wuninitialized
110
+        -Wunknown-pragmas
111
+        -Wunused
112
+        -Wunused-function
113
+        -Wwrite-strings
114
+    )
115
+
116
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
117
+        list(APPEND options
118
+            -Wduplicated-cond
119
+            -Whsa
120
+            -Wignored-attributes
121
+            -Wmisleading-indentation
122
+            -Wnull-dereference
123
+            -Wplacement-new=2
124
+            -Wshift-negative-value
125
+            -Wshift-overflow=2
126
+            -Wvirtual-inheritance
127
+        )
128
+    endif()
129
+
130
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
131
+        list(APPEND options
132
+            -Wdouble-promotion
133
+            -Wsized-deallocation
134
+            -Wsuggest-override
135
+            -Wtrampolines
136
+            -Wvector-operation-performance
137
+            -Wzero-as-null-pointer-constant
138
+        )
139
+    endif()
140
+
141
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
142
+        list(APPEND options
143
+            -Wconditionally-supported
144
+            -Wdate-time
145
+            -Weffc++
146
+            -Wextra
147
+            -Winline
148
+            -Wopenmp-simd
149
+        )
150
+    endif()
151
+
152
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
153
+        list(APPEND options
154
+            -Wpedantic
155
+            -Wsuggest-attribute=format
156
+        )
157
+    endif()
158
+
159
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
160
+        list(APPEND options
161
+            -Wnoexcept
162
+        )
163
+    endif()
164
+
165
+    target_compile_options(${target} PRIVATE ${options} ${ARGN})
166
+endfunction()
167
+
168
+function(_find_verilator)
169
+    find_package(PackageHandleStandardArgs REQUIRED)
170
+    find_package(SystemC)
171
+
172
+    find_program(VERILATOR_EXECUTABLE verilator
173
+        HINTS $ENV{VERILATOR_ROOT} /usr/local/bin
174
+        PATH_SUFFIXES bin
175
+        DOC "Path to the Verilator executable"
176
+    )
177
+   	if(VERILATOR_EXECUTABLE STREQUAL VERILATOR_EXECUTABLE-NOTFOUND)
178
+    	message( FATAL_ERROR "verilator not found." )
179
+	endif()
180
+    
181
+
182
+    find_program(VERILATOR_COVERAGE_EXECUTABLE verilator_coverage
183
+        HINTS $ENV{VERILATOR_ROOT} /usr/local/bin
184
+        PATH_SUFFIXES bin
185
+        DOC "Path to the Verilator coverage executable"
186
+    )
187
+
188
+    get_filename_component(VERILATOR_EXECUTABLE_DIR ${VERILATOR_EXECUTABLE}
189
+        DIRECTORY)
190
+
191
+    find_path(VERILATOR_INCLUDE_DIR verilated.h
192
+        HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_EXECUTABLE_DIR}/.. /usr/local
193
+        PATH_SUFFIXES include share/verilator/include
194
+        DOC "Path to the Verilator headers"
195
+    )
196
+   	if(VERILATOR_INCLUDE_DIR STREQUAL VERILATOR_INCLUDE_DIR-NOTFOUND)
197
+    	message( FATAL_ERROR "verilator include files not found." )
198
+	endif()
199
+
200
+    mark_as_advanced(VERILATOR_EXECUTABLE)
201
+    mark_as_advanced(VERILATOR_COVERAGE_EXECUTABLE)
202
+    mark_as_advanced(VERILATOR_INCLUDE_DIR)
203
+
204
+    find_package_handle_standard_args(Verilator REQUIRED_VARS
205
+        VERILATOR_EXECUTABLE VERILATOR_COVERAGE_EXECUTABLE VERILATOR_INCLUDE_DIR)
206
+
207
+    if (WIN32)
208
+        set(library_policy STATIC)
209
+    else()
210
+        set(library_policy SHARED)
211
+    endif()
212
+
213
+    add_library(verilated ${library_policy}
214
+        ${VERILATOR_INCLUDE_DIR}/verilated.cpp
215
+        ${VERILATOR_INCLUDE_DIR}/verilated_cov.cpp
216
+        ${VERILATOR_INCLUDE_DIR}/verilated_dpi.cpp
217
+        ${VERILATOR_INCLUDE_DIR}/verilated_vcd_c.cpp
218
+        ${VERILATOR_INCLUDE_DIR}/verilated_vcd_sc.cpp
219
+        #${CMAKE_CURRENT_LIST_DIR}/verilator_callbacks.cpp
220
+    )
221
+
222
+    set_target_properties(verilated PROPERTIES
223
+        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
224
+        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
225
+        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
226
+    )
227
+
228
+    set_source_files_properties(
229
+        ${VERILATOR_INCLUDE_DIR}/verilated.cpp
230
+        PROPERTIES
231
+            COMPILE_DEFINITIONS "VL_USER_STOP;VL_USER_FINISH"
232
+    )
233
+
234
+    set_source_files_properties(
235
+        ${VERILATOR_INCLUDE_DIR}/verilated_cov.cpp
236
+        PROPERTIES
237
+            COMPILE_DEFINITIONS "VM_COVERAGE=1"
238
+    )
239
+
240
+    target_link_libraries(verilated PRIVATE systemc)
241
+
242
+    set_target_properties(verilated PROPERTIES
243
+        ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
244
+        LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
245
+    )
246
+
247
+    target_include_directories(verilated SYSTEM PRIVATE
248
+        ${VERILATOR_INCLUDE_DIR}
249
+        ${VERILATOR_INCLUDE_DIR}/vltstd
250
+        ${SYSTEMC_INCLUDE_DIRS}
251
+    )
252
+
253
+    if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
254
+        verilator_target_compile_options(verilated PRIVATE
255
+            -Wno-attributes
256
+            -Wno-cast-qual
257
+            -Wno-float-equal
258
+            -Wno-suggest-override
259
+            -Wno-conversion
260
+            -Wno-unused-parameter
261
+            -Wno-effc++
262
+            -Wno-format
263
+            -Wno-format-nonliteral
264
+            -Wno-missing-declarations
265
+            -Wno-old-style-cast
266
+            -Wno-shadow
267
+            -Wno-sign-conversion
268
+            -Wno-strict-overflow
269
+            -Wno-suggest-attribute=noreturn
270
+            -Wno-suggest-final-methods
271
+            -Wno-suggest-final-types
272
+            -Wno-switch-default
273
+            -Wno-switch-enum
274
+            -Wno-undef
275
+            -Wno-inline
276
+            -Wno-variadic-macros
277
+            -Wno-suggest-attribute=format
278
+            -Wno-zero-as-null-pointer-constant
279
+        )
280
+    elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
281
+        verilator_target_compile_options(verilated PRIVATE -Wno-everything)
282
+    endif()
283
+
284
+    set(VERILATOR_FOUND ${VERILATOR_FOUND} PARENT_SCOPE)
285
+    set(VERILATOR_EXECUTABLE "${VERILATOR_EXECUTABLE}" PARENT_SCOPE)
286
+    set(VERILATOR_INCLUDE_DIR "${VERILATOR_INCLUDE_DIR}" PARENT_SCOPE)
287
+    set(VERILATOR_COVERAGE_EXECUTABLE "${VERILATOR_COVERAGE_EXECUTABLE}"
288
+        PARENT_SCOPE)
289
+endfunction()
290
+
291
+_find_verilator()

+ 1
- 1
incl/scc/tlm_target.h View File

@@ -89,7 +89,7 @@ protected:
89 89
 };
90 90
 
91 91
 template <unsigned BUSWIDTH = 32> struct target_memory_map_entry {
92
-    scc::tlm_target<BUSWIDTH> *target;
92
+    tlm::tlm_target_socket<BUSWIDTH>& target;
93 93
     sc_dt::uint64 start;
94 94
     sc_dt::uint64 size;
95 95
 };

+ 1
- 0
incl/scc/utilities.h View File

@@ -35,6 +35,7 @@
35 35
 
36 36
 #define NAMED(X, ...) X(#X, ##__VA_ARGS__)
37 37
 #define NAMEDD(T, X, ...) X(new T(#X, ##__VA_ARGS__))
38
+#define CREATE(T, X, I, ...)  X(T::create<I>(#X, ##__VA_ARGS__))
38 39
 
39 40
 #define TRACE_VAR(F, X) sc_core::sc_trace(F, X, std::string(this->name()) + "." #X)
40 41
 #define TRACE_ARR(F, X, I)                                                                                             \