Beispiel #1
0
    def update(self):
        self.check_MPATH_exist()

        if self.arguments["<args>"] != [] and "recursive" not in self.arguments["<args>"]: # TODO: recursive or all?
            err("Wrong command option: " + str(self.arguments["<args>"]))
            info("Usage: module MPATH update [recursive]")
            exit(0)
Beispiel #2
0
    def on_remove(self):
        '''|
        | Command 'remove' removes an interface from the .json file and updates the HW module design files
        |________'''
        interface_name = self.arguments[0]

        gdf = MFDesign()
        gdf.initialize(self.full_name)

        found = self.check_name(gdf, interface_name)

        if not found:
            err("Name not found: " + interface_name)
            exit(0)

        # Remove Interface
        gdf.interfaces[:] = [
            value for value in gdf.interfaces
            if value["name"] != interface_name
        ]
        # Remove Parameter
        gdf.parameters[:] = [
            value for value in gdf.parameters
            if value["name"] != interface_name
        ]

        gdf.overwrite = True
        print_json_file(gdf)

        gdf.update(self.full_name)
Beispiel #3
0
 def remove(self):
     self.check_MPATH_exist()
     
     if len(self.arguments["<args>"]) != 1:
         err("Wrong command format")
         info("Usage: module MPATH remove NAME")
         exit(0)
Beispiel #4
0
    def on_add(self):
        '''|
        | Command 'add' adds an interface to the .json file and updates the HW module design files
        |________'''
        interface_type = self.arguments[0]
        
        gdf = MFDesign()
        gdf.initialize( self.full_name )

        found = self.check_name( gdf, self.opt_Name )

        if found:
            err("Can not add - interface with the same name exists: " + self.opt_Name)
            exit(0)

        if interface_type == 'HSD':
            gdf.interfaces.append({'push': self.opt_Push, 'direction': self.opt_Direction, 'data': self.opt_Data, 'type': interface_type, 'name': self.opt_Name})

        elif interface_type == 'Bus':
            gdf.interfaces.append({'interfaces': self.opt_BusType, 'type': interface_type, 'name': self.opt_Name})

        elif interface_type == 'Parameter':
            gdf.parameters.append({'value': self.opt_ParValue, 'name': self.opt_Name})

        elif interface_type == 'STAvln':
            gdf.interfaces.append({'direction': self.opt_Direction, 'width': self.opt_Data, 'type': interface_type, 'name': self.opt_Name})

        else: # this should not happen
            err("Unknown type: " + interface_type)
            exit(0)
            
        gdf.overwrite = True
        print_json_file( gdf )

        gdf.update( self.full_name )
Beispiel #5
0
    def remove(self):
        self.check_MPATH_exist()

        if len(self.arguments["<args>"]) != 1:
            err("Wrong command format")
            info("Usage: module MPATH remove NAME")
            exit(0)
Beispiel #6
0
    def update(self):
        self.check_MPATH_exist()

        if self.arguments["<args>"] != [] and "recursive" not in self.arguments[
                "<args>"]:  # TODO: recursive or all?
            err("Wrong command option: " + str(self.arguments["<args>"]))
            info("Usage: module MPATH update [recursive]")
            exit(0)
Beispiel #7
0
    def convert(self):
        self.check_MPATH_exist()

        if len(self.arguments["<args>"]) > 1  or  \
               self.arguments["<args>"] != [] and \
                    (("verilog" not in self.arguments["<args>"]) and ("vhdl" not in self.arguments["<args>"])):
                   
            err("Wrong command option: " + str(self.arguments["<args>"]))
            info("Usage: module MPATH convert [verilog | vhdl]")
            exit(0)
Beispiel #8
0
 def usage_add(self):
     err("Wrong command format")
     info(
         "Usage: module MPATH add <interface_type> -n <name> -d <direction> -w <width/fields> [-p <push>]"
     )
     info(
         "Usage: module MPATH add Bus              -n <name> -i <bus_type>")
     info(
         "       module MPATH add Parameter        -n <name> -v <value>...")
     exit(0)
Beispiel #9
0
    def convert(self):
        self.check_MPATH_exist()

        if len(self.arguments["<args>"]) > 1  or  \
               self.arguments["<args>"] != [] and \
                    (("verilog" not in self.arguments["<args>"]) and ("vhdl" not in self.arguments["<args>"])):

            err("Wrong command option: " + str(self.arguments["<args>"]))
            info("Usage: module MPATH convert [verilog | vhdl]")
            exit(0)
Beispiel #10
0
    def on_add(self):
        '''|
        | Command 'add' adds an interface to the .json file and updates the HW module design files
        |________'''
        interface_type = self.arguments[0]

        gdf = MFDesign()
        gdf.initialize(self.full_name)

        found = self.check_name(gdf, self.opt_Name)

        if found:
            err("Can not add - interface with the same name exists: " +
                self.opt_Name)
            exit(0)

        if interface_type == 'HSD':
            gdf.interfaces.append({
                'push': self.opt_Push,
                'direction': self.opt_Direction,
                'data': self.opt_Data,
                'type': interface_type,
                'name': self.opt_Name
            })

        elif interface_type == 'Bus':
            gdf.interfaces.append({
                'interfaces': self.opt_BusType,
                'type': interface_type,
                'name': self.opt_Name
            })

        elif interface_type == 'Parameter':
            gdf.parameters.append({
                'value': self.opt_ParValue,
                'name': self.opt_Name
            })

        elif interface_type == 'STAvln':
            gdf.interfaces.append({
                'direction': self.opt_Direction,
                'width': self.opt_Data,
                'type': interface_type,
                'name': self.opt_Name
            })

        else:  # this should not happen
            err("Unknown type: " + interface_type)
            exit(0)

        gdf.overwrite = True
        print_json_file(gdf)

        gdf.update(self.full_name)
Beispiel #11
0
    def add(self):
        self.check_MPATH_exist()
        if self.arguments["<args>"] == []:
            err("Missing Interface type")
            exit(0)

        if len(self.arguments["<args>"]) != 1:
            err("More arguments given.")
            self.usage_add()

        if self.arguments["-n"] == "None":
            err("Missing name.")
            self.usage_add()

        interface_type = self.arguments["<args>"][0]

        if interface_type == 'HSD':
            self.check_arguments(self.arguments["-d"], self.arguments["-w"])

        elif interface_type == 'Bus':
            self.check_arguments(self.arguments["-i"])

        elif interface_type == 'Parameter':
            self.check_arguments(self.arguments["-v"])

        elif interface_type == 'STAvln':
            self.check_arguments(self.arguments["-d"], self.arguments["-w"])

        else:
            err("Unknown type: " + interface_type)
            exit(0)
Beispiel #12
0
    def add(self):
        self.check_MPATH_exist()
        if self.arguments["<args>"] == []:
            err("Missing Interface type")
            exit(0)

        if len(self.arguments["<args>"]) != 1:
            err("More arguments given.")
            self.usage_add()

        if self.arguments["-n"] == "None":
            err("Missing name.")
            self.usage_add()

        interface_type = self.arguments["<args>"][0]

        if interface_type == 'HSD':
            self.check_arguments(self.arguments["-d"], self.arguments["-w"])

        elif interface_type == 'Bus':
            self.check_arguments(self.arguments["-i"])

        elif interface_type == 'Parameter':
            self.check_arguments(self.arguments["-v"])

        elif interface_type == 'STAvln':
            self.check_arguments(self.arguments["-d"], self.arguments["-w"])

        else:
            err("Unknown type: " + interface_type)
            exit(0)
Beispiel #13
0
 def on_update(self):
     '''|
     | Command update re-generates the files, which are created with command new.
     | This command is useful when, e.g., HW module's interfaces or structure changes.
     | First, the corresponding .json file is modified capturing the changes.
     |________'''
     recursive = "recursive" in self.arguments
     
     if recursive == True:
         files = [os.path.join(root, file) for root, dirs, files in os.walk(self.module_path) for file in files if file.endswith('.json')]
         for file_name in files:
             gdf = MFDesign()
             gdf.update( file_name )
     else:
         if os.path.exists( self.full_name ):
             gdf = MFDesign()
             gdf.update( self.full_name )
         else:
             err("File not found: " + self.file_name)
             info("Did you mean: 'update recursive'?")
Beispiel #14
0
    def check_path_and_create_json(self, file_name):
        '''|
        | Checks if the new module directory and the corresponding .json file exists in the provided path.
        | If not, this function creates the directory and a default .json file (containing only Reset and Clock interfaces).
        | In this way, a new module design (directory structure and files) can always be initialized correctly.
        |________'''
        dirname, filename = os.path.split(file_name)

        if not os.path.exists(dirname):
            info("Target module path does not exist. Creating a directory...")
            os.makedirs(dirname)

        if not os.listdir(dirname):  # empty directory
            info(
                "Target module .json file does not exist. Creating a default file..."
            )

        if len(os.listdir(dirname)) > 1:
            err("The target module directory is not empty. Use command 'delete' before you start again. Aborting..."
                )
            exit(0)

        # Create a default .json file
        if not os.path.isfile(file_name):
            s = StrBuilder()
            s.indent()
            s += '{\n'
            s += s.indent() + '"design":\n'
            s += '{\n'
            s += s.indent() + '"name": "' + filename[:-5] + '",\n'
            s += '"interfaces":\n'
            s += '[\n'
            s.indent()
            s += '{ "name": "rst", "type": "Reset", "active": "1" },\n'
            s += '{ "name": "clk", "type": "Clock" }\n'
            s += s.dedent() + ']\n'
            s += s.dedent() + '}\n'
            s += s.dedent() + '}\n'

            s.write(file_name)
Beispiel #15
0
    def check_path_and_create_json(self, file_name):
        '''|
        | Checks if the new module directory and the corresponding .json file exists in the provided path.
        | If not, this function creates the directory and a default .json file (containing only Reset and Clock interfaces).
        | In this way, a new module design (directory structure and files) can always be initialized correctly.
        |________'''
        dirname, filename = os.path.split(file_name)

        if not os.path.exists( dirname ):
            info("Target module path does not exist. Creating a directory...")
            os.makedirs( dirname )

        if not os.listdir( dirname ): # empty directory
            info("Target module .json file does not exist. Creating a default file...")

        if len(os.listdir( dirname )) > 1:
            err("The target module directory is not empty. Use command 'delete' before you start again. Aborting...")
            exit(0)

        # Create a default .json file
        if not os.path.isfile( file_name ):
            s = StrBuilder()
            s.indent()
            s += '{\n'
            s += s.indent() + '"design":\n'
            s += '{\n'
            s += s.indent() + '"name": "' + filename[:-5] + '",\n'
            s += '"interfaces":\n'
            s += '[\n'
            s.indent()
            s += '{ "name": "rst", "type": "Reset", "active": "1" },\n'
            s += '{ "name": "clk", "type": "Clock" }\n'
            s += s.dedent() + ']\n'
            s += s.dedent() + '}\n'
            s += s.dedent() + '}\n'

            s.write( file_name )
Beispiel #16
0
    def on_remove(self):
        '''|
        | Command 'remove' removes an interface from the .json file and updates the HW module design files
        |________'''
        interface_name = self.arguments[0]

        gdf = MFDesign()
        gdf.initialize( self.full_name )

        found = self.check_name( gdf, interface_name )

        if not found:
            err("Name not found: " + interface_name)
            exit(0)

        # Remove Interface
        gdf.interfaces[:] = [value for value in gdf.interfaces if value["name"] != interface_name]
        # Remove Parameter
        gdf.parameters[:] = [value for value in gdf.parameters if value["name"] != interface_name]

        gdf.overwrite = True
        print_json_file( gdf )

        gdf.update( self.full_name )
Beispiel #17
0
    def on_update(self):
        '''|
        | Command update re-generates the files, which are created with command new.
        | This command is useful when, e.g., HW module's interfaces or structure changes.
        | First, the corresponding .json file is modified capturing the changes.
        |________'''
        recursive = "recursive" in self.arguments

        if recursive == True:
            files = [
                os.path.join(root, file)
                for root, dirs, files in os.walk(self.module_path)
                for file in files if file.endswith('.json')
            ]
            for file_name in files:
                gdf = MFDesign()
                gdf.update(file_name)
        else:
            if os.path.exists(self.full_name):
                gdf = MFDesign()
                gdf.update(self.full_name)
            else:
                err("File not found: " + self.file_name)
                info("Did you mean: 'update recursive'?")
Beispiel #18
0
 def validate_command_syntax(self):
     if self.arguments["<command>"] not in self.check:
         err("Unknown command: " + self.arguments["<command>"])
         # An additional check
         self.check_MPATH_exist()
         exit(0)
Beispiel #19
0
 def check_MPATH_exist(self):
     if not self.module_path_exist:
         err("Module path does not exist")
         exit(0)
Beispiel #20
0
 def validate_command_syntax(self):
     if self.arguments["<command>"] not in self.check:
         err("Unknown command: " + self.arguments["<command>"])
         # An additional check
         self.check_MPATH_exist()
         exit(0)
Beispiel #21
0
 def new(self):
     if not self.module_path:
         err("Missing module path")
         info("Usage: module MPATH new")
         exit(0)
Beispiel #22
0
 def usage_add(self):
     err("Wrong command format")
     info("Usage: module MPATH add <interface_type> -n <name> -d <direction> -w <width/fields> [-p <push>]")
     info("Usage: module MPATH add Bus              -n <name> -i <bus_type>")
     info("       module MPATH add Parameter        -n <name> -v <value>...")
     exit(0)
Beispiel #23
0
 def check_MPATH_exist(self):
     if not self.module_path_exist:
         err("Module path does not exist")
         exit(0)
Beispiel #24
0
 def new(self):
     if not self.module_path:
         err("Missing module path")
         info("Usage: module MPATH new")
         exit(0)