Support`--compiler-include` headers in user-supplied cpp files (#5271)
Signed-off-by: Bartłomiej Chmiel <bchmiel@antmicro.com>
This commit is contained in:
parent
cb5d03ff0b
commit
20dba7464d
|
|
@ -236,11 +236,18 @@ public:
|
|||
of.puts("\n");
|
||||
}
|
||||
|
||||
const string compilerIncludePch
|
||||
= v3Global.opt.compilerIncludes().empty() ? "" : "$(VK_PCH_H).fast.gch";
|
||||
const string compilerIncludeFlag
|
||||
= v3Global.opt.compilerIncludes().empty() ? "" : "$(VK_PCH_I_FAST)";
|
||||
for (const string& cppfile : cppFiles) {
|
||||
const string basename = V3Os::filenameNonDirExt(cppfile);
|
||||
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
|
||||
of.puts(basename + ".o: " + cppfile + "\n");
|
||||
of.puts("\t$(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $<\n");
|
||||
of.puts(basename + ".o: " + cppfile + " " + compilerIncludePch + "\n");
|
||||
|
||||
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
|
||||
of.puts("\t$(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) "
|
||||
+ compilerIncludeFlag + " -c -o $@ $<\n");
|
||||
}
|
||||
|
||||
if (v3Global.opt.exe()) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
||||
//*************************************************************************
|
||||
//
|
||||
// Copyright 2009-2024 by Antmicro. This program is free software; you can
|
||||
// Copyright 2024 by Antmicro. This program is free software; you can
|
||||
// redistribute it and/or modify it under the terms of either the GNU
|
||||
// Lesser General Public License Version 3 or the Perl Artistic License
|
||||
// Version 2.0.
|
||||
|
|
@ -9,34 +9,23 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
|
||||
#include "svdpi.h"
|
||||
// t_compiler_include.h is implicitly included by `--compiler-include`
|
||||
|
||||
// These require the above. Comment prevents clang-format moving them
|
||||
#include "TestCheck.h"
|
||||
#include <verilated.h>
|
||||
#include VM_PREFIX_INCLUDE
|
||||
|
||||
//======================================================================
|
||||
int main() {
|
||||
Verilated::debug(0);
|
||||
|
||||
// clang-format off
|
||||
#if defined(VERILATOR)
|
||||
# include "Vt_compiler_include__Dpi.h"
|
||||
#elif defined(VCS)
|
||||
# include "../vc_hdrs.h"
|
||||
#elif defined(NC)
|
||||
# define NEED_EXTERNS
|
||||
// #elif defined(MS)
|
||||
// # define NEED_EXTERNS
|
||||
#else
|
||||
# error "Unknown simulator for DPI test"
|
||||
#endif
|
||||
// clang-format on
|
||||
VM_PREFIX* topp = new VM_PREFIX;
|
||||
topp->in = 123;
|
||||
topp->eval();
|
||||
|
||||
#ifdef NEED_EXTERNS
|
||||
extern "C" {
|
||||
// If get ncsim: *F,NOFDPI: Function {foo} not found in default libdpi.
|
||||
// Then probably forgot to list a function here.
|
||||
if (ext_equal(topp->in, topp->out))
|
||||
VL_PRINTF("*-* All Finished *-*\n");
|
||||
else
|
||||
VL_PRINTF("in (%d) != out (%d)\n", topp->in, topp->out);
|
||||
|
||||
extern void dpii_add(int a, int b, int* out);
|
||||
topp->final();
|
||||
VL_DO_DANGLING(delete topp, topp);
|
||||
}
|
||||
#endif
|
||||
|
||||
void dpii_add(int a, int b, int* out) { *out = a + b; }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
||||
//*************************************************************************
|
||||
//
|
||||
// Copyright 2009-2024 by Antmicro. This program is free software; you can
|
||||
// Copyright 2024 by Antmicro. This program is free software; you can
|
||||
// redistribute it and/or modify it under the terms of either the GNU
|
||||
// Lesser General Public License Version 3 or the Perl Artistic License
|
||||
// Version 2.0.
|
||||
|
|
@ -11,4 +11,4 @@
|
|||
|
||||
// no header guards to check if included once in pch file
|
||||
|
||||
extern "C" int dpii_add_check(int actual, int expected) { return actual == expected; }
|
||||
static inline int ext_equal(int actual, int expected) { return actual == expected; }
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di
|
|||
scenarios(simulator => 1);
|
||||
|
||||
compile(
|
||||
v_flags2 => ["t/t_compiler_include.cpp"],
|
||||
verilator_flags2 => ["-Wall -Wno-DECLFILENAME --compiler-include $Self->{t_dir}/t_compiler_include.h"],
|
||||
make_top_shell => 0,
|
||||
make_main => 0,
|
||||
verilator_flags2 => ["--exe", "$Self->{t_dir}/$Self->{name}.cpp", "--compiler-include $Self->{t_dir}/t_compiler_include.h", "--output-split 0"],
|
||||
);
|
||||
|
||||
execute(
|
||||
|
|
|
|||
|
|
@ -6,26 +6,6 @@
|
|||
// Version 2.0.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
module t (/*AUTOARG*/);
|
||||
int a = 123;
|
||||
int b = 321;
|
||||
int out;
|
||||
|
||||
import "DPI-C" function void dpii_add
|
||||
(int a, int b, ref int out);
|
||||
import "DPI-C" function int dpii_add_check
|
||||
(int actual, int expected);
|
||||
|
||||
initial begin
|
||||
dpii_add(a, b, out);
|
||||
if (dpii_add_check(out, (a + b)) != 1) begin
|
||||
$write("%%Error: Failure in DPI tests\n");
|
||||
$stop;
|
||||
end
|
||||
else begin
|
||||
$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
end
|
||||
|
||||
module t (input logic[31:0] in, output logic[31:0] out);
|
||||
assign out = in;
|
||||
endmodule
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
||||
//*************************************************************************
|
||||
//
|
||||
// Copyright 2024 by Antmicro. This program is free software; you can
|
||||
// redistribute it and/or modify it under the terms of either the GNU
|
||||
// Lesser General Public License Version 3 or the Perl Artistic License
|
||||
// Version 2.0.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
// t_compiler_include.h is implicitly included by `--compiler-include`
|
||||
|
||||
int dpii_add_check(int actual, int expected) { return actual == expected; }
|
||||
void dpii_add(int a, int b, int* out) { *out = a + b; }
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
||||
//*************************************************************************
|
||||
//
|
||||
// Copyright 2024 by Antmicro. This program is free software; you can
|
||||
// redistribute it and/or modify it under the terms of either the GNU
|
||||
// Lesser General Public License Version 3 or the Perl Artistic License
|
||||
// Version 2.0.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
// no header guards to check if included once in pch file
|
||||
|
||||
extern "C" int dpii_add_check(int actual, int expected);
|
||||
extern "C" void dpii_add(int a, int b, int* out);
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2024 by Wilson Snyder. This program is free software; you
|
||||
# can redistribute it and/or modify it under the terms of either the GNU
|
||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||
# Version 2.0.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(simulator => 1);
|
||||
top_filename("t/t_compiler_include_dpi.v");
|
||||
|
||||
compile(
|
||||
v_flags2 => ["t/t_compiler_include_dpi.cpp"],
|
||||
verilator_flags2 => ["-Wall -Wno-DECLFILENAME --compiler-include $Self->{t_dir}/t_compiler_include_dpi.h --output-split 0"],
|
||||
);
|
||||
|
||||
execute(
|
||||
check_finished => 1,
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// Copyright 2024 by Antmicro. This program is free software; you can
|
||||
// redistribute it and/or modify it under the terms of either the GNU
|
||||
// Lesser General Public License Version 3 or the Perl Artistic License
|
||||
// Version 2.0.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
module t (/*AUTOARG*/);
|
||||
int a = 123;
|
||||
int b = 321;
|
||||
int out;
|
||||
|
||||
import "DPI-C" function void dpii_add
|
||||
(int a, int b, ref int out);
|
||||
import "DPI-C" function int dpii_add_check
|
||||
(int actual, int expected);
|
||||
|
||||
initial begin
|
||||
dpii_add(a, b, out);
|
||||
if (dpii_add_check(out, (a + b)) != 1) begin
|
||||
$write("%%Error: Failure in DPI tests\n");
|
||||
$stop;
|
||||
end
|
||||
else begin
|
||||
$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2024 by Wilson Snyder. This program is free software; you
|
||||
# can redistribute it and/or modify it under the terms of either the GNU
|
||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||
# Version 2.0.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(simulator => 1);
|
||||
top_filename("t/t_compiler_include_dpi.v");
|
||||
|
||||
compile(
|
||||
v_flags2 => ["t/t_compiler_include_dpi.cpp"],
|
||||
verilator_flags2 => ["-Wall -Wno-DECLFILENAME --compiler-include $Self->{t_dir}/t_compiler_include_dpi.h --output-split 1"],
|
||||
);
|
||||
|
||||
execute(
|
||||
check_finished => 1,
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2024 by Wilson Snyder. This program is free software; you
|
||||
# can redistribute it and/or modify it under the terms of either the GNU
|
||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||
# Version 2.0.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(simulator => 1);
|
||||
top_filename("t/t_compiler_include.v");
|
||||
|
||||
compile(
|
||||
make_top_shell => 0,
|
||||
make_main => 0,
|
||||
verilator_flags2 => ["--exe", "$Self->{t_dir}/t_compiler_include.cpp", "--compiler-include $Self->{t_dir}/t_compiler_include.h", "--output-split 1"],
|
||||
);
|
||||
|
||||
execute(
|
||||
check_finished => 1,
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
||||
Loading…
Reference in New Issue