<commit_before>#include "ire.h"


IRE_API(ire_error_t)
ire_cpu_create(ire_binary_t *binary, ire_cpu_t **destination) {
    ire_cpu_t *self;

    if (binary == NULL || binary->data == NULL || binary->code == NULL || destination == NULL) {
        return IRE_ERROR_NULL_POINTER;
    }

    self = malloc(sizeof(*self) + 0x10000);

    if (self == NULL) {
        return IRE_ERROR_OUT_OF_MEMORY;
    }

    self->registers[IRE_RIP] = binary->code->entry;
    self->registers[IRE_RSP] = binary->code->stack_base;

    if (binary->data->zero > 0) {
        memset(&(self->memory[binary->data->base]), 0, binary->data->zero);
    }

    memcpy(
        &(self->memory[binary->data->base + binary->data->zero]),
        binary->data->data,
        binary->data->size);

    memcpy(
        &(self->memory[binary->code->interrupt_base]),
        binary->code->interrupt_table,
        sizeof(binary->code->interrupt_table));

    memcpy(
        &(self->memory[binary->code->base]),
        binary->code->data,
        binary->code->size);

    *destination = self;

    return IRE_OK;
}


IRE_API(ire_error_t)
ire_cpu_destroy(ire_cpu_t **self) {
    if (self == NULL || *self == NULL) {
        return IRE_ERROR_NULL_POINTER;
    }

    free(*self);

    *self = NULL;

    return IRE_OK;
}<commit_msg>implemented ire_cpu_load_argv<commit_after>#include "ire.h"


IRE_API(ire_error_t)
ire_cpu_create(ire_binary_t *binary, ire_cpu_t **destination) {
    ire_cpu_t *self;

    if (binary == NULL || binary->data == NULL || binary->code == NULL || destination == NULL) {
        return IRE_ERROR_NULL_POINTER;
    }

    self = malloc(sizeof(*self) + 0x10000);

    if (self == NULL) {
        return IRE_ERROR_OUT_OF_MEMORY;
    }

    self->registers[IRE_RIP] = binary->code->entry;
    self->registers[IRE_RSP] = binary->code->stack_base;

    if (binary->data->zero > 0) {
        memset(&(self->memory[binary->data->base]), 0, binary->data->zero);
    }

    memcpy(
        &(self->memory[binary->data->base + binary->data->zero]),
        binary->data->data,
        binary->data->size);

    memcpy(
        &(self->memory[binary->code->interrupt_base]),
        binary->code->interrupt_table,
        sizeof(binary->code->interrupt_table));

    memcpy(
        &(self->memory[binary->code->base]),
        binary->code->data,
        binary->code->size);

    *destination = self;

    return IRE_OK;
}


IRE_API(ire_error_t)
ire_cpu_destroy(ire_cpu_t **self) {
    if (self == NULL || *self == NULL) {
        return IRE_ERROR_NULL_POINTER;
    }

    free(*self);

    *self = NULL;

    return IRE_OK;
}


IRE_API(ire_error_t)
ire_cpu_load_argv(ire_cpu_t *self, int argc, char **argv) {
    uint16_t rsp, tmp;
    size_t size;
    int i;

    if (self == NULL || argv == NULL) {
        return IRE_ERROR_NULL_POINTER;
    }

    rsp = self->registers[IRE_RSP];

    for (i = argc - 1; i >= 0; --i) {
        size = strlen(argv[i]) + 1;

        rsp -= size;

        memcpy(&(self->memory[rsp]), argv[i], size);
    }

    rsp -= sizeof(uint16_t);

    tmp = (uint16_t)argc;

    memcpy(&(self->memory[rsp]), &tmp, sizeof(tmp));

    self->registers[IRE_RSP] = rsp;

    return IRE_OK;
}
{'fraction_non_alphanumeric': 0.1670846394984326, 'fraction_numerical': 0.007836990595611285, 'mean_word_length': 2.7321637426900587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 86, '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': '3765451', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1115, 'n_words': 190}