mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-26 04:07:57 +00:00
Fmt
This commit is contained in:
@@ -17,15 +17,18 @@ pub extern "C" fn solidity_license() -> *const c_char {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn solidity_version() -> *const c_char {
|
||||
let mut solc = SoljsonCompiler { version: None };
|
||||
let version = solc.version().map(|v| v.long).unwrap_or("unknown".to_owned());
|
||||
// Store the string in a static variable
|
||||
unsafe {
|
||||
let version = solc
|
||||
.version()
|
||||
.map(|v| v.long)
|
||||
.unwrap_or("unknown".to_owned());
|
||||
// Store the string in a static variable
|
||||
unsafe {
|
||||
if VERSION.is_none() {
|
||||
VERSION = Some(Box::new(CString::new(version).unwrap()));
|
||||
}
|
||||
|
||||
VERSION.as_ref().map_or_else(std::ptr::null, |s| s.as_ptr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -46,7 +49,15 @@ pub extern "C" fn solidity_free(data: *mut c_char) {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn solidity_compile(
|
||||
input: *const c_char,
|
||||
_readCallback: Option<extern "C" fn(*mut libc::c_void, *const c_char, *const c_char, *mut *mut c_char, *mut *mut c_char)>,
|
||||
_readCallback: Option<
|
||||
extern "C" fn(
|
||||
*mut libc::c_void,
|
||||
*const c_char,
|
||||
*const c_char,
|
||||
*mut *mut c_char,
|
||||
*mut *mut c_char,
|
||||
),
|
||||
>,
|
||||
_readContext: *mut libc::c_void,
|
||||
) -> *mut c_char {
|
||||
let input = unsafe { CStr::from_ptr(input).to_str().unwrap_or("") };
|
||||
@@ -58,5 +69,4 @@ pub extern "C" fn solidity_compile(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn solidity_reset() {
|
||||
}
|
||||
pub extern "C" fn solidity_reset() {}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl Process for NativeProcess {
|
||||
let mut stdin = std::io::stdin();
|
||||
let mut stdout = std::io::stdout();
|
||||
let mut stderr = std::io::stderr();
|
||||
|
||||
|
||||
let mut buffer = Vec::with_capacity(16384);
|
||||
match input_file {
|
||||
Some(ins) => {
|
||||
@@ -39,7 +39,7 @@ impl Process for NativeProcess {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
|
||||
let result = input.contract.compile(
|
||||
input.project,
|
||||
@@ -47,7 +47,7 @@ impl Process for NativeProcess {
|
||||
input.include_metadata_hash,
|
||||
input.debug_config,
|
||||
);
|
||||
|
||||
|
||||
match result {
|
||||
Ok(build) => {
|
||||
let output = Output::new(build);
|
||||
@@ -66,16 +66,16 @@ impl Process for NativeProcess {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Runs this process recursively to compile a single contract.
|
||||
fn call(input: Input) -> anyhow::Result<Output> {
|
||||
let input_json = serde_json::to_vec(&input).expect("Always valid");
|
||||
|
||||
|
||||
let executable = match EXECUTABLE.get() {
|
||||
Some(executable) => executable.to_owned(),
|
||||
None => std::env::current_exe()?,
|
||||
};
|
||||
|
||||
|
||||
let mut command = Command::new(executable.as_path());
|
||||
command.stdin(std::process::Stdio::piped());
|
||||
command.stdout(std::process::Stdio::piped());
|
||||
@@ -84,7 +84,7 @@ impl Process for NativeProcess {
|
||||
let process = command.spawn().map_err(|error| {
|
||||
anyhow::anyhow!("{:?} subprocess spawning error: {:?}", executable, error)
|
||||
})?;
|
||||
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
if let Some(dbg_config) = &input.debug_config {
|
||||
dbg_config
|
||||
@@ -97,13 +97,15 @@ impl Process for NativeProcess {
|
||||
)
|
||||
})?;
|
||||
}
|
||||
|
||||
|
||||
process
|
||||
.stdin
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("{:?} stdin getting error", executable))?
|
||||
.write_all(input_json.as_slice())
|
||||
.map_err(|error| anyhow::anyhow!("{:?} stdin writing error: {:?}", executable, error))?;
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!("{:?} stdin writing error: {:?}", executable, error)
|
||||
})?;
|
||||
let output = process.wait_with_output().map_err(|error| {
|
||||
anyhow::anyhow!("{:?} subprocess output error: {:?}", executable, error)
|
||||
})?;
|
||||
@@ -113,9 +115,9 @@ impl Process for NativeProcess {
|
||||
String::from_utf8_lossy(output.stderr.as_slice()).to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let output: Output =
|
||||
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
|
||||
|
||||
let output: Output = revive_common::deserialize_from_slice(output.stdout.as_slice())
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
"{:?} subprocess output parsing error: {}",
|
||||
executable,
|
||||
|
||||
@@ -42,8 +42,8 @@ impl SolcCompiler {
|
||||
}
|
||||
|
||||
impl Compiler for SolcCompiler {
|
||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
||||
fn standard_json(
|
||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
||||
fn standard_json(
|
||||
&mut self,
|
||||
mut input: StandardJsonInput,
|
||||
pipeline: Pipeline,
|
||||
|
||||
@@ -12,11 +12,11 @@ use crate::compiler::solc::SolcCompiler;
|
||||
use crate::compiler::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
use crate::compiler::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||
use crate::compiler::standard_json::input::Input as SolcStandardJsonInput;
|
||||
use crate::compiler::standard_json::output::contract::evm::bytecode::Bytecode;
|
||||
use crate::compiler::standard_json::output::contract::evm::bytecode::DeployedBytecode;
|
||||
use crate::compiler::standard_json::output::Output as SolcStandardJsonOutput;
|
||||
use crate::compiler::Compiler;
|
||||
use crate::project::Project;
|
||||
use crate::compiler::standard_json::output::contract::evm::bytecode::Bytecode;
|
||||
use crate::warning::Warning;
|
||||
|
||||
static PVM_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Default::default);
|
||||
@@ -214,8 +214,11 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> {
|
||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||
let optimizer_settings = revive_llvm_context::OptimizerSettings::none();
|
||||
|
||||
let project =
|
||||
Project::try_from_yul_string::<SolcCompiler>(PathBuf::from("test.yul").as_path(), source_code, None)?;
|
||||
let project = Project::try_from_yul_string::<SolcCompiler>(
|
||||
PathBuf::from("test.yul").as_path(),
|
||||
source_code,
|
||||
None,
|
||||
)?;
|
||||
let _build = project.compile(optimizer_settings, false, None)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user