gigahorse-toolchain icon indicating copy to clipboard operation
gigahorse-toolchain copied to clipboard

How does loops work? How does Gigahorse translate loops?

Open lahiri-phdworks opened this issue 9 months ago • 3 comments

I am not able to understand the translation of a loop function to the IR generated by Gigahorse. I have a solidity function that looks like the example shown below.

Example:

pragma solidity >=0.4.2 <=0.7.6;

contract Loop {
    function loop_example (uint a, uint b) public view returns (uint) {
       require(a > 0, "parameter a passed to this function be greater than 0");
       uint c = 0;
       while (a > 0) {
           a = a - 1;
           c = c + b
       }
       return c;
    }
}
  • How does Gigahorse translate this function?
  • Is a, the loop variable, stored in the register or in memory using MSTORE/MLOAD constructs?

Any clarification in this direction will be really helpful.

lahiri-phdworks avatar May 23 '24 17:05 lahiri-phdworks