Giter VIP home page Giter VIP logo

Comments (5)

AnthonyVH avatar AnthonyVH commented on September 27, 2024

The code below does the trick. Implementing it without C++11 (i.e. without expression SFINAE) will require some extra code (see e.g. https://stackoverflow.com/questions/257288).

// These changes go in frontend/SystemC.hpp, starting at line 47.
// For C++98 compatibility and e.g. QuestaSim, Boost needs to be used instead of C++11 std.
namespace detail {
  template <class T> struct is_randv_type : std::false_type { };
  template <class T> struct is_randv_type<::crave::randv<T>> : std::true_type { };
} // ns detail

#define RANDV_SCDT_BINARY_OPERATOR(Typename, BinOp)                           \
  template <int N, typename T>                                                \
  sc_dt::int64 operator BinOp(randv<Typename<N> > const& r, T const& i) {     \
    return static_cast<Typename<N>>(r) BinOp i;                               \
  }                                                                           \
  template <int N, typename T,                                                \
    typename std::enable_if<!detail::is_randv_type<T>::value, int>::type = 0> \
  auto operator BinOp(T const & i, randv<Typename<N>> const & r)              \
      -> decltype(i BinOp static_cast<Typename<N>>(r), sc_dt::int64()) {      \
    return i BinOp static_cast<Typename<N>>(r);                               \
  }

The general idea is to prevent operator BinOp (T const &, Typename<N> const &) from being instantiated for any T which is itself a crave::randv<U>, because in that case the same function is already defined as operator BinOp (randv<Typename<N>> const &, V const &). The expression SFINAE is required to prevent the function being instantiated if the BinOp operation doesn't exist for the given types.

Note that I kept the return type as sc_dt::int64. Ideally I would use e.g. decltype(i BinOp static_cast<Typename<N>>(r)) to auto deduce what it should be, but I'm not quite sure how that would be implemented pre-C++11 (something along the lines of std::result_of I guess).

Also note that I replaced the C-style casts with C++ ones.

from crave.

hoangmle avatar hoangmle commented on September 27, 2024

LGTM, thanks! Can you create a PR which also includes the example from your first comment as an unittest? The unittest should be in tests/core/test_SystemC_Data.cpp. We already have crave::is_crave_variable<T> in src/crave/frontend/bitsize_traits.hpp which you can use instead of is_randv_type<T>. A C++11 compiler is now required to build CRAVE, so please feel free to use C++11 stuffs as much as you can.

from crave.

AnthonyVH avatar AnthonyVH commented on September 27, 2024

Sure, I'll put something together.

BTW, when you say "use C++11 stuffs as much as you can", you mean the language extensions, right? Because as far as I know the C++11 additions to the STL aren't even supported by the latest QuestaSim versions (e.g. 10.5b, which still uses GCC 4.7.4). Or is there some extra trick I'm unaware of to make those work as well?

from crave.

hoangmle avatar hoangmle commented on September 27, 2024

I actually meant full C++11 support as we do not explicitly try to be compatible with any particular EDA simulator. It has been a while since the last time we compiled CRAVE with QuestaSim, does it still work out of the box?

from crave.

AnthonyVH avatar AnthonyVH commented on September 27, 2024

Honestly, I haven't tried yet. I'll try to give it a go soon. I've never been able to get any C++11 STL additions to compile in QuestaSim 10.5b/10.6 though.

Edit: Just noticed that GCC 5.3.0 is bundled with QuestaSim 10.6 and newer. Maybe that'll do it.

from crave.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.