<commit_before>#!/usr/bin/python

import os
import sys
import subprocess

JS_VER = 2

exec(open(os.path.expanduser('~/.emscripten'), 'r').read())
toolPath = os.path.join(EMSCRIPTEN_ROOT, 'tools')
emmakenPath = os.path.join(toolPath, 'emmaken.py')
emscriptenPath = os.path.join(EMSCRIPTEN_ROOT, 'emscripten.py')

def loadVersion():
    f = open('libqrencode/configure.ac')
    major = 0
    majorStr = 'MAJOR_VERSION='
    minor = 0
    minorStr = 'MINOR_VERSION='
    micro = 0
    microStr = 'MICRO_VERSION='
    for l in f.readlines():
        if l.startswith(majorStr):
            major = int(l[len(majorStr):])
        if l.startswith(minorStr):
            minor = int(l[len(minorStr):])
        if l.startswith(microStr):
            micro = int(l[len(microStr):])
            
    return '%s.%s.%s_%s' % (major, minor, micro, JS_VER)

ver = loadVersion()
jsFileName = 'libqrencode-' + ver + '.js'
jsMinFileName = 'libqrencode-' + ver + '.min.js'

def readAll(h):
    r = ''
    while True:
        n = h.read()
        if n == '':
            break
        r = r + n
    return r

def makeLib():
    buildFailed = 'Build failed'

    if not os.path.exists('build'):
        os.makedirs('build')
    os.chdir('build')

    def showState(s):
        print
        print '================ ' + s
        print

    showState('compiling libqrencode')
    r = subprocess.call(emmakenPath + ' -D HAVE_CONFIG_H ../*.c', shell=True)
    assert r == 0, buildFailed
    print 'ok'

    showState('linking libqrencode')
    r = subprocess.call('llvm-link *.o -o libqrencode-js.bc', shell=True)
    assert r == 0, buildFailed
    print 'ok'

    showState('compiling to JavaScript')
    jsPipe = subprocess.Popen(emscriptenPath + ' -s INVOKE_RUN=0 -s OPTIMIZE=1 -s RELOOP=1 -s FAST_MEMORY=1 libqrencode-js.bc', 
        shell=True, stdout=subprocess.PIPE).stdout
    print 'ok'

    jsCode = readAll(jsPipe)

    tmplVars = {'genCode': jsCode}

    tmpl = readAll(open('../libqrencode.tmpl.js'))

    def jsApplyTmpl(varName):
        return tmpl.replace('{{genCode}}', jsCode)\
                   .replace('{{varName}}', varName)

    os.chdir('../release/')<commit_msg>more optimizations<commit_after>#!/usr/bin/python

import os
import sys
import subprocess

JS_VER = 3

exec(open(os.path.expanduser('~/.emscripten'), 'r').read())
toolPath = os.path.join(EMSCRIPTEN_ROOT, 'tools')
emmakenPath = os.path.join(toolPath, 'emmaken.py')
emscriptenPath = os.path.join(EMSCRIPTEN_ROOT, 'emscripten.py')

def loadVersion():
    f = open('libqrencode/configure.ac')
    major = 0
    majorStr = 'MAJOR_VERSION='
    minor = 0
    minorStr = 'MINOR_VERSION='
    micro = 0
    microStr = 'MICRO_VERSION='
    for l in f.readlines():
        if l.startswith(majorStr):
            major = int(l[len(majorStr):])
        if l.startswith(minorStr):
            minor = int(l[len(minorStr):])
        if l.startswith(microStr):
            micro = int(l[len(microStr):])
            
    return '%s.%s.%s_%s' % (major, minor, micro, JS_VER)

ver = loadVersion()
jsFileName = 'libqrencode-' + ver + '.js'
jsMinFileName = 'libqrencode-' + ver + '.min.js'

def readAll(h):
    r = ''
    while True:
        n = h.read()
        if n == '':
            break
        r = r + n
    return r

def makeLib():
    buildFailed = 'Build failed'

    if not os.path.exists('build'):
        os.makedirs('build')
    os.chdir('build')

    def showState(s):
        print
        print '================ ' + s
        print

    showState('compiling libqrencode')
    r = subprocess.call(emmakenPath + ' -D HAVE_CONFIG_H ../*.c', shell=True)
    assert r == 0, buildFailed
    print 'ok'

    showState('linking libqrencode')
    r = subprocess.call('llvm-link *.o -o libqrencode-js.bc', shell=True)
    assert r == 0, buildFailed
    print 'ok'

    showState('compiling to JavaScript')
    jsPipe = subprocess.Popen(emscriptenPath + ' -s INVOKE_RUN=0 -s OPTIMIZE=1 -s RELOOP=1 -s FAST_MEMORY=1 -s CORRECT_OVERFLOWS=0 -s CORRECT_ROUNDINGS=0 libqrencode-js.bc', 
        shell=True, stdout=subprocess.PIPE).stdout
    print 'ok'

    jsCode = readAll(jsPipe)

    tmplVars = {'genCode': jsCode}

    tmpl = readAll(open('../libqrencode.tmpl.js'))

    def jsApplyTmpl(varName):
        return tmpl.replace('{{genCode}}', jsCode)\
                   .replace('{{varName}}', varName)

    os.chdir('../release/')
{'fraction_non_alphanumeric': 0.15970796258270592, 'fraction_numerical': 0.005019393109742185, 'mean_word_length': 2.6655518394648827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1603022', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1558, 'n_words': 324}