From 1460c9b5748c7cb7779cb79b2d3de792106be1f2 Mon Sep 17 00:00:00 2001 From: Marcel Keller Date: Tue, 24 May 2022 15:54:56 +0200 Subject: [PATCH] Fix output issue. --- Compiler/types.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Compiler/types.py b/Compiler/types.py index 03fe7eb45..1d06f3f71 100644 --- a/Compiler/types.py +++ b/Compiler/types.py @@ -5189,10 +5189,10 @@ def delete(self): self.value_type.free(self.address) self.address = None - def get_address(self, index): + def get_address(self, index, size=None): if isinstance(index, (_secret, _single)): raise CompilerError('need cleartext index') - key = str(index) + key = str(index), size or 1 if self.length is not None: from .GC.types import cbits if isinstance(index, int): @@ -5211,6 +5211,8 @@ def get_address(self, index): # length can be None for single-element arrays length = 0 base = self.address + index * self.value_type.mem_size() + if size is not None and isinstance(base, _register): + base = regint._expand_address(base, size) self.address_cache[program.curr_block, key] = \ util.untuplify([base + i * length \ for i in range(n)]) @@ -5332,7 +5334,8 @@ def assign(self, other, base=0): except: pass try: - self.value_type.conv(other).store_in_mem(self.get_address(base)) + other = self.value_type.conv(other) + other.store_in_mem(self.get_address(base, other.size)) if len(self) != None and util.is_constant(base): assert len(self) >= other.size + base except (AttributeError, CompilerError): @@ -5370,7 +5373,7 @@ def get_vector(self, base=0, size=None): :param base: starting point (regint/cint/int) :param size: length (compile-time int) """ size = size or self.length - base - return self.value_type.load_mem(self.get_address(base), size=size) + return self.value_type.load_mem(self.get_address(base, size), size=size) get_part_vector = get_vector @@ -5581,6 +5584,9 @@ def Array(self, size): # compatibility with registers return Array(size, self.value_type) + def output_if(self, cond): + library.print_str_if(cond, '%s', self.get_vector()) + def __str__(self): return '%s array of length %s at %s' % (self.value_type, len(self), self.address)