Skip to content

Commit

Permalink
Merge 1cefa13 into 406702a
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed May 3, 2024
2 parents 406702a + 1cefa13 commit 520aae7
Show file tree
Hide file tree
Showing 53 changed files with 2,430 additions and 1,642 deletions.
15 changes: 12 additions & 3 deletions sway-ast/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::fmt;
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub enum Intrinsic {
IsReferenceType,
IsStrArray,
SizeOfType,
SizeOfVal,
SizeOfStr,
IsStrArray,
AssertIsStrArray,
ToStrArray,
Eq,
Expand Down Expand Up @@ -36,8 +36,11 @@ pub enum Intrinsic {
Smo,
Not,
JmpMem,
ContractCall, // __contract_call(params, coins, asset_id, gas)
ContractRet, // __contract_ret(ptr, len)
ContractCall, // __contract_call(params, coins, asset_id, gas)
ContractRet, // __contract_ret(ptr, len)
EncodeBufferEmpty, // let buffer: (raw_ptr, u64, u64) = __encode_buffer_empty()
EncodeBufferAppend, // let buffer: (raw_ptr, u64, u64) = __encode_buffer_append(buffer, primitive data type)
EncodeBufferAsRawSlice, // let slice: raw_slice = __encode_buffer_as_raw_slice(buffer)
}

impl fmt::Display for Intrinsic {
Expand Down Expand Up @@ -79,6 +82,9 @@ impl fmt::Display for Intrinsic {
Intrinsic::JmpMem => "jmp_mem",
Intrinsic::ContractCall => "contract_call",
Intrinsic::ContractRet => "contract_ret",
Intrinsic::EncodeBufferEmpty => "encode_buffer_empty",
Intrinsic::EncodeBufferAppend => "encode_buffer_append",
Intrinsic::EncodeBufferAsRawSlice => "encode_buffer_as_raw_slice",
};
write!(f, "{s}")
}
Expand Down Expand Up @@ -124,6 +130,9 @@ impl Intrinsic {
"__jmp_mem" => JmpMem,
"__contract_call" => ContractCall,
"__contract_ret" => ContractRet,
"__encode_buffer_empty" => EncodeBufferEmpty,
"__encode_buffer_append" => EncodeBufferAppend,
"__encode_buffer_as_raw_slice" => EncodeBufferAsRawSlice,
_ => return None,
})
}
Expand Down
37 changes: 36 additions & 1 deletion sway-core/src/asm_generation/fuel/data_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum Datum {
Byte(u8),
Word(u64),
ByteArray(Vec<u8>),
Slice(Vec<u8>),
Collection(Vec<Entry>),
}

Expand Down Expand Up @@ -54,6 +55,19 @@ impl Entry {
}
}

pub(crate) fn new_slice(
bytes: Vec<u8>,
name: Option<String>,
padding: Option<Padding>,
) -> Entry {
dbg!(&name, &bytes);
Entry {
padding: padding.unwrap_or(Padding::default_for_byte_array(&bytes)),
value: Datum::Slice(bytes),
name,
}
}

pub(crate) fn new_collection(
elements: Vec<Entry>,
name: Option<String>,
Expand Down Expand Up @@ -124,9 +138,10 @@ impl Entry {
name,
padding,
),
ConstantValue::RawUntypedSlice(bytes) => Entry::new_slice(bytes.clone(), name, padding),
ConstantValue::Reference(_) => {
todo!("Constant references are currently not supported.")
} // TODO-IG: Implement.
}
}
}

Expand All @@ -143,6 +158,13 @@ impl Entry {
.copied()
.take((bs.len() + 7) & 0xfffffff8_usize)
.collect(),
Datum::Slice(bs) if bs.len() % 8 == 0 => bs.clone(),
Datum::Slice(bs) => bs
.iter()
.chain([0; 8].iter())
.copied()
.take((bs.len() + 7) & 0xfffffff8_usize)
.collect(),
Datum::Collection(els) => els.iter().flat_map(|el| el.to_bytes()).collect(),
};

Expand Down Expand Up @@ -309,6 +331,19 @@ impl fmt::Display for DataSection {
}
format!(".bytes[{}] {hex_str} {chr_str}", bs.len())
}
Datum::Slice(bs) => {
let mut hex_str = String::new();
let mut chr_str = String::new();
for b in bs {
hex_str.push_str(format!("{b:02x} ").as_str());
chr_str.push(if *b == b' ' || b.is_ascii_graphic() {
*b as char
} else {
'.'
});
}
format!(".slice[{}] {hex_str} {chr_str}", bs.len())
}
Datum::Collection(els) => format!(
".collection {{ {} }}",
els.iter()
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/asm_generation/fuel/fuel_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
stored_val: &Value,
) -> Result<(), CompileError> {
let owning_span = self.md_mgr.val_to_span(self.context, *instr_val);

if stored_val
.get_type(self.context)
.map_or(true, |ty| !self.is_copy_type(&ty))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ impl<'ir, 'eng> MidenVMAsmBuilder<'ir, 'eng> {
Array(_) => todo!(),
Struct(_) => todo!(),
Reference(_) => todo!(),
RawUntypedSlice(_) => todo!(),
}
}
}
Expand Down

0 comments on commit 520aae7

Please sign in to comment.