Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sway-core/src/asm_generation/fuel/data_section.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use rustc_hash::FxHashMap;
use sway_ir::{size_bytes_round_up_to_word_alignment, Constant, ConstantValue, Context, Padding};
use sway_ir::{
size_bytes_round_up_to_word_alignment, ConstantContent, ConstantValue, Context, Padding,
};

use std::{fmt, iter::repeat};

Expand Down Expand Up @@ -89,7 +91,7 @@ impl Entry {

pub(crate) fn from_constant(
context: &Context,
constant: &Constant,
constant: &ConstantContent,
name: EntryName,
padding: Option<Padding>,
) -> Entry {
Expand Down
15 changes: 10 additions & 5 deletions sway-core/src/asm_generation/fuel/fuel_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl AsmBuilder for FuelAsmBuilder<'_, '_> {
ConfigContent::V0 { name, constant, .. } => {
let entry = Entry::from_constant(
self.context,
constant,
constant.get_content(self.context),
EntryName::Configurable(name.clone()),
None,
);
Expand Down Expand Up @@ -1130,7 +1130,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
idx_val
.get_constant(self.context)
.and_then(|idx_const| {
if let ConstantValue::Uint(idx) = idx_const.value {
if let ConstantValue::Uint(idx) = idx_const.get_content(self.context).value {
Some(idx as usize)
} else {
None
Expand Down Expand Up @@ -2072,7 +2072,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
config_name: Option<String>,
span: Option<Span>,
) -> (VirtualRegister, Option<DataId>) {
match &constant.value {
match &constant.get_content(self.context).value {
// Use cheaper $zero or $one registers if possible.
ConstantValue::Unit | ConstantValue::Bool(false) | ConstantValue::Uint(0)
if config_name.is_none() =>
Expand All @@ -2091,7 +2091,12 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
} else {
EntryName::NonConfigurable
};
let entry = Entry::from_constant(self.context, constant, config_name, None);
let entry = Entry::from_constant(
self.context,
constant.get_content(self.context),
config_name,
None,
);
let data_id = self.data_section.insert_data_value(entry);

// Allocate a register for it, and a load instruction.
Expand Down Expand Up @@ -2137,7 +2142,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
.or_else(|| {
value.get_constant(self.context).map(|constant| {
let span = self.md_mgr.val_to_span(self.context, *value);
match constant.value {
match constant.get_content(self.context).value {
// If it's a small enough constant, just initialize using an IMM value.
// (exceptions for zero and one as they have special registers).
ConstantValue::Uint(c)
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/asm_generation/fuel/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ impl FuelAsmBuilder<'_, '_> {
ptr.is_mutable(self.context),
ptr.get_initializer(self.context),
) {
match constant.value {
match constant.get_content(self.context).value {
ConstantValue::Uint(c) if c <= compiler_constants::EIGHTEEN_BITS => {
self.ptr_map.insert(
*ptr,
Expand All @@ -848,7 +848,7 @@ impl FuelAsmBuilder<'_, '_> {
let data_id =
self.data_section.insert_data_value(Entry::from_constant(
self.context,
constant,
constant.get_content(self.context),
EntryName::NonConfigurable,
None,
));
Expand All @@ -863,7 +863,7 @@ impl FuelAsmBuilder<'_, '_> {
let var_size = ptr_ty.size(self.context);

if let Some(constant) = ptr.get_initializer(self.context) {
match constant.value {
match constant.get_content(self.context).value {
ConstantValue::Uint(c) if c <= compiler_constants::EIGHTEEN_BITS => {
let imm = VirtualImmediate18::new_unchecked(
c,
Expand All @@ -879,7 +879,7 @@ impl FuelAsmBuilder<'_, '_> {
let data_id =
self.data_section.insert_data_value(Entry::from_constant(
self.context,
constant,
constant.get_content(self.context),
EntryName::NonConfigurable,
None,
));
Expand Down
7 changes: 4 additions & 3 deletions sway-core/src/ir_generation/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub(crate) fn compile_configurables(
let opt_metadata = md_mgr.span_to_md(context, &decl.span);

if context.experimental.new_encoding {
let mut encoded_bytes = match constant.value {
let mut encoded_bytes = match constant.get_content(context).value.clone() {
ConstantValue::RawUntypedSlice(bytes) => bytes,
_ => unreachable!(),
};
Expand Down Expand Up @@ -651,11 +651,12 @@ fn compile_fn(
// Special case: sometimes the returned value at the end of the function block is hacked
// together and is invalid. This can happen with diverging control flow or with implicit
// returns. We can double check here and make sure the return value type is correct.
let undef = Constant::unique(context, ConstantContent::get_undef(ret_type));
ret_val = match ret_val.get_type(context) {
Some(ret_val_type) if ret_type.eq(context, &ret_val_type) => ret_val,

// Mismatched or unavailable type. Set ret_val to a correctly typed Undef.
_otherwise => Value::new_constant(context, Constant::get_undef(ret_type)),
_otherwise => Value::new_constant(context, undef),
};

// Another special case: if the last expression in a function is a return then we don't want to
Expand All @@ -676,7 +677,7 @@ fn compile_fn(
|| compiler.current_block.num_predecessors(context) > 0)
{
if ret_type.is_unit(context) {
ret_val = Constant::get_unit(context);
ret_val = ConstantContent::get_unit(context);
}
compiler
.current_block
Expand Down
Loading
Loading