pub fn solc_yul(source: &str, return_optimized_yul: bool) -> Result<(Vec<u8>, Option<String>)> {
    let mut prog = Command::new(&solc_path()?);
    prog.arg("--optimize").arg("--strict-assembly").arg("--bin");
    if return_optimized_yul {
        prog.arg("--ir-optimized");
    }
    let mut child = prog
        .arg("-")
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()?;
    let pipe = child.stdin.as_mut().ok_or(anyhow!("cannot create pipe"))?;
    pipe.write_all(source.as_bytes())?;
    let out = child.wait_with_output()?;
    if !out.status.success() {
        return Err(anyhow!(String::from_utf8_lossy(&out.stderr).to_string()));
    }
    let out_str = String::from_utf8_lossy(&out.stdout).to_string();
    let start_of_yul = out_str.find(OPTIMIZED_YUL_MARKER);
    let start_of_hex = out_str.find(HEX_OUTPUT_MARKER);
    if return_optimized_yul && start_of_yul.is_none() || start_of_hex.is_none() {
        return Err(anyhow!(
            "Internal error: unexpected output of solc during Yul compilation"
        ));
    }
    let yul = if return_optimized_yul {
        Some(
            (&out_str[(start_of_yul.unwrap() + OPTIMIZED_YUL_MARKER.len())..start_of_hex.unwrap()])
                .trim()
                .to_string(),
        )
    } else {
        None
    };
    let bin = hex::decode(&out_str[(start_of_hex.unwrap() + HEX_OUTPUT_MARKER.len())..].trim())?;
    Ok((bin, yul))
}
/// Compile the Yul source, given as a string, and return the binary representation of the
/// compiled bytecode. If `return_optimized_yul` is true, also return the textual representation
/// of optimized Yul.
Compile the Yul source, given as a string, and return the binary representation of the
compiled bytecode. If `return_optimized_yul` is true, also return the textual representation
of optimized Yul.
Compile the Yul source given as a string and return the binary representation of the compiled bytecode . If ` return_optimized_yul ` is true also return the textual representation of optimized Yul .
pub fn solc_yul(source: &str, return_optimized_yul: bool) -> Result<(Vec<u8>, Option<String>)> {
    let mut prog = Command::new(&solc_path()?);
    prog.arg("--optimize").arg("--strict-assembly").arg("--bin");
    if return_optimized_yul {
        prog.arg("--ir-optimized");
    }
    let mut child = prog
        .arg("-")
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()?;
    let pipe = child.stdin.as_mut().ok_or(anyhow!("cannot create pipe"))?;
    pipe.write_all(source.as_bytes())?;
    let out = child.wait_with_output()?;
    if !out.status.success() {
        return Err(anyhow!(String::from_utf8_lossy(&out.stderr).to_string()));
    }
    let out_str = String::from_utf8_lossy(&out.stdout).to_string();
    let start_of_yul = out_str.find(OPTIMIZED_YUL_MARKER);
    let start_of_hex = out_str.find(HEX_OUTPUT_MARKER);
    if return_optimized_yul && start_of_yul.is_none() || start_of_hex.is_none() {
        return Err(anyhow!(
            "Internal error: unexpected output of solc during Yul compilation"
        ));
    }
    let yul = if return_optimized_yul {
        Some(
            (&out_str[(start_of_yul.unwrap() + OPTIMIZED_YUL_MARKER.len())..start_of_hex.unwrap()])
                .trim()
                .to_string(),
        )
    } else {
        None
    };
    let bin = hex::decode(&out_str[(start_of_hex.unwrap() + HEX_OUTPUT_MARKER.len())..].trim())?;
    Ok((bin, yul))
}
pub fn solc_yul ( source : & str , return_optimized_yul : bool ) -> Result < ( Vec < u8 > , Option < String > ) > { let mut prog = Command :: new ( & solc_path ( ) ? ) ; prog . arg ( " " ) . arg ( " " ) . arg ( " " ) ; if return_optimized_yul { prog . arg ( " " ) ; } let mut child = prog . arg ( " " ) . stdin ( Stdio :: piped ( ) ) . stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: piped ( ) ) . spawn ( ) ? ; let pipe = child . stdin . as_mut ( ) . ok_or ( anyhow ! ( " " ) ) ? ; pipe . write_all ( source . as_bytes ( ) ) ? ; let out = child . wait_with_output ( ) ? ; if ! out . status . success ( ) { return Err ( anyhow ! ( String from_utf8_lossy ( out stderr ) to_string ( ) ) ) ; } let out_str = String :: from_utf8_lossy ( & out . stdout ) . to_string ( ) ; let start_of_yul = out_str . find ( OPTIMIZED_YUL_MARKER ) ; let start_of_hex = out_str . find ( HEX_OUTPUT_MARKER ) ; if return_optimized_yul && start_of_yul . is_none ( ) || start_of_hex . is_none ( ) { return Err ( anyhow ! ( " " ) ) ; } let yul = if return_optimized_yul { Some ( ( & out_str [ ( start_of_yul . unwrap ( ) + OPTIMIZED_YUL_MARKER . len ( ) ) .. start_of_hex . unwrap ( ) ] ) . trim ( ) . to_string ( ) , ) } else { None } ; let bin = hex :: decode ( & out_str [ ( start_of_hex . unwrap ( ) + HEX_OUTPUT_MARKER . len ( ) ) .. ] . trim ( ) ) ? ; Ok ( ( bin , yul ) ) }
Compile the Yul source, given as a string, and return the binary representation of the
compiled bytecode.
Compile the Yul source given as a string and return the binary representation of the compiled bytecode .
source
&str
return_optimized_yul
bool