sol_codegen 0.1.0+1 copy "sol_codegen: ^0.1.0+1" to clipboard
sol_codegen: ^0.1.0+1 copied to clipboard

Lowers semantically-analysed Solidity AST to Yul IR for the sol_pkgs compiler.

sol_codegen #

Lowers semantically-analysed Solidity AST to Yul IR for the sol_pkgs compiler.

Corresponds to solc's IRGenerator and IRGeneratorForStatements subsystem.

What it produces #

For each contract, IRGenerator emits a two-level YulObject:

object "Adder" {
    code {
        // deployment code: copy runtime object to memory, return it
        codecopy(0, dataoffset("Adder_deployed"), datasize("Adder_deployed"))
        return(0, datasize("Adder_deployed"))
    }
    object "Adder_deployed" {
        code {
            // ABI dispatcher (switch on selector)
            switch shr(224, calldataload(0))
            case 0xdeadbeef { … }  // getSum selector
            revert(0, 0)

            // function implementations
            function fun_getSum(param_a, param_b) -> ret_0 {
                ret_0 := add(var_a, var_b)
                leave
            }
        }
    }
}

Usage #

import 'package:sol_codegen/sol_codegen.dart';
import 'package:sol_support/sol_support.dart';
import 'package:sol_yul/sol_yul.dart';

void compile(ContractDefinition contract) {
  final diagnostics = DiagnosticCollector();
  final yulObj = IRGenerator(diagnostics).generateContract(contract);

  // Print IR
  print(YulPrinter().print(yulObj));

  // Compile to bytecode
  final bytecode = YulCodeGenerator().generate(yulObj);
  print(bytecode.map((b) => b.toRadixString(16).padLeft(2, '0')).join());
}

Current status #

  • ✅ Deployment skeleton (codecopy + return)
  • ✅ ABI dispatcher (switch on selector)
  • ✅ Function definition lowering
  • return statement with leave
  • ✅ Binary arithmetic operators
  • ❌ Full ABI encoding/decoding
  • ❌ Storage read/write
  • ❌ Struct / array access
  • ❌ Events / errors

Dependencies #

  • sol_support — diagnostics
  • sol_ast — source AST nodes
  • sol_types — type information
  • sol_yul — Yul IR
0
likes
140
points
98
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Lowers semantically-analysed Solidity AST to Yul IR for the sol_pkgs compiler.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

sol_abi, sol_ast, sol_support, sol_types, sol_yul

More

Packages that depend on sol_codegen