2020-07-09 15:55:58 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Fluence Labs Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-07-09 06:21:04 +03:00
|
|
|
use super::IType;
|
2020-07-26 19:38:11 +03:00
|
|
|
use crate::instructions_generator::WITResolver;
|
|
|
|
use crate::Result;
|
|
|
|
|
2020-07-09 06:21:04 +03:00
|
|
|
use fluence_sdk_wit::ParsedType;
|
2020-07-11 23:04:55 +03:00
|
|
|
use fluence_sdk_wit::WasmType;
|
2020-07-09 06:21:04 +03:00
|
|
|
|
2020-07-26 19:38:11 +03:00
|
|
|
pub(crate) fn ptype_to_itype(pty: &ParsedType, wit_resolver: &WITResolver) -> Result<IType> {
|
2020-07-09 06:21:04 +03:00
|
|
|
match pty {
|
2020-07-26 19:38:11 +03:00
|
|
|
ParsedType::I8 => Ok(IType::S8),
|
|
|
|
ParsedType::I16 => Ok(IType::S16),
|
|
|
|
ParsedType::I32 => Ok(IType::S32),
|
|
|
|
ParsedType::I64 => Ok(IType::S64),
|
|
|
|
ParsedType::U8 => Ok(IType::U8),
|
|
|
|
ParsedType::U16 => Ok(IType::U16),
|
|
|
|
ParsedType::U32 => Ok(IType::U32),
|
|
|
|
ParsedType::U64 => Ok(IType::U64),
|
|
|
|
ParsedType::F32 => Ok(IType::F32),
|
|
|
|
ParsedType::F64 => Ok(IType::F64),
|
|
|
|
ParsedType::Boolean => Ok(IType::I32),
|
|
|
|
ParsedType::Utf8String => Ok(IType::String),
|
|
|
|
ParsedType::ByteVector => Ok(IType::ByteArray),
|
|
|
|
ParsedType::Record(record_name) => {
|
|
|
|
Ok(IType::Record(wit_resolver.get_record_type(record_name)?))
|
|
|
|
}
|
2020-07-09 06:21:04 +03:00
|
|
|
}
|
|
|
|
}
|
2020-07-11 23:04:55 +03:00
|
|
|
|
|
|
|
pub(crate) fn wtype_to_itype(pty: &WasmType) -> IType {
|
|
|
|
match pty {
|
|
|
|
WasmType::I32 => IType::I32,
|
|
|
|
WasmType::I64 => IType::I64,
|
|
|
|
WasmType::F32 => IType::F32,
|
|
|
|
WasmType::F64 => IType::F64,
|
|
|
|
}
|
|
|
|
}
|