intel / rohd

The Rapid Open Hardware Development (ROHD) framework is a framework for describing and verifying hardware in the Dart programming language.
https://intel.github.io/rohd-website
BSD 3-Clause "New" or "Revised" License
370 stars 65 forks source link

Refactored tick() in simulator.dart #475

Closed AdamRose66 closed 5 months ago

AdamRose66 commented 5 months ago

Description & Motivation

Refactored tick() method in simulator.dart.

The high level motivation is to move towards a common scheduler shared by the Rohd and Rohm simulators. This is preparatory refactoring with that in mind.

Concretely, I have added a method for each phase.

The tick method now looks like this:

  static Future<void> tick() async {
    if (_injectedActions.isNotEmpty) {
      _pendingTimestamps.putIfAbsent( _currentTimestamp , () => ListQueue() );
    }

    // the main event loop
    if (_updateTimeStamp()) {
      _preTick();
      await _mainTick();
      _clkStable();
      await _outOfTick();
    }
  }

The justification is as follows:

       // case 1 : ( the usual Rohd case )
       //   The previous delta cycle did NOT do 'registerAction( _currentTimeStamp );'.
       //   In that case, _pendingTimestamps[_currentTimestamp] is currently
       //   null, so putIfAbsent will add a new empty list, which will trigger
       //   a new delta cycle.
       // case 2 :
       //   The previous delta cycle DID do 'registerAction( _currentTimestamp );'.
       //   In that case, there is *already* another tick scheduled for
       //   _currentTimestamp, and the injected actions will get called in
       //   the normal way.
       ...
      // Either way, the end result is that a whole new tick gets scheduled for
      // _currentTimestamp and any outstanding injected actions get executed.

Testing

All Rohme and Rohd tests pass using this code.

Backwards-compatibility

The user facing API has not changed and tool integrations should be unaffected.

Documentation

Documentation is inline ( including for the new private methods ).

AdamRose66 commented 5 months ago

Checks now pass but build dev tools fails, not sure why or what to do about that.

AdamRose66 commented 5 months ago

Yes I think the lint is saying that, but I also read somewhere that while you can do that with an ordinary function you can’t do it with a constructor.I have to admit I didn’t do the experiment, and I just used the ignore statement. On 3 Apr 2024, at 18:06, Max Korbel @.***> wrote: @mkorbel1 commented on this pull request.

In lib/src/simulator.dart:

   // Either way, the end result is that a whole new tick gets scheduled for

// _currentTimestamp and any outstanding injected actions get executed. +

  • // ignore: unnecessary_lambdas

I think this lint is saying you could have done ListQueue.new instead of () => ListQueue(), which seems fair but not a big deal. Better to avoid the lint rather than waive, since it's probably a better way

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>