mirror of
https://github.com/YosysHQ/yosys
synced 2026-06-02 15:18:07 +00:00
Merge pull request #5882 from YosysHQ/std_cpp20
Bump required standard to C++20
This commit is contained in:
commit
1d87cefd80
13 changed files with 42 additions and 32 deletions
32
.github/workflows/test-compile.yml
vendored
32
.github/workflows/test-compile.yml
vendored
|
|
@ -44,18 +44,18 @@ jobs:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
compiler:
|
compiler:
|
||||||
# oldest supported
|
# oldest supported
|
||||||
- 'clang-10'
|
- 'clang-14'
|
||||||
- 'gcc-10'
|
- 'gcc-11'
|
||||||
# newest, make sure to update maximum standard step to match
|
# newest, make sure to update maximum standard step to match
|
||||||
- 'clang-19'
|
- 'clang-22'
|
||||||
- 'gcc-14'
|
- 'gcc-15'
|
||||||
include:
|
include:
|
||||||
# macOS x86
|
# macOS x86
|
||||||
- os: macos-15-intel
|
- os: macos-15-intel
|
||||||
compiler: 'clang-19'
|
compiler: 'clang-22'
|
||||||
# macOS arm
|
# macOS arm
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
compiler: 'clang-19'
|
compiler: 'clang-22'
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Yosys
|
- name: Checkout Yosys
|
||||||
|
|
@ -74,6 +74,7 @@ jobs:
|
||||||
uses: aminya/setup-cpp@v1
|
uses: aminya/setup-cpp@v1
|
||||||
with:
|
with:
|
||||||
compiler: ${{ matrix.compiler }}
|
compiler: ${{ matrix.compiler }}
|
||||||
|
gcc: ${{ (matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-14') && '12' || '' }}
|
||||||
|
|
||||||
- name: Tool versions
|
- name: Tool versions
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
@ -81,21 +82,26 @@ jobs:
|
||||||
$CC --version
|
$CC --version
|
||||||
$CXX --version
|
$CXX --version
|
||||||
|
|
||||||
# minimum standard
|
- name: Fix clang-14 toolchain
|
||||||
- name: Build C++17
|
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-14'
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
make config-$CC_SHORT
|
echo 'CXXFLAGS=--gcc-toolchain=/usr -isystem /usr/include/c++/12 -isystem /usr/include/x86_64-linux-gnu/c++/12' >> $GITHUB_ENV
|
||||||
make -j$procs CXXSTD=c++17 compile-only
|
|
||||||
|
|
||||||
# maximum standard, only on newest compilers
|
# minimum standard
|
||||||
- name: Build C++20
|
- name: Build C++20
|
||||||
if: ${{ matrix.compiler == 'clang-19' || matrix.compiler == 'gcc-14' }}
|
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
make config-$CC_SHORT
|
make config-$CC_SHORT
|
||||||
make -j$procs CXXSTD=c++20 compile-only
|
make -j$procs CXXSTD=c++20 compile-only
|
||||||
|
|
||||||
|
# maximum standard, only on newest compilers
|
||||||
|
- name: Build C++26
|
||||||
|
if: ${{ matrix.compiler == 'clang-22' || matrix.compiler == 'gcc-15' }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
make config-$CC_SHORT
|
||||||
|
make -j$procs CXXSTD=c++26 compile-only
|
||||||
|
|
||||||
test-compile-result:
|
test-compile-result:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
|
|
|
||||||
4
Makefile
4
Makefile
|
|
@ -103,7 +103,7 @@ VPATH := $(YOSYS_SRC)
|
||||||
# Unit test
|
# Unit test
|
||||||
UNITESTPATH := $(YOSYS_SRC)/tests/unit
|
UNITESTPATH := $(YOSYS_SRC)/tests/unit
|
||||||
|
|
||||||
export CXXSTD ?= c++17
|
export CXXSTD ?= c++20
|
||||||
CXXFLAGS := $(CXXFLAGS) -Wall -Wextra -Werror=unused -ggdb -I. -I"$(YOSYS_SRC)" -MD -MP -D_YOSYS_ -fPIC -I$(PREFIX)/include
|
CXXFLAGS := $(CXXFLAGS) -Wall -Wextra -Werror=unused -ggdb -I. -I"$(YOSYS_SRC)" -MD -MP -D_YOSYS_ -fPIC -I$(PREFIX)/include
|
||||||
LIBS := $(LIBS) -lstdc++ -lm
|
LIBS := $(LIBS) -lstdc++ -lm
|
||||||
PLUGIN_LINKFLAGS :=
|
PLUGIN_LINKFLAGS :=
|
||||||
|
|
@ -1142,7 +1142,7 @@ vcxsrc: $(GENFILES) $(EXTRA_TARGETS) kernel/version_$(GIT_REV).cc
|
||||||
rm -rf $(VCX_DIR_NAME){,.zip}
|
rm -rf $(VCX_DIR_NAME){,.zip}
|
||||||
cp -f kernel/version_$(GIT_REV).cc kernel/version.cc
|
cp -f kernel/version_$(GIT_REV).cc kernel/version.cc
|
||||||
set -e; for f in `ls $(filter %.cc %.cpp,$(GENFILES)) $(addsuffix .cc,$(basename $(OBJS))) $(addsuffix .cpp,$(basename $(OBJS))) 2> /dev/null`; do \
|
set -e; for f in `ls $(filter %.cc %.cpp,$(GENFILES)) $(addsuffix .cc,$(basename $(OBJS))) $(addsuffix .cpp,$(basename $(OBJS))) 2> /dev/null`; do \
|
||||||
echo "Analyse: $$f" >&2; cpp -std=c++17 -MM -I. -D_YOSYS_ $$f; done | sed 's,.*:,,; s,//*,/,g; s,/[^/]*/\.\./,/,g; y, \\,\n\n,;' | grep '^[^/]' | sort -u | grep -v kernel/version_ > srcfiles.txt
|
echo "Analyse: $$f" >&2; cpp -std=c++20 -MM -I. -D_YOSYS_ $$f; done | sed 's,.*:,,; s,//*,/,g; s,/[^/]*/\.\./,/,g; y, \\,\n\n,;' | grep '^[^/]' | sort -u | grep -v kernel/version_ > srcfiles.txt
|
||||||
echo "libs/fst/fst_win_unistd.h" >> srcfiles.txt
|
echo "libs/fst/fst_win_unistd.h" >> srcfiles.txt
|
||||||
echo "kernel/version.cc" >> srcfiles.txt
|
echo "kernel/version.cc" >> srcfiles.txt
|
||||||
bash misc/create_vcxsrc.sh $(VCX_DIR_NAME) $(YOSYS_VER)
|
bash misc/create_vcxsrc.sh $(VCX_DIR_NAME) $(YOSYS_VER)
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ not regularly tested:
|
||||||
Build prerequisites
|
Build prerequisites
|
||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
A C++ compiler with C++17 support is required as well as some standard tools
|
A C++ compiler with C++20 support is required as well as some standard tools
|
||||||
such as GNU Flex, GNU Bison (>=3.8), Make, and Python (>=3.11). Some additional
|
such as GNU Flex, GNU Bison (>=3.8), Make, and Python (>=3.11). Some additional
|
||||||
tools: readline, libffi, Tcl and zlib; are optional but enabled by default (see
|
tools: readline, libffi, Tcl and zlib; are optional but enabled by default (see
|
||||||
:makevar:`ENABLE_*` settings in Makefile). Graphviz and Xdot are used by the
|
:makevar:`ENABLE_*` settings in Makefile). Graphviz and Xdot are used by the
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ have incorrect results in unusual situations.
|
||||||
Coding style
|
Coding style
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
Yosys is written in C++17.
|
Yosys is written in C++20.
|
||||||
|
|
||||||
In general Yosys uses ``int`` instead of ``size_t``. To avoid compiler warnings
|
In general Yosys uses ``int`` instead of ``size_t``. To avoid compiler warnings
|
||||||
for implicit type casts, always use ``GetSize(foobar)`` instead of
|
for implicit type casts, always use ``GetSize(foobar)`` instead of
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ wide range of real-world designs, including the `OpenRISC 1200 CPU`_, the
|
||||||
|
|
||||||
.. _k68 CPU: http://opencores.org/projects/k68
|
.. _k68 CPU: http://opencores.org/projects/k68
|
||||||
|
|
||||||
Yosys is written in C++, targeting C++17 at minimum. This chapter describes some
|
Yosys is written in C++, targeting C++20 at minimum. This chapter describes some
|
||||||
of the fundamental Yosys data structures. For the sake of simplicity the C++
|
of the fundamental Yosys data structures. For the sake of simplicity the C++
|
||||||
type names used in the Yosys implementation are used in this chapter, even
|
type names used in the Yosys implementation are used in this chapter, even
|
||||||
though the chapter only explains the conceptual idea behind it and can be used
|
though the chapter only explains the conceptual idea behind it and can be used
|
||||||
|
|
|
||||||
|
|
@ -804,8 +804,10 @@ std::string Fmt::render() const
|
||||||
buf += 'X';
|
buf += 'X';
|
||||||
else if (has_z)
|
else if (has_z)
|
||||||
buf += 'Z';
|
buf += 'Z';
|
||||||
else
|
else {
|
||||||
buf += (part.hex_upper ? "0123456789ABCDEF" : "0123456789abcdef")[subvalue.as_int()];
|
const char *digits = part.hex_upper ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||||
|
buf += digits[subvalue.as_int()];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (part.base == 10) {
|
} else if (part.base == 10) {
|
||||||
if (part.show_base)
|
if (part.show_base)
|
||||||
|
|
|
||||||
|
|
@ -475,7 +475,8 @@ public:
|
||||||
private:
|
private:
|
||||||
std::string_view fmt;
|
std::string_view fmt;
|
||||||
bool has_escapes = false;
|
bool has_escapes = false;
|
||||||
FoundFormatSpec specs[sizeof...(Args)] = {};
|
// Making array at least size of one to make MSVC happy and strict to standards
|
||||||
|
FoundFormatSpec specs[sizeof...(Args) ? sizeof...(Args) : 1] = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct WrapType { using type = T; };
|
template <typename T> struct WrapType { using type = T; };
|
||||||
|
|
|
||||||
|
|
@ -120,10 +120,10 @@
|
||||||
# define YS_MAYBE_UNUSED
|
# define YS_MAYBE_UNUSED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 202002L
|
||||||
# define YS_FALLTHROUGH [[fallthrough]];
|
# define YS_FALLTHROUGH [[fallthrough]];
|
||||||
#else
|
#else
|
||||||
# error "C++17 or later compatible compiler is required"
|
# error "C++20 or later compatible compiler is required"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__has_cpp_attribute) && __has_cpp_attribute(gnu::cold)
|
#if defined(__has_cpp_attribute) && __has_cpp_attribute(gnu::cold)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ if [ -f "/usr/include/FlexLexer.h" ] ; then
|
||||||
cp /usr/include/FlexLexer.h libs/flex/FlexLexer.h
|
cp /usr/include/FlexLexer.h libs/flex/FlexLexer.h
|
||||||
ls libs/flex/*.h >> ../../srcfiles.txt
|
ls libs/flex/*.h >> ../../srcfiles.txt
|
||||||
fi
|
fi
|
||||||
|
sed -i '\#libs/../kernel/yosys.h#d' ../../srcfiles.txt
|
||||||
|
|
||||||
popd
|
popd
|
||||||
{
|
{
|
||||||
|
|
@ -35,7 +36,7 @@ popd
|
||||||
tail -n +$((n+1)) "$vcxsrc"/YosysVS/YosysVS.vcxproj
|
tail -n +$((n+1)) "$vcxsrc"/YosysVS/YosysVS.vcxproj
|
||||||
} > "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
} > "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
||||||
|
|
||||||
sed -i 's,</AdditionalIncludeDirectories>,</AdditionalIncludeDirectories>\n <LanguageStandard>stdcpp17</LanguageStandard>\n <AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
sed -i 's,</AdditionalIncludeDirectories>,</AdditionalIncludeDirectories>\n <LanguageStandard>stdcpp20</LanguageStandard>\n <AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
||||||
sed -i 's,<PreprocessorDefinitions>,<PreprocessorDefinitions>YOSYS_ENABLE_THREADS;,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
sed -i 's,<PreprocessorDefinitions>,<PreprocessorDefinitions>YOSYS_ENABLE_THREADS;,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
||||||
if [ -f "/usr/include/FlexLexer.h" ] ; then
|
if [ -f "/usr/include/FlexLexer.h" ] ; then
|
||||||
sed -i 's,</AdditionalIncludeDirectories>,;..\\yosys\\libs\\flex</AdditionalIncludeDirectories>,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
sed -i 's,</AdditionalIncludeDirectories>,;..\\yosys\\libs\\flex</AdditionalIncludeDirectories>,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ struct EstimateSta {
|
||||||
cell, cell->type.unescape());
|
cell, cell->type.unescape());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ff.sig_clk != clk)
|
if (!clk || ff.sig_clk.as_bit() != *clk)
|
||||||
continue;
|
continue;
|
||||||
launch.append(ff.sig_q);
|
launch.append(ff.sig_q);
|
||||||
sample.append(ff.sig_d);
|
sample.append(ff.sig_d);
|
||||||
|
|
@ -144,12 +144,12 @@ struct EstimateSta {
|
||||||
log_error("Unsupported async memory port '%s'\n", rd.cell);
|
log_error("Unsupported async memory port '%s'\n", rd.cell);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sigmap(rd.clk) != clk)
|
if (!clk || sigmap(rd.clk).as_bit() != *clk)
|
||||||
continue;
|
continue;
|
||||||
add_seq(rd.cell, rd.data, {rd.addr, rd.srst, rd.en});
|
add_seq(rd.cell, rd.data, {rd.addr, rd.srst, rd.en});
|
||||||
}
|
}
|
||||||
for (auto &wr : mem.wr_ports) {
|
for (auto &wr : mem.wr_ports) {
|
||||||
if (sigmap(wr.clk) != clk)
|
if (!clk || sigmap(wr.clk).as_bit() != *clk)
|
||||||
continue;
|
continue;
|
||||||
add_seq(wr.cell, {}, {wr.en, wr.addr, wr.data});
|
add_seq(wr.cell, {}, {wr.en, wr.addr, wr.data});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -767,7 +767,7 @@ struct FormalFfPass : public Pass {
|
||||||
ff.sig_d = ff.sig_ad;
|
ff.sig_d = ff.sig_ad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ff.has_clk || sigmap(ff.sig_clk) != gate_clock || ff.pol_clk != pol_clk) {
|
if (!ff.has_clk || sigmap(ff.sig_clk).as_bit() != gate_clock || ff.pol_clk != pol_clk) {
|
||||||
log_debug("FF driver for gate enable %s.%s of gated clk bit %s.%s has incompatible clocking: "
|
log_debug("FF driver for gate enable %s.%s of gated clk bit %s.%s has incompatible clocking: "
|
||||||
"%s %s.%s\n",
|
"%s %s.%s\n",
|
||||||
module, log_signal(SigSpec(gate_enable)), module,
|
module, log_signal(SigSpec(gate_enable)), module,
|
||||||
|
|
@ -798,7 +798,7 @@ struct FormalFfPass : public Pass {
|
||||||
auto &mem = memories.at(clocked_cell->name);
|
auto &mem = memories.at(clocked_cell->name);
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
for (auto &rd_port : mem.rd_ports) {
|
for (auto &rd_port : mem.rd_ports) {
|
||||||
if (rd_port.clk_enable && rd_port.clk == clk && rd_port.clk_polarity == pol_clk) {
|
if (rd_port.clk_enable && rd_port.clk.as_bit() == clk && rd_port.clk_polarity == pol_clk) {
|
||||||
log_debug("patching rd port\n");
|
log_debug("patching rd port\n");
|
||||||
changed = true;
|
changed = true;
|
||||||
rd_port.clk = gate_clock;
|
rd_port.clk = gate_clock;
|
||||||
|
|
@ -808,7 +808,7 @@ struct FormalFfPass : public Pass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto &wr_port : mem.wr_ports) {
|
for (auto &wr_port : mem.wr_ports) {
|
||||||
if (wr_port.clk_enable && wr_port.clk == clk && wr_port.clk_polarity == pol_clk) {
|
if (wr_port.clk_enable && wr_port.clk.as_bit() == clk && wr_port.clk_polarity == pol_clk) {
|
||||||
log_debug("patching wr port\n");
|
log_debug("patching wr port\n");
|
||||||
changed = true;
|
changed = true;
|
||||||
wr_port.clk = gate_clock;
|
wr_port.clk = gate_clock;
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,7 @@ class PyosysWrapperGenerator(object):
|
||||||
def make_preprocessor_options(self):
|
def make_preprocessor_options(self):
|
||||||
py_include = get_paths()["include"]
|
py_include = get_paths()["include"]
|
||||||
preprocessor_bin = shutil.which("clang++") or "g++"
|
preprocessor_bin = shutil.which("clang++") or "g++"
|
||||||
cxx_std = os.getenv("CXX_STD", "c++17")
|
cxx_std = os.getenv("CXX_STD", "c++20")
|
||||||
return ParserOptions(
|
return ParserOptions(
|
||||||
preprocessor=make_gcc_preprocessor(
|
preprocessor=make_gcc_preprocessor(
|
||||||
defines=["_YOSYS_", "YOSYS_ENABLE_PYTHON"],
|
defines=["_YOSYS_", "YOSYS_ENABLE_PYTHON"],
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ def yosys(script):
|
||||||
run([base_path / 'yosys', '-Q', '-p', script])
|
run([base_path / 'yosys', '-Q', '-p', script])
|
||||||
|
|
||||||
def compile_cpp(in_path, out_path, args):
|
def compile_cpp(in_path, out_path, args):
|
||||||
run(['g++', '-g', '-std=c++17'] + args + [str(in_path), '-o', str(out_path)])
|
run(['g++', '-g', '-std=c++20'] + args + [str(in_path), '-o', str(out_path)])
|
||||||
|
|
||||||
def yosys_synth(verilog_file, rtlil_file):
|
def yosys_synth(verilog_file, rtlil_file):
|
||||||
yosys(f"read_verilog {quote(verilog_file)} ; prep ; setundef -undriven -undef ; write_rtlil {quote(rtlil_file)}")
|
yosys(f"read_verilog {quote(verilog_file)} ; prep ; setundef -undriven -undef ; write_rtlil {quote(rtlil_file)}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue