<commit_before>#include <jive/arch/stackslot.h>

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <jive/common.h>
#include <jive/context.h>

#include <jive/arch/memory.h>
#include <jive/vsdg/statetype-private.h>

static const jive_resource_class_demotion no_demotion[] = {{NULL, NULL}};
static const jive_memory_type stackvar_type = {{{&JIVE_MEMORY_TYPE}}};

const jive_resource_class jive_root_stackslot_class = {
	.name = "stackslot",
	.limit = 0,
	.parent = &jive_root_resource_class,
	.depth = 1,
	.is_abstract = true,
	.priority = jive_resource_class_priority_lowest,
	.demotions = no_demotion
};

#define MAKE_STACKSLOT_CLASS(SIZE, ALIGNMENT) \
const jive_stackslot_size_class jive_stackslot_class_##SIZE##_##ALIGNMENT = { \
	.base = { \
		.name = "stack" #SIZE " " #ALIGNMENT, \
		.limit = 0, .names = NULL, \
		.parent = &jive_root_stackslot_class, \
		.depth = 2, \
		.is_abstract = false, \
		.priority = jive_resource_class_priority_mem_low,\
		.demotions = no_demotion, \
		.type = &stackvar_type.base.base \
	}, \
	.size = SIZE, \
	.alignment = ALIGNMENT \
}

MAKE_STACKSLOT_CLASS(8, 8);
MAKE_STACKSLOT_CLASS(16, 16);
MAKE_STACKSLOT_CLASS(32, 32);
MAKE_STACKSLOT_CLASS(64, 64);
MAKE_STACKSLOT_CLASS(128, 128);

static const jive_stackslot_size_class *
jive_stackslot_size_class_create(size_t size, size_t alignment)
{
	/* try statically allocated classes first */
	if (size == alignment) {
		switch(size) {
			case 8: return &jive_stackslot_class_8_8;
			case 16: return &jive_stackslot_class_16_16;
			case 32: return &jive_stackslot_class_32_32;
			case 64: return &jive_stackslot_class_64_64;
			case 128: return &jive_stackslot_class_128_128;
		}
	};
	
	/* if requisite class not statically allocated, create it
	dynamically */
	char tmpname[80];
	snprintf(tmpname, sizeof(tmpname), "stack_s%zda%zd", size, alignment);
	
	char * name = strdup(tmpname);
	if (!name)
		return 0;
	
	jive_stackslot_size_class * cls = malloc(sizeof(*cls));
	if (!cls) {
		free(name);
		return 0;
	}
	
	cls->base.name = name;
	cls->base.limit = 0;
	cls->base.names = NULL;
	cls->base.parent = &jive_root_stackslot_class;
	cls->base.depth = cls->base.parent->depth + 1;
	cls->base.is_abstract = false;
	cls->base.priority = jive_resource_class_priority_mem_low;
	cls->base.demotions = no_demotion;
	cls->base.type = &stackvar_type.base.base;
	cls->size = size;
	cls->alignment = alignment;
	
	return cls;
}

jive_stackslot *
jive_stackslot_create(const jive_resource_class * parent, long offset);

static const jive_fixed_stackslot_class *
jive_fixed_stackslot_class_create(const jive_stackslot_size_class * parent, int offset)
{
	char tmpname[80];
	snprintf(tmpname, sizeof(tmpname), "stack_s%zda%zd@%d", parent->size, parent->alignment, offset);
	
	char * name = strdup(tmpname);
	if (!name)
		return 0;
	
	jive_fixed_stackslot_class * cls = malloc(sizeof(*cls));
	if (!cls) {
		free(name);
		return 0;
	}
	
	jive_stackslot * slot = malloc(sizeof(*slot));
	if (!slot) {
		free(name);
		free(cls);
		return 0;
	}
	
	slot->base.name = name;
	slot->base.resource_class = &cls->base.base;
	slot->offset = offset;
	
	cls->base.base.name = name;
	cls->base.base.limit = 1;
	cls->base.base.names = &cls->slot;
	cls->base.base.parent = &parent->base;
	cls->base.base.depth = parent->base.depth + 1;
	cls->base.base.is_abstract = false;
	cls->base.base.priority = jive_resource_class_priority_mem_high;
	cls->base.base.demotions = no_demotion;<commit_msg>arch: stackslot size and offset in bytes<commit_after>#include <jive/arch/stackslot.h>

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <jive/common.h>
#include <jive/context.h>

#include <jive/arch/memory.h>
#include <jive/vsdg/statetype-private.h>

static const jive_resource_class_demotion no_demotion[] = {{NULL, NULL}};
static const jive_memory_type stackvar_type = {{{&JIVE_MEMORY_TYPE}}};

const jive_resource_class jive_root_stackslot_class = {
	.name = "stackslot",
	.limit = 0,
	.parent = &jive_root_resource_class,
	.depth = 1,
	.is_abstract = true,
	.priority = jive_resource_class_priority_lowest,
	.demotions = no_demotion
};

#define MAKE_STACKSLOT_CLASS(SIZE, ALIGNMENT) \
const jive_stackslot_size_class jive_stackslot_class_##SIZE##_##ALIGNMENT = { \
	.base = { \
		.name = "stack" #SIZE " " #ALIGNMENT, \
		.limit = 0, .names = NULL, \
		.parent = &jive_root_stackslot_class, \
		.depth = 2, \
		.is_abstract = false, \
		.priority = jive_resource_class_priority_mem_low,\
		.demotions = no_demotion, \
		.type = &stackvar_type.base.base \
	}, \
	.size = SIZE, \
	.alignment = ALIGNMENT \
}

MAKE_STACKSLOT_CLASS(8, 8);
MAKE_STACKSLOT_CLASS(16, 16);
MAKE_STACKSLOT_CLASS(32, 32);
MAKE_STACKSLOT_CLASS(64, 64);
MAKE_STACKSLOT_CLASS(128, 128);

static const jive_stackslot_size_class *
jive_stackslot_size_class_create(size_t size, size_t alignment)
{
	/* try statically allocated classes first */
	if (size == alignment) {
		switch(size) {
			case 8: return &jive_stackslot_class_8_8;
			case 16: return &jive_stackslot_class_16_16;
			case 32: return &jive_stackslot_class_32_32;
			case 64: return &jive_stackslot_class_64_64;
			case 128: return &jive_stackslot_class_128_128;
		}
	};
	
	/* if requisite class not statically allocated, create it
	dynamically */
	char tmpname[80];
	snprintf(tmpname, sizeof(tmpname), "stack_s%zda%zd", size, alignment);
	
	char * name = strdup(tmpname);
	if (!name)
		return 0;
	
	jive_stackslot_size_class * cls = malloc(sizeof(*cls));
	if (!cls) {
		free(name);
		return 0;
	}
	
	cls->base.name = name;
	cls->base.limit = 0;
	cls->base.names = NULL;
	cls->base.parent = &jive_root_stackslot_class;
	cls->base.depth = cls->base.parent->depth + 1;
	cls->base.is_abstract = false;
	cls->base.priority = jive_resource_class_priority_mem_low;
	cls->base.demotions = no_demotion;
	cls->base.type = &stackvar_type.base.base;
	cls->size = size;
	cls->alignment = alignment;
	
	return cls;
}

jive_stackslot *
jive_stackslot_create(const jive_resource_class * parent, long offset);

static const jive_fixed_stackslot_class *
jive_fixed_stackslot_class_create(const jive_stackslot_size_class * parent, int offset)
{
	char tmpname[80];
	snprintf(tmpname, sizeof(tmpname), "stack_s%zda%zd@%d", parent->size, parent->alignment / 8, offset / 8);
	
	char * name = strdup(tmpname);
	if (!name)
		return 0;
	
	jive_fixed_stackslot_class * cls = malloc(sizeof(*cls));
	if (!cls) {
		free(name);
		return 0;
	}
	
	jive_stackslot * slot = malloc(sizeof(*slot));
	if (!slot) {
		free(name);
		free(cls);
		return 0;
	}
	
	slot->base.name = name;
	slot->base.resource_class = &cls->base.base;
	slot->offset = offset / 8;
	
	cls->base.base.name = name;
	cls->base.base.limit = 1;
	cls->base.base.names = &cls->slot;
	cls->base.base.parent = &parent->base;
	cls->base.base.depth = parent->base.depth + 1;
	cls->base.base.is_abstract = false;
	cls->base.base.priority = jive_resource_class_priority_mem_high;
	cls->base.base.demotions = no_demotion;
{'fraction_non_alphanumeric': 0.1404710920770878, 'fraction_numerical': 0.019557458957887224, 'mean_word_length': 4.7052117263843645, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 81, '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': '194610', 'n_tokens_mistral': 2944, 'n_tokens_neox': 2709, 'n_words': 504}