rsmmr / hilti

**NOTE**: This is outdated and no longer maintained. There's a new version at https://github.com/zeek/spicy.
Other
40 stars 22 forks source link

imported types : hooks not executed #14

Open FrozenCaribou opened 8 years ago

FrozenCaribou commented 8 years ago

I tried to import "parses/asn1.pac" but it did not work. It seems that hooks (like "on %done") of imported types are not executed.

Here a simple test :

test.pac2

module Test;

import BinPAC;
import p;

export type T = unit(){

  d : ABC::A;

  on %done{
    print self.d;
  }
};

p.pac2

module ABC;

import BinPAC;

type A = unit(){
  var c : uint<8> = 3;
  var a : bytes;
  b : uint<8> {self.c = 4;}

  on %done{
    self.a = b"TEST";
    print "AAA";
  }
};
echo "A" | pac-driver test.pac2
<c=3, b=65>

We notice that "c" is not modified and "a" is not defined.

rsmmr commented 8 years ago

Yeah, that does look like a bug. There's are some tests for making sure things work across imports, but this may not be covered. Thanks for reporting.

FrozenCaribou commented 8 years ago

Hello,

In fact it exists an unit test https://github.com/rsmmr/hilti/blob/master/tests/binpac/unit/external-hooks-import.pac2 that tests hooks of imported types. However this test gives the both modules in parameters to pac-driver.

If we take the previous case, hooks are well executed if we run:

echo "A" | pac-driver test.pac2 p.pac2
AAA
<c=4, a=b"TEST", b=65>

I do not know if it is the behaviour excepted but it could be interesting to not have to specify all files included because we still give the "pac2 include paths" with -I argument. It is useful if we use a pac2 files library with many pac2 modules.

I tried to correct that by compiling all (recursives) dependencies of a pac2 module and link them into a final llvm module. I implemented a dependencies method that returns all pac2 file path dependencies of a binpac context.

https://github.com/FrozenCaribou/hilti/tree/fix_pac2_import The branch fixes binpac++ and pac-driver.