<commit_before>import logging
import subprocess
from tempfile import NamedTemporaryFile

from .. import lekvar
from ..errors import *

from .state import State
from .builtins import builtins
from . import emitter
from . import bindings

def emit(module:lekvar.Module, logger = logging.getLogger()):
    State.logger = logger.getChild("llvm")

    with State.begin("main", logger):
        module.emit()

    State.module.verify()
    return State.module.toString()

# Wrapping around lli
#TODO: Replace with direct calls to llvm
def run(source:bytes):
    try:
        return subprocess.check_output("lli",
            input = source,
            stderr = subprocess.STDOUT,
        )
    except subprocess.CalledProcessError as e:
        raise ExecutionError("lli error running source: {}".format(e.output))

# Wrapping around clang
#TODO: Replace with direct calls to llvm
def compile(source:bytes):
    try:
        # Leave cleaning these up to python. Breaks circleci otherwise...
        f_in = NamedTemporaryFile('wb', suffix=".ll")
        f_in.write(source)
        f_in.flush()

        f_out = NamedTemporaryFile('rb')
        subprocess.check_output(["clang", "-o", f_out.name, f_in.name],
                                    stderr = subprocess.STDOUT)
        return f_out.read()
    except subprocess.CalledProcessError as e:
        output = e.output.decode("UTF-8")
        raise ExecutionError("clang error compiling source {}".format(output))
<commit_msg>Made clang wrapper use verbose output<commit_after>import logging
import subprocess
from tempfile import NamedTemporaryFile

from .. import lekvar
from ..errors import *

from .state import State
from .builtins import builtins
from . import emitter
from . import bindings

def emit(module:lekvar.Module, logger = logging.getLogger()):
    State.logger = logger.getChild("llvm")

    with State.begin("main", logger):
        module.emit()

    State.module.verify()
    return State.module.toString()

# Wrapping around lli
#TODO: Replace with direct calls to llvm
def run(source:bytes):
    try:
        return subprocess.check_output("lli",
            input = source,
            stderr = subprocess.STDOUT,
        )
    except subprocess.CalledProcessError as e:
        raise ExecutionError("lli error running source: {}".format(e.output))

# Wrapping around clang
#TODO: Replace with direct calls to llvm
def compile(source:bytes):
    try:
        # Leave cleaning these up to python. Breaks circleci otherwise...
        f_in = NamedTemporaryFile('wb', suffix=".ll")
        f_in.write(source)
        f_in.flush()

        f_out = NamedTemporaryFile('rb')
        subprocess.check_output(["clang", "-v", "-o", f_out.name, f_in.name],
                                    stderr = subprocess.STDOUT)
        return f_out.read()
    except subprocess.CalledProcessError as e:
        output = e.output.decode("UTF-8")
        raise ExecutionError("clang error compiling source {}".format(output))

{'fraction_non_alphanumeric': 0.10409670920080591, 'fraction_numerical': 0.000671591672263264, 'mean_word_length': 2.87890625, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '207294', 'n_tokens_mistral': 870, 'n_tokens_neox': 851, 'n_words': 244}