<commit_before>namespace :jit do
  task :generate_header do
    puts "GEN vm/llvm/types{32|64}.cpp.gen"
    `llvm-as < vm/llvm/types32.ll > vm/gen/types32.bc`
    `llvm-as < vm/llvm/types64.ll > vm/gen/types64.bc`
    `llc -march=cpp -cppgen=contents -o vm/llvm/types32.cpp.gen vm/gen/types32.bc`
    `llc -march=cpp -cppgen=contents -o vm/llvm/types64.cpp.gen vm/gen/types64.bc`
  end

  task :generate_offsets do
    classes = {}
    File.open "vm/llvm/types64.ll" do |f|
      while line = f.gets
        if m1 = /%"?(struct|union)\.rubinius::([^"]*)"?\s*=\s*type\s*\{\n/.match(line)
          line = f.gets

          fields = []
          while line.strip != "}"
            if m2 = /;\s*(.*)/.match(line)
              fields << m2[1].strip
            else
              fields << nil
            end

            line = f.gets
          end

          classes[m1[2]] = fields
        end
      end
    end

    File.open "vm/llvm/offset.hpp", "w" do |f|
      f.puts "#ifndef RBX_LLVM_OFFSET_HPP"
      f.puts "#define RBX_LLVM_OFFSET_HPP"
      f.puts ""
      f.puts "namespace offset {"

      classes.each do |name, fields|
        f.puts "namespace #{name.gsub('::', '_')} {"<commit_msg>Sort classes for LLVM offsets<commit_after>namespace :jit do
  task :generate_header do
    puts "GEN vm/llvm/types{32|64}.cpp.gen"
    `llvm-as < vm/llvm/types32.ll > vm/gen/types32.bc`
    `llvm-as < vm/llvm/types64.ll > vm/gen/types64.bc`
    `llc -march=cpp -cppgen=contents -o vm/llvm/types32.cpp.gen vm/gen/types32.bc`
    `llc -march=cpp -cppgen=contents -o vm/llvm/types64.cpp.gen vm/gen/types64.bc`
  end

  task :generate_offsets do
    classes = {}
    File.open "vm/llvm/types64.ll" do |f|
      while line = f.gets
        if m1 = /%"?(struct|union)\.rubinius::([^"]*)"?\s*=\s*type\s*\{\n/.match(line)
          line = f.gets

          fields = []
          while line.strip != "}"
            if m2 = /;\s*(.*)/.match(line)
              fields << m2[1].strip
            else
              fields << nil
            end

            line = f.gets
          end

          classes[m1[2]] = fields
        end
      end
    end

    File.open "vm/llvm/offset.hpp", "w" do |f|
      f.puts "#ifndef RBX_LLVM_OFFSET_HPP"
      f.puts "#define RBX_LLVM_OFFSET_HPP"
      f.puts ""
      f.puts "namespace offset {"

      classes.keys.sort.each do |name|
        fields = classes[name]
        f.puts "namespace #{name.gsub('::', '_')} {"
{'fraction_non_alphanumeric': 0.16333197223356472, 'fraction_numerical': 0.022866476112699062, 'mean_word_length': 1.8588098016336057, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5784365', 'n_tokens_mistral': 941, 'n_tokens_neox': 899, 'n_words': 177}