Пример #1
0
    def _join_iclasses_to_groups(self, iarray, log_dir):
        '''           
            1. dividing the iclasses into groups.
            2. creating a mapping from iclass to its group Id.
            3. generating a log
            
            return: a list of ins_group_t objects '''

        groups = []
        #1. generate the groups
        for iclass, iforms in iarray.items():
            iforms.sort(cmp=cmp_iforms_by_bind_ptrn)
            self._put_iclass_in_group(groups, iclass, iforms)

        # 2. generate the iclass to group Id mapping
        self.iclass2group = {}
        for i, group in enumerate(groups):
            for iclass in group.get_iclasses():
                self.iclass2group[iclass] = i

        # 3. print the log
        if verbosity.vencode():
            log_file = os.path.join(log_dir, self.log_name)
            df = open(log_file, 'w')  #debug file
            df.write("number of iclasses: %d\n" % len(iarray))
            df.write("number of groups: %d\n" % len(groups))
            for i, group in enumerate(groups):
                df.write("GROUP Id: %d\n" % i)
                df.write("ICLASSES: %s\n" % str(group.get_iclasses()))
                for iform in group.iforms:
                    df.write("%s: %s\n" % ('BIND PATTERN: ', iform.bind_ptrn))
                df.write("\n\n")

            df.close()
        self.groups = groups
Пример #2
0
    def work(self):  # main entry point
        ''' 
            Each instruction has 
                1) conditions (iclass, user registers, user inputs) and 

                2) actions. 3 types:
                   2a) field bindings, 
                   2b) nonterminals, 
                   2c) bit-emit of operand fields 
                          (hard-coded or from NT output)).

              fos = function output object (plural)

            generate the following:
            1) list of emit patterns fos  (2c)
            2) list of field bindings patterns fos (2a)
            3) list of all field bindings values  (values from prev step)
            4) max number of emit patterns  
            5) max number of field binding patterns
            6) max number of field bindings values
            7) list of groups fos (see explanation in instructions_group_t)
            
        '''

        for iform in self.iform_list:
            self._identify_map_and_nominal_opcode(iform)
            self._make_field_bindings_pattern(iform)
            self._make_emit_pattern(iform)
            #see explanation about bind patterns in instructions_group_t
            self._make_bind_pattern(iform)

        #self._study_emit_patterns()
        #self._verify_naked_bits_in_unique_pattern()

        self.fb_values_list = self._make_fb_values_list()  # step 3
        self.fb_values_table_size = len(self.fb_values_list)

        self.emit_ptrs_fo_list = self._make_emit_pattern_fos()
        self.max_emit_ptrns = len(self.emit_ptrs_fo_list)
        if self.max_emit_ptrns > max_in_byte:
            # we are using uint8 to hold the number of patterns,
            # we need to make sure we don't exceeds
            error = "total number of emit patterns(%d) exceeds 8 bits"
            genutil.die(error % self.max_emit_ptrns)

        self.instruction_groups = instructions_group_t(self.iarray,
                                                       self.logs_dir)

        self.fb_ptrs_fo_list = self._make_fb_pattern_fos()
        self.max_fb_ptrns = len(self.fb_ptrs_fo_list)
        if self.max_fb_ptrns > max_in_byte:
            # we are using uint8to hold the number of patterns,
            # we need to make sure we don't exceeds
            error = "total number of field binding patterns(%d) exceeds 8 bits"
            genutil.die(error % self.max_fb_ptrns)

        if verbosity.vencode():
            self._print_log()