@@ -2086,17 +2086,32 @@ struct EncodeOpLowering : public OpConversionPattern<sol::EncodeOp> {
20862086 if (op.getPacked ()) {
20872087 Value dataStart =
20882088 r.create <arith::AddIOp>(loc, freePtr, bExt.genI256Const (32 ));
2089- Value dataEnd = evmB.genABIPackedEncoding (
2090- op. getOperandTypes (), adaptor.getOperands (), dataStart);
2089+ Value dataEnd = evmB.genABIPackedEncoding (op. getIns (). getType (),
2090+ adaptor.getIns (), dataStart);
20912091 Value dataSize = r.create <arith::SubIOp>(loc, dataEnd, dataStart);
20922092 r.create <yul::MStoreOp>(loc, freePtr, dataSize);
20932093 Value allocationSize = r.create <arith::SubIOp>(loc, dataEnd, freePtr);
20942094 evmB.genFreePtrUpd (freePtr, allocationSize);
2095+ } else if (op.getSelector ()) {
2096+ assert (adaptor.getSelector () && " selector operand is required" );
2097+
2098+ Value selectorAddr =
2099+ r.create <arith::AddIOp>(loc, freePtr, bExt.genI256Const (32 ));
2100+ r.create <yul::MStoreOp>(loc, selectorAddr, adaptor.getSelector ());
2101+
2102+ Value tupleStart =
2103+ r.create <arith::AddIOp>(loc, selectorAddr, bExt.genI256Const (4 ));
2104+ Value tupleEnd = evmB.genABITupleEncoding (op.getIns ().getType (),
2105+ adaptor.getIns (), tupleStart);
2106+ Value dataSize = r.create <arith::SubIOp>(loc, tupleEnd, selectorAddr);
2107+ r.create <yul::MStoreOp>(loc, freePtr, dataSize);
2108+ Value allocationSize = r.create <arith::SubIOp>(loc, tupleEnd, freePtr);
2109+ evmB.genFreePtrUpd (freePtr, allocationSize);
20952110 } else {
20962111 Value tupleStart =
20972112 r.create <arith::AddIOp>(loc, freePtr, bExt.genI256Const (32 ));
2098- Value tupleEnd = evmB.genABITupleEncoding (
2099- op. getOperandTypes (), adaptor.getOperands (), tupleStart);
2113+ Value tupleEnd = evmB.genABITupleEncoding (op. getIns (). getType (),
2114+ adaptor.getIns (), tupleStart);
21002115 Value tupleSize = r.create <arith::SubIOp>(loc, tupleEnd, tupleStart);
21012116 r.create <yul::MStoreOp>(loc, freePtr, tupleSize);
21022117 Value allocationSize = r.create <arith::SubIOp>(loc, tupleEnd, freePtr);
0 commit comments