Skip to content

Out-of-box CXXSim fails on MacOS #495

@BracketMaster

Description

@BracketMaster

The user needs to install and put Homebrew's clang on the path
for CXXSim to work out of the box on MacOS, otherwise, the following
simple example fails.

"""
Simple counter in nMigen.
Write simulations results to a
vcd file.
"""
from nmigen import Signal, Elaboratable, Module
from nmigen.sim import Simulator

class Top(Elaboratable):
    def __init__(self):
        self.counter = Signal(range(10))

    def elaborate(self, platform):
        m = Module()
        m.d.sync += self.counter.eq(self.counter + 1)

        return m

if __name__ == '__main__':
    def process():
        for tick in range(10):
            print(f"counter = {(yield dut.counter)}")
            yield
    
    dut = Top()
    sim = Simulator(dut,engine='cxxsim')
    sim.add_clock(1e-6)
    sim.add_sync_process(process)

    with sim.write_vcd(f"{__file__[:-3]}.vcd"):
        sim.run()
$python3 counter.py 
In file included from sim.cc:1:
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:75:15: warning: 
      alias declarations are a C++11 extension [-Wc++11-extensions]
        using type = T;
                     ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:76:9: error: 
      unknown type name 'constexpr'
        static constexpr size_t bits = std::numeric_limits<T>::digits;
               ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:76:25: error: 
      expected ';' at end of declaration list
        static constexpr size_t bits = std::numeric_limits<T>::digits;
                               ^
                               ;
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:77:9: error: 
      unknown type name 'constexpr'
        static constexpr T mask = std::numeric_limits<T>::max();
               ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:77:20: error: 
      expected ';' at end of declaration list
        static constexpr T mask = std::numeric_limits<T>::max();
                          ^
                          ;
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:84:46: error: 
      expected expression
struct value : public expr_base<value<Bits>> {
                                             ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:506:2: error: 
      expected a type
};
 ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:506:2: error: 
      expected '{' after base class list
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:510:66: error: 
      expected expression
struct slice_expr : public expr_base<slice_expr<T, Stop, Start>> {
                                                                 ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:540:2: error: 
      expected a type
};
 ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:540:2: error: 
      expected '{' after base class list
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:544:55: error: 
      a space is required between consecutive right angle brackets (use '> >')
struct concat_expr : public expr_base<concat_expr<T, U>> {
                                                      ^~
                                                      > >
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:545:9: error: 
      unknown type name 'constexpr'; did you mean 'concat_expr'?
        static constexpr size_t bits = T::bits + U::bits;
               ^~~~~~~~~
               concat_expr
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:544:8: note: 
      'concat_expr' declared here
struct concat_expr : public expr_base<concat_expr<T, U>> {
       ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:545:25: error: 
      expected ';' at end of declaration list
        static constexpr size_t bits = T::bits + U::bits;
                               ^
                               ;
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:551:43: warning: 
      deleted function definitions are a C++11 extension [-Wc++11-extensions]
        concat_expr(const concat_expr<T, U> &) = delete;
                                                 ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:554:17: error: 
      use of undeclared identifier 'bits'
        operator value<bits>() const {
                       ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:594:31: warning: 
      default template arguments for a function template are a C++11 extension
      [-Wc++11-extensions]
        template<size_t Stop, size_t Start = Stop>
                                     ^       ~~~~
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:600:31: warning: 
      default template arguments for a function template are a C++11 extension
      [-Wc++11-extensions]
        template<size_t Stop, size_t Start = Stop>
                                     ^       ~~~~
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:614:67: warning: 
      rvalue references are a C++11 extension [-Wc++11-extensions]
        concat_expr<T, typename std::remove_reference<U>::type> concat(U &&other) {
                                                                         ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:597:10: warning: 
      generalized initializer lists are a C++11 extension [-Wc++11-extensions]
                return {*static_cast<const T *>(this)};
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:603:10: warning: 
      generalized initializer lists are a C++11 extension [-Wc++11-extensions]
                return {*static_cast<T *>(this)};
                       ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:609:10: warning: 
      generalized initializer lists are a C++11 extension [-Wc++11-extensions]
                return {*static_cast<const T *>(this), other};
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:615:10: warning: 
      generalized initializer lists are a C++11 extension [-Wc++11-extensions]
                return {*static_cast<T *>(this), other};
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:621:2: warning: 
      'auto' type specifier is a C++11 extension [-Wc++11-extensions]
        auto old_flags = os.flags(std::ios::right);
        ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:622:2: warning: 
      'auto' type specifier is a C++11 extension [-Wc++11-extensions]
        auto old_width = os.width(0);
        ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:623:2: warning: 
      'auto' type specifier is a C++11 extension [-Wc++11-extensions]
        auto old_fill  = os.fill('0');
        ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:640:9: error: 
      unknown type name 'constexpr'
        static constexpr size_t bits = Bits;
               ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:640:25: error: 
      expected ';' at end of declaration list
        static constexpr size_t bits = Bits;
                               ^
                               ;
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:645:11: warning: 
      defaulted function definitions are a C++11 extension [-Wc++11-extensions]
        wire() = default;
                 ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:646:2: error: 
      unknown type name 'constexpr'
        constexpr wire(const value<Bits> &init) : curr(init), next(init) {}
        ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:646:12: error: 
      constructor cannot have a return type
        constexpr wire(const value<Bits> &init) : curr(init), next(init) {}
                  ^~~~
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:647:19: warning: 
      variadic templates are a C++11 extension [-Wc++11-extensions]
        template<typename... Init>
                         ^
/usr/local/Cellar/yosys/HEAD-87b9ee3_2/share/yosys/include/backends/cxxrtl/cxxrtl.h:648:11: error: 
      unknown type name 'constexpr'
        explicit constexpr wire(Init ...init) : curr{init...}, next{init...} {}
                 ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
14 warnings and 20 errors generated.
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/unixccompiler.py", line 117, in _compile
    self.spawn(compiler_so + cc_args + [src, '-o', obj] +
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/spawn.py", line 157, in _spawn_posix
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command 'cc' failed with exit status 1

During handling of the above exception, another exception occurred:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions