Esempio n. 1
0
    def test_invalid_comparison(self):
        statestruct = hls_types_pb2.HLSStructType()

        int_type = hls_types_pb2.HLSIntType()
        int_type.signed = True
        int_type.width = 18

        translated_hls_type = hls_types_pb2.HLSType()
        translated_hls_type.as_int.CopyFrom(int_type)

        statestructtype = hls_types_pb2.HLSType()
        statestructtype.as_struct.CopyFrom(statestruct)
        hls_types_by_name = {"State": statestructtype}

        source = """
      enum states{State_TX=1};
      int test(){
        int ret = 0;
        State state;
        if (state == State_TX){
            return State_TX;
        }
        return ret;
      }
      """
        with self.assertRaisesRegex(ValueError, "Invalid operand at"):
            self.parse_and_get_function(source, hls_types_by_name)
Esempio n. 2
0
    def test_structref(self):
        somestruct = hls_types_pb2.HLSStructType()

        int_type = hls_types_pb2.HLSIntType()
        int_type.signed = True
        int_type.width = 18

        translated_hls_type = hls_types_pb2.HLSType()
        translated_hls_type.as_int.CopyFrom(int_type)

        hls_field = hls_types_pb2.HLSNamedType()
        hls_field.name = "x"
        hls_field.hls_type.CopyFrom(translated_hls_type)
        somestruct.fields.add().CopyFrom(hls_field)

        hls_field = hls_types_pb2.HLSNamedType()
        hls_field.name = "y"
        hls_field.hls_type.CopyFrom(translated_hls_type)
        somestruct.fields.add().CopyFrom(hls_field)

        somestructtype = hls_types_pb2.HLSType()
        somestructtype.as_struct.CopyFrom(somestruct)
        hls_types_by_name = {"SomeStruct": somestructtype}

        f = self.parse_and_get_function(
            """
      void struct_update(SomeStruct &o, sai18 x) {
        o.x.set_slc(0, x);
      }
      int test(sai32 a, int b) {
        SomeStruct s;
        s.x = 0;
        s.y = b;
        struct_update(s, a);
        return s.x + s.y;
      }
    """, hls_types_by_name)
        aval = ir_value.Value(bits_mod.SBits(value=int(22), bit_count=32))
        bval = ir_value.Value(bits_mod.SBits(value=int(10), bit_count=32))
        args = dict(a=aval, b=bval)
        result = ir_interpreter.run_function_kwargs(f, args)
        result_int = int(ctypes.c_int32(int(str(result))).value)
        self.assertEqual(32, result_int)