rsmmr/hilti

[BinPAC++] Type of 'deref' in bytes iterator

FrozenCaribou opened this issue · 0 comments

Hello,
I think there is an issue to store in a variable the value pointed by an iter<bytes>.

import BinPAC;

global b : bytes = b"Hello";
global it : iter<bytes>;
global v : bytes;

it = b.begin();
print *it;
v = *it;

Raise the following error :

>>> v = assign __tmp_elem
<no location>:: error, operand not compatible with target [pass::hilti::Validator]

If we look at the hilti generated code:

void __entry()
{
  local iterator<bytes> __tmp_iter
  local int<8> &hostapp_type=(37) __tmp_elem
  local int<8> &hostapp_type=(37) __tmp_elem_2


    # Statement: it  = b .begin()
    __tmp_iter = begin b
    it = assign __tmp_iter
    # Statement: v  = *it
    __tmp_elem = deref it
   = assign __tmp_elem
    # Statement: print *it ;
    __tmp_elem_2 = deref it
    call BinPACHilti::print (__tmp_elem_2)
    block.end
}

[...]

global iterator<bytes> it
global ref<bytes> v

In fact deref i returns an int<8> for iter<bytes> however v is a ref<bytes>.
It seems it is not possible in BinPAC++ to save the value in a int<8> because the type does not match with the type of the iterator (bytes)

A solution could be to change the return type of iterator::Deref operator in the binpac compiler and use int<8> only for bytes ?