<commit_before>module OrigenTesters
  module SmartestBasedTester
    module SMT8
      # An internal method called by Origen to create the pattern header
      def pattern_header(options = {})
        options = {
        }.merge(options)
        @program_lines = []
        @program_action_lines = []
        @program_lines << '<?xml version="1.0" encoding="UTF-8"?>'
        @program_lines << '<Program xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Program.xsd">'
        @program_lines << '  <Assignment id="memory" value="SM"/>'
        pin_list = ordered_pins.map do |p|
          if Origen.app.pin_pattern_order.include?(p.id)
            # specified name overrides pin name
            if (p.is_a?(Origen::Pins::PinCollection)) || p.id != p.name
              p.id.to_s # groups or aliases can be lower case
            else
              p.id.to_s.upcase # pins must be uppercase
            end
          else
            if (p.is_a?(Origen::Pins::PinCollection)) || p.id != p.name
              p.name.to_s # groups or aliases can be lower case
            else
              p.name.to_s.upcase # pins must be uppercase
            end
          end
        end.join(',')
        @program_lines << "  <Instrument id=\"#{pin_list}\">"
      end

      # An internal method called by Origen to generate the pattern footer
      def pattern_footer(options = {})
        options = {
          end_in_ka:      false
        }.merge(options)
        if options[:end_in_ka]
          Origen.log.warning '93K keep alive not yet implemented!'
          ss 'WARNING: 93K keep alive not yet implemented!'
        end
        @program_footer_lines = []
        @program_footer_lines << '</Program>'
      end

      # @api private
      def open_and_write_pattern(filename)
        pat_name = Pathname.new(filename).basename.to_s
        tmp_dir = filename.gsub('.', '_')
        FileUtils.mkdir_p(tmp_dir)
        program_file = File.join(tmp_dir, 'Program.sprg')
        vector_file = File.join(tmp_dir, 'Vectors.vec')
        comments_file = File.join(tmp_dir, 'Comments.cmt')

        @gen_vec = 0
        @vector_number = 0
        @vector_lines = []
        @comment_lines = []
        # @program_lines was already created with the pattern_header

        yield

        write_gen_vec

        @program_lines << '  </Instrument>'

        File.open(program_file, 'w') do |f|
          (@program_lines + @program_action_lines + @program_footer_lines).each do |line|
            f.puts line
          end
        end

        File.open(vector_file, 'w') { |f| @vector_lines.each { |l| f.puts l } }
        File.open(comments_file, 'w') { |f| @comment_lines.each { |l| f.puts l } }

        Dir.chdir tmp_dir do
          `zip #{pat_name} Program.sprg Vectors.vec Comments.cmt`
          FileUtils.mv pat_name, filename
        end
      ensure
        FileUtils.rm_rf(tmp_dir) if File.exist?(tmp_dir)
      end

      # @api private
      #
      # The SMT8 microcode is implemented as a post conversion of the SMT7 microcode, rather than
      # generating SMT8 microcode originally.
      # This is generally an easier implementation and since they both run on the same h/ware there
      # should always be a 1:1 feature mapping between the 2 systems.
      def track_and_format_comment(comment)
        if comment =~ /^SQPG/
          write_gen_vec
          if comment =~ /^SQPG JSUB ([^;]+);/
            @program_lines << "    <Instruction id=\"patternCall\" value=\"#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG MACT (\d+);/
            @program_lines << "    <Instruction id=\"match\" value=\"#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG MRPT (\d+);/
            @program_lines << "    <Instruction id=\"matchRepeat\" value=\"#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG LBGN (\d+);/
            @program_lines << "    <Instruction id=\"loop\" value=\"#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG LEND;/
            @program_lines << "    <Instruction id=\"loopEnd\"/>"
          elsif comment =~ /^SQPG RETC (\d) (\d);/
            @program_lines << "    <Instruction id=\"returnConditional\">"
            @program_lines << "      <Assignment id=\"onFail\" value=\"#{Regexp.last_match(1) == '0' ? 'false' : 'true'}\"/>"
            @program_lines << "      <Assignment id=\"resetFail\" value=\"#{Regexp.last_match(2) == '0' ? 'false' : 'true'}\"/>"
            @program_lines << '    </Instruction>'
          elsif comment =~ /^SQPG PADDING/
            # TODO: Is this required in SMT8?
          else
            Origen.log.warning "This SMT7 microcode was not converted to SMT8: #{comment}"
          end
        end
      end

      # This is an internal method use by Origen which returns a fully formatted vector<commit_msg>Add path to patterns directory when making subroutine calls<commit_after>module OrigenTesters
  module SmartestBasedTester
    module SMT8
      # An internal method called by Origen to create the pattern header
      def pattern_header(options = {})
        options = {
        }.merge(options)
        @program_lines = []
        @program_action_lines = []
        @program_lines << '<?xml version="1.0" encoding="UTF-8"?>'
        @program_lines << '<Program xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Program.xsd">'
        @program_lines << '  <Assignment id="memory" value="SM"/>'
        pin_list = ordered_pins.map do |p|
          if Origen.app.pin_pattern_order.include?(p.id)
            # specified name overrides pin name
            if (p.is_a?(Origen::Pins::PinCollection)) || p.id != p.name
              p.id.to_s # groups or aliases can be lower case
            else
              p.id.to_s.upcase # pins must be uppercase
            end
          else
            if (p.is_a?(Origen::Pins::PinCollection)) || p.id != p.name
              p.name.to_s # groups or aliases can be lower case
            else
              p.name.to_s.upcase # pins must be uppercase
            end
          end
        end.join(',')
        @program_lines << "  <Instrument id=\"#{pin_list}\">"
      end

      # An internal method called by Origen to generate the pattern footer
      def pattern_footer(options = {})
        options = {
          end_in_ka:      false
        }.merge(options)
        if options[:end_in_ka]
          Origen.log.warning '93K keep alive not yet implemented!'
          ss 'WARNING: 93K keep alive not yet implemented!'
        end
        @program_footer_lines = []
        @program_footer_lines << '</Program>'
      end

      # @api private
      def open_and_write_pattern(filename)
        pat_name = Pathname.new(filename).basename.to_s
        tmp_dir = filename.gsub('.', '_')
        FileUtils.mkdir_p(tmp_dir)
        program_file = File.join(tmp_dir, 'Program.sprg')
        vector_file = File.join(tmp_dir, 'Vectors.vec')
        comments_file = File.join(tmp_dir, 'Comments.cmt')

        @gen_vec = 0
        @vector_number = 0
        @vector_lines = []
        @comment_lines = []
        # @program_lines was already created with the pattern_header

        yield

        write_gen_vec

        @program_lines << '  </Instrument>'

        File.open(program_file, 'w') do |f|
          (@program_lines + @program_action_lines + @program_footer_lines).each do |line|
            f.puts line
          end
        end

        File.open(vector_file, 'w') { |f| @vector_lines.each { |l| f.puts l } }
        File.open(comments_file, 'w') { |f| @comment_lines.each { |l| f.puts l } }

        Dir.chdir tmp_dir do
          `zip #{pat_name} Program.sprg Vectors.vec Comments.cmt`
          FileUtils.mv pat_name, filename
        end
      ensure
        FileUtils.rm_rf(tmp_dir) if File.exist?(tmp_dir)
      end

      # @api private
      #
      # The SMT8 microcode is implemented as a post conversion of the SMT7 microcode, rather than
      # generating SMT8 microcode originally.
      # This is generally an easier implementation and since they both run on the same h/ware there
      # should always be a 1:1 feature mapping between the 2 systems.
      def track_and_format_comment(comment)
        if comment =~ /^SQPG/
          write_gen_vec
          if comment =~ /^SQPG JSUB ([^;]+);/
            @program_lines << "    <Instruction id=\"patternCall\" value=\"patterns.#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG MACT (\d+);/
            @program_lines << "    <Instruction id=\"match\" value=\"#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG MRPT (\d+);/
            @program_lines << "    <Instruction id=\"matchRepeat\" value=\"#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG LBGN (\d+);/
            @program_lines << "    <Instruction id=\"loop\" value=\"#{Regexp.last_match(1)}\"/>"
          elsif comment =~ /^SQPG LEND;/
            @program_lines << "    <Instruction id=\"loopEnd\"/>"
          elsif comment =~ /^SQPG RETC (\d) (\d);/
            @program_lines << "    <Instruction id=\"returnConditional\">"
            @program_lines << "      <Assignment id=\"onFail\" value=\"#{Regexp.last_match(1) == '0' ? 'false' : 'true'}\"/>"
            @program_lines << "      <Assignment id=\"resetFail\" value=\"#{Regexp.last_match(2) == '0' ? 'false' : 'true'}\"/>"
            @program_lines << '    </Instruction>'
          elsif comment =~ /^SQPG PADDING/
            # TODO: Is this required in SMT8?
          else
            Origen.log.warning "This SMT7 microcode was not converted to SMT8: #{comment}"
          end
        end
      end

      # This is an internal method use by Origen which returns a fully formatted vector
{'fraction_non_alphanumeric': 0.12877778916094662, 'fraction_numerical': 0.006556705255609057, 'mean_word_length': 2.099047619047619, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 2, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5277393', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2967, 'n_words': 743}