diff --git a/Changes b/Changes index f3f250292..526a53539 100644 --- a/Changes +++ b/Changes @@ -24,6 +24,7 @@ Verilator 4.211 devel C++ direct references to parameters might require updating (#3077). [Geza Lore] * Refactored Verilated include files; include verilated.h not verilated_heavy.h. * Add error when constant function under a generate (#3103). [Don Owen] +* Add header guards on Dpi.h generated files (#2979). [Tood Strader] * Fix -G to treat simple integer literals as signed (#3060). [Anikin1610] * Fix emitted string array initializers (#2895). [Iztok Jeras] * Fix bitop tree optimization dropping necessary & operator (#3096). [Flavien Solt] diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index f86dd7487..fc430a369 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -940,6 +940,9 @@ void EmitCSyms::emitDpiHdr() { puts("// Verilator includes this file in all generated .cpp files that use DPI functions.\n"); puts("// Manually include this file where DPI .c import functions are declared to ensure\n"); puts("// the C functions match the expectations of the DPI imports.\n"); + + ofp()->putsGuard(); + puts("\n"); puts("#include \"svdpi.h\"\n"); puts("\n"); @@ -970,6 +973,8 @@ void EmitCSyms::emitDpiHdr() { puts("#ifdef __cplusplus\n"); puts("}\n"); puts("#endif\n"); + + ofp()->putsEndGuard(); } //###################################################################### diff --git a/test_regress/t/t_dpi_arg_inout_type__Dpi.out b/test_regress/t/t_dpi_arg_inout_type__Dpi.out index 01379ddcd..b800f7d8f 100644 --- a/test_regress/t/t_dpi_arg_inout_type__Dpi.out +++ b/test_regress/t/t_dpi_arg_inout_type__Dpi.out @@ -5,6 +5,9 @@ // Manually include this file where DPI .c import functions are declared to ensure // the C functions match the expectations of the DPI imports. +#ifndef VERILATED_VT_DPI_ARG_INOUT_TYPE__DPI_H_ +#define VERILATED_VT_DPI_ARG_INOUT_TYPE__DPI_H_ // guard + #include "svdpi.h" #ifdef __cplusplus @@ -152,3 +155,5 @@ extern "C" { #ifdef __cplusplus } #endif + +#endif // guard diff --git a/test_regress/t/t_dpi_arg_inout_unpack__Dpi.out b/test_regress/t/t_dpi_arg_inout_unpack__Dpi.out index e4f0d5949..8c6d9be71 100644 --- a/test_regress/t/t_dpi_arg_inout_unpack__Dpi.out +++ b/test_regress/t/t_dpi_arg_inout_unpack__Dpi.out @@ -5,6 +5,9 @@ // Manually include this file where DPI .c import functions are declared to ensure // the C functions match the expectations of the DPI imports. +#ifndef VERILATED_VT_DPI_ARG_INOUT_UNPACK__DPI_H_ +#define VERILATED_VT_DPI_ARG_INOUT_UNPACK__DPI_H_ // guard + #include "svdpi.h" #ifdef __cplusplus @@ -181,3 +184,5 @@ extern "C" { #ifdef __cplusplus } #endif + +#endif // guard diff --git a/test_regress/t/t_dpi_arg_input_type__Dpi.out b/test_regress/t/t_dpi_arg_input_type__Dpi.out index 632b44b9c..d0994c659 100644 --- a/test_regress/t/t_dpi_arg_input_type__Dpi.out +++ b/test_regress/t/t_dpi_arg_input_type__Dpi.out @@ -5,6 +5,9 @@ // Manually include this file where DPI .c import functions are declared to ensure // the C functions match the expectations of the DPI imports. +#ifndef VERILATED_VT_DPI_ARG_INPUT_TYPE__DPI_H_ +#define VERILATED_VT_DPI_ARG_INPUT_TYPE__DPI_H_ // guard + #include "svdpi.h" #ifdef __cplusplus @@ -152,3 +155,5 @@ extern "C" { #ifdef __cplusplus } #endif + +#endif // guard diff --git a/test_regress/t/t_dpi_arg_input_unpack__Dpi.out b/test_regress/t/t_dpi_arg_input_unpack__Dpi.out index 0867d13f0..4d1afa518 100644 --- a/test_regress/t/t_dpi_arg_input_unpack__Dpi.out +++ b/test_regress/t/t_dpi_arg_input_unpack__Dpi.out @@ -5,6 +5,9 @@ // Manually include this file where DPI .c import functions are declared to ensure // the C functions match the expectations of the DPI imports. +#ifndef VERILATED_VT_DPI_ARG_INPUT_UNPACK__DPI_H_ +#define VERILATED_VT_DPI_ARG_INPUT_UNPACK__DPI_H_ // guard + #include "svdpi.h" #ifdef __cplusplus @@ -181,3 +184,5 @@ extern "C" { #ifdef __cplusplus } #endif + +#endif // guard diff --git a/test_regress/t/t_dpi_arg_output_type__Dpi.out b/test_regress/t/t_dpi_arg_output_type__Dpi.out index 1a9db977f..e84de47c3 100644 --- a/test_regress/t/t_dpi_arg_output_type__Dpi.out +++ b/test_regress/t/t_dpi_arg_output_type__Dpi.out @@ -5,6 +5,9 @@ // Manually include this file where DPI .c import functions are declared to ensure // the C functions match the expectations of the DPI imports. +#ifndef VERILATED_VT_DPI_ARG_OUTPUT_TYPE__DPI_H_ +#define VERILATED_VT_DPI_ARG_OUTPUT_TYPE__DPI_H_ // guard + #include "svdpi.h" #ifdef __cplusplus @@ -152,3 +155,5 @@ extern "C" { #ifdef __cplusplus } #endif + +#endif // guard diff --git a/test_regress/t/t_dpi_arg_output_unpack__Dpi.out b/test_regress/t/t_dpi_arg_output_unpack__Dpi.out index 24675921e..ddcd704de 100644 --- a/test_regress/t/t_dpi_arg_output_unpack__Dpi.out +++ b/test_regress/t/t_dpi_arg_output_unpack__Dpi.out @@ -5,6 +5,9 @@ // Manually include this file where DPI .c import functions are declared to ensure // the C functions match the expectations of the DPI imports. +#ifndef VERILATED_VT_DPI_ARG_OUTPUT_UNPACK__DPI_H_ +#define VERILATED_VT_DPI_ARG_OUTPUT_UNPACK__DPI_H_ // guard + #include "svdpi.h" #ifdef __cplusplus @@ -181,3 +184,5 @@ extern "C" { #ifdef __cplusplus } #endif + +#endif // guard diff --git a/test_regress/t/t_dpi_result_type__Dpi.out b/test_regress/t/t_dpi_result_type__Dpi.out index cd2d0ecc8..344971158 100644 --- a/test_regress/t/t_dpi_result_type__Dpi.out +++ b/test_regress/t/t_dpi_result_type__Dpi.out @@ -5,6 +5,9 @@ // Manually include this file where DPI .c import functions are declared to ensure // the C functions match the expectations of the DPI imports. +#ifndef VERILATED_VT_DPI_RESULT_TYPE__DPI_H_ +#define VERILATED_VT_DPI_RESULT_TYPE__DPI_H_ // guard + #include "svdpi.h" #ifdef __cplusplus @@ -86,3 +89,5 @@ extern "C" { #ifdef __cplusplus } #endif + +#endif // guard