Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BigInt / Int to Bool conversion (0.B, 1.B) #913

Merged
merged 3 commits into from
Nov 2, 2018
Merged

Conversation

ducky64
Copy link
Contributor

@ducky64 ducky64 commented Oct 26, 2018

I think there are cases where it's cleaner to use 0.B and 1.B instead of false.B and true.B, especially as testers is going to use chisel literals.

(the use case is in testing interface code, where signal levels are usually specified as 0 and 1 instead of false and true)

Type of change: other enhancement

Impact: API addition (no impact on existing code)

Development Phase: proposal, implementation

Release Notes

@ducky64 ducky64 requested a review from a team as a code owner October 26, 2018 07:58
@edwardcwang
Copy link
Contributor

Doesn't this mean 2.B will be a runtime error as opposed to a compile-time error?

@ducky64
Copy link
Contributor Author

ducky64 commented Oct 26, 2018

Yeah. It would be nice if there was a way to make that type-safe, but there's a trade-off between syntax and error type in this implementation. We can discuss at the meeting today.

Macros might be able to detect something like 2.B at compile time, though I don't think it's possible to do that in general with variables (though I also can't think of when you would want to do an Int-to-Bool conversion on a variable).

@aswaterman
Copy link
Member

No objections here. I don’t think it’s especially problematic that 2.B is a runtime error.

@seldridge
Copy link
Member

retest this please

Copy link
Contributor

@chick chick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me.

Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except I think it could use a better error message

/** Int to Bool conversion, allowing compact syntax like 1.B and 0.B
*/
def B: Bool = {
require(bigint == 0 || bigint == 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would provide an explicit message so that people who try 3.B get something more than requirement failed

@ducky64 ducky64 merged commit 1910f70 into master Nov 2, 2018
@ducky64 ducky64 deleted the fromIntoToBool branch November 2, 2018 00:06
@ucbjrl ucbjrl added this to the 3.2.0 milestone Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants