Skip to content
New issue

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

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

Already on GitHub? # to your account

Constant Folding #45

Open
Tracked by #43
ControlCplusControlV opened this issue Dec 17, 2022 · 1 comment
Open
Tracked by #43

Constant Folding #45

ControlCplusControlV opened this issue Dec 17, 2022 · 1 comment
Assignees

Comments

@ControlCplusControlV
Copy link
Owner

No description provided.

@ControlCplusControlV
Copy link
Owner Author

Constant Folding

Evaluate all expressions which can be evaluated at compile time

    c := add(100, 15)
    a := add(c, 50)
    b := add(b, 10)

Should compiled down to a block which just PUSH's the result of 175 onto the stack.

Test Cases

  1. Input Yul
{
    let c:u32 := add(100, 15)
    let a:u32 := sub(c, 50)
    let b:u32 := mul(a, 10)
    let d:u32 := div(b, 2)
}
  1. Assembly Output
use.std::math::u256
 
begin
    # Assigning to d #
        # u32 literal 425 #
        push.425
end
  1. Input Yul
{
    let c := add(100, 15)
    let a := sub(c, 50)
    let b := mul(a, 10)
    let d := div(b, 2)
}
  1. Assembly Output
use.std::math::u256
 
 
begin
    # Assigning to d #
        # u256 literal: 425 #
        push.425        push.0          push.0          push.0          push.0          push.0          push.0          push.0         

end

@ControlCplusControlV ControlCplusControlV self-assigned this Jan 21, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant