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

Enum reset x #771

Merged
merged 7 commits into from
Jun 13, 2024
Merged

Enum reset x #771

merged 7 commits into from
Jun 13, 2024

Conversation

nblei
Copy link
Contributor

@nblei nblei commented Jun 10, 2024

Allows EnumMembers with 'x' or 'z' values to be Factors in assignment operations inside if_reset blocks.

Previously,

module top (
    i_clk: input clock,
    i_rst: input reset,
) {

    enum State: logic<3> {
        Idle = 3'bxx1,
        Run0 = 3'b000,
        Run1 = 3'b010,
        Run2 = 3'b100,
        Done = 3'b110,
    }

    var state: State;

    always_ff {
        if_reset {
            state = State::Idle;
        }
    }

}

would result in an error because of the don't care bits in State::Idle.

@nblei
Copy link
Contributor Author

nblei commented Jun 10, 2024

@dalance

One thing that is strange about this is that EnumItems are not evaluated. When are symbols supposed to be evaluated?

@dalance
Copy link
Collaborator

dalance commented Jun 11, 2024

Evaluation is executed at symbol table resolve.

symbol.evaluate();

But it may be unnecessary. I think calling symbol.found.evaluate() is sufficient when it is necessary.
If the symbol is already evalated, it returns the cached evaluated, and if not, it evaluates at the call time.

Therefore, the code of evaluator.rs can be simplified like below:

// from
if let Some(evaluated) = symbol.found.evaluated.get() {
    evaluated
} else {
    symbol.found.evaluate()
}

// to
symbol.found.evaluate()

@taichi-ishitani
Copy link
Contributor

For SystemVerilog, there is the limitation below for unassigned enum labels following the enum label with x/z value.

From IEEE 1800-2023 6.19.2 Enumerated type ranges
image

I think you need to check if this limitation is satisfied.

@dalance
Copy link
Collaborator

dalance commented Jun 12, 2024

@nblei
I think this PR can be merged.
Is it ok with you?

@taichi-ishitani
I think this change is about evaluating enum value,
and your suggestion seems to be about requirement of additional check for enum declaration.
So could you create a new issue for it?

@taichi-ishitani
Copy link
Contributor

@taichi-ishitani I think this change is about evaluating enum value, and your suggestion seems to be about requirement of additional check for enum declaration. So could you create a new issue for it?

Sure, I will create a new ticket.

@nblei
Copy link
Contributor Author

nblei commented Jun 12, 2024

@nblei I think this PR can be merged. Is it ok with you?

Yes.

@dalance dalance merged commit 1c8bb4c into veryl-lang:master Jun 13, 2024
6 checks passed
@dalance dalance added the enhancement New feature or request label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants