예제 #1
0
    def exitExplicitIOBlock(self, ctx: lfrXParser.ExplicitIOBlockContext):
        #  First check the type of the explicit io block
        decltype = ctx.start.text
        mode = None
        if decltype == 'finput':
            mode = IOType.FLOW_INPUT
        elif decltype == 'foutput':
            mode = IOType.FLOW_OUTPUT
        elif decltype == 'control':
            mode = IOType.CONTROL

        for declvar in ctx.declvar():
            startindex = 0
            endindex = 0

            if declvar.vector() is not None:
                # Parse all the info regarding the vector
                # print("Parsing Vector:", declvar.vector().getText())
                startindex = int(declvar.vector().start.text)
                endindex = int(declvar.vector().end.text)

            name = declvar.ID().getText()
            # Check if the vector has been created
            if name in self.vectors:
                # Retrieve the vector to change the subitems
                vec = self.vectors[name]

                # First check if the size is the same or not, if not give an error
                if len(vec) is not (abs(startindex - endindex) + 1):
                    self.compilingErrors.append(
                        LFRError(
                            ErrorType.VECTOR_SIZE_MISMATCH,
                            "explicit i/o:{0} definition not same size as module definition"
                            .format(name)))

                # Go through each of the ios and modify the type
                for io in vec.get_items():
                    io.type = mode
            else:
                if self.EXPLICIT_MODULE_DECLARATION is True:
                    # This is the scenario where all the declaration is done explicitly
                    vec = self.__createVector(name, IONode, startindex,
                                              endindex)
                    self.vectors[name] = vec
                    self.typeMap[name] = VariableTypes.FLUID

                    # Go through each of the ios and modify the type
                    for io in vec.get_items():
                        io.type = mode

                    # Create and add a ModuleIO reference
                    m = ModuleIO(name, mode)
                    m.vector_ref = vec.get_range()
                    self.currentModule.add_io(m)

                else:
                    self.compilingErrors.append(
                        LFRError(
                            ErrorType.MODULE_IO_NOT_FOUND,
                            "i/o:{0} not declared in module".format(name)))
예제 #2
0
    def exitSensitivitylist(self, ctx: lfrXParser.SensitivitylistContext):
        sentivity_list = []

        # TODO - Go through the signals and then add then to the sentivity list
        for signal in ctx.signal():
            start_index = 0
            end_index = 0
            signal_name = signal.ID().getText()

            if signal_name not in self.vectors.keys():
                self.compilingErrors.append(
                    LFRError(ErrorType.SIGNAL_NOT_FOUND,
                             "Cannot find signal - {}".format(signal_name)))
                continue

            v = self.vectors[signal_name]

            if signal.vector() is not None:
                start_index = int(ctx.vector().start.text)
                end_index = int(ctx.vector().end.text)
            else:
                start_index = v.startindex
                end_index = v.endindex

            vrange = VectorRange(v, start_index, end_index)
            sentivity_list.append(vrange)

        self._current_dist_block.sensitivity_list = sentivity_list
예제 #3
0
    def exitConcatenation(self, ctx: lfrXParser.ConcatenationContext):
        if ctx.vectorvar() is not None:
            item_in_concatenation = len(ctx.vectorvar())
        else:
            # TODO - Check if this is right ?
            item_in_concatenation = 1
        # slice the items out of the stack
        stackslice = self.stack[-(item_in_concatenation):]
        del self.stack[-(item_in_concatenation):]

        c = Concatenation(stackslice)

        # TODO: Here the selector will determine the start and endindex for the vector
        # range
        startindex = 0
        endindex = len(c) - 1
        if ctx.vector() is not None:
            self.compilingErrors.append(
                LFRError(
                    ErrorType.COMPILER_NOT_IMPLEMENTED,
                    "Selecting range from compiler has not been implemented, ignoring range for concatenation on line {0} column{1}"
                    .format(ctx.start.getLine(),
                            ctx.start.getCharPositionInLine()),
                ))

        v = c.get_range(startindex, endindex)
        self.stack.append(v)
예제 #4
0
    def exitExplicitinstanceiomapping(
            self, ctx: lfrXParser.ExplicitinstanceiomappingContext):
        variable = self.stack.pop()
        label = ctx.ID().getText()

        # Check if label exists in module_to_import
        if label not in self._module_to_import.get_all_io():
            self.compilingErrors.append(
                LFRError(
                    ErrorType.MODULE_IO_NOT_FOUND,
                    "Could not find io `{}` in module `{}`".format(
                        label, self._module_to_import.name)))
            return

        io = self._module_to_import.get_io(label)
        assert (len(io.vector_ref) == len(variable))
        for i in range(len(variable)):
            self._io_mapping[io.vector_ref[i].id] = variable[i].id
예제 #5
0
    def enterModuleinstantiationstat(
            self, ctx: lfrXParser.ModuleinstantiationstatContext):
        # Check if the type exists in current compiler memory
        type_id = ctx.moduletype().getText()
        module_to_import = None
        for module_to_check in self.modules:
            if module_to_check.name == type_id:
                module_to_import = module_to_check
        if module_to_import is None:
            self.compilingErrors.append(
                LFRError(ErrorType.MODULE_NOT_FOUND,
                         "Could find type {}".format(type_id)))
            return
        self._io_mapping = dict()
        self.currentModule.add_new_import(module_to_import)

        # Save the reference in the class
        self._module_to_import = module_to_import