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

How to compile multiple yul files? #46

Open
q871795224 opened this issue Nov 9, 2020 · 2 comments
Open

How to compile multiple yul files? #46

q871795224 opened this issue Nov 9, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@q871795224
Copy link

After I use solidity to yul function of solc, sometimes solc will compile the contract file into multiple yul files. So how do I use soll to compile it into a wasm file?
For example:

library SafeMath {
    function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
        require(b <= a);
        c = a - b;
    }
}
contract Abt {
    using SafeMath for uint256;
    mapping (address => uint256) public etherBalance;
    uint256 feeETH = 0;
    uint256 totalEthFee = 0;
    constructor() {
        feeETH = 1500000000000000;
    }
    function deposit() payable public {
        totalEthFee = totalEthFee.sub(feeETH);
        //etherBalance[msg.sender] = etherBalance[msg.sender].add(msg.value);
    }
    function balanceOfETH(address user) public returns (uint256) {
     return etherBalance[user];
    }
}

After "solc -o ./ --ir ./Abt.sol", multiple files will appear.

Abt.yul
SafeMath.yul

So how to compile multiple yul files?

@hydai hydai added the enhancement New feature or request label Nov 9, 2020
@hydai
Copy link
Member

hydai commented Nov 9, 2020

Hi @q871795224 ,

SOLL has not yet supported multiple yul files.
I am afraid that you may need to compose it into a single file and then send to SOLL.

For example, here is a workaround for you.

contract Abt {
    mapping (address => uint256) public etherBalance;
    uint256 feeETH = 0;
    uint256 totalEthFee = 0;
    constructor() {
        feeETH = 1500000000000000;
    }
    function deposit() payable public {
        totalEthFee = sub(totalEthFee, feeETH);
        //etherBalance[msg.sender] = etherBalance[msg.sender].add(msg.value);
    }
    function balanceOfETH(address user) public returns (uint256) {
     return etherBalance[user];
    }
    function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
        require(b <= a);
        c = a - b;
    }
}

And we also found a lack of yul opcode invalid. Because the output yul from the above sol contains invalid(), you may get this error /tmp/sol/Abt.yul:277:17: error: Use of undeclared identifier 'invalid'. I created a new issue to track this error, see #47

@q871795224
Copy link
Author

It helps a lot, thanks you!

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

No branches or pull requests

2 participants