Files
CWasm/cwasm.c

62 lines
1.8 KiB
C

/*
File: main.c
Author: Taylor Robbins
Date: 08\28\2025
Description:
** This file serves as the compilable file for all of CWasm. It may be #included by the app.c file
*/
#include "cwasm.h"
#include "std/src/std_main.c"
#include "cwasm_debug.c"
#include "cwasm_vectors.c"
#include "cwasm_matrices.c"
#include "cwasm_arena.c"
#if !CWASM_NO_STB_IMAGE
#define STB_IMAGE_IMPLEMENTATION
#define STBIDEF static
#define STBI_NO_STDIO
#define STBI_ASSERT(expression) Assert(expression)
#define STBI_MALLOC(numBytes) AllocMem(&ScratchArenas[0], numBytes)
#define STBI_REALLOC_SIZED(allocPntr, oldSize, newSize) ReallocMem(&ScratchArenas[0], (allocPntr), (oldSize), (newSize))
#define STBI_FREE(allocPntr) //nothing TODO: Once we have a general purpose arena we can implement this!
#define STBI_NO_SIMD
#define STBI_ONLY_PNG
#define STBI_NO_THREAD_LOCALS
#include "stb_image.h"
#endif
#include "cwasm_webgl_js_imports.h"
#include "cwasm_webgl_constants.h"
void InitializeCWasm(u32 scratchArenasSize)
{
InitGlobalArenas(scratchArenasSize);
}
WASM_EXPORT(cAllocMem) void* cAllocMem(Arena* arenaPntr, int numBytes, int alignment)
{
NotNull(arenaPntr);
Assert(numBytes >= 0);
Assert(alignment >= 0);
return AllocMemAligned(arenaPntr, (u32)numBytes, (u32)alignment);
}
WASM_EXPORT(cGetScratchArenaPntr) Arena* cGetScratchArenaPntr(Arena* conflictArenaPntr)
{
ArenaMark scratchMark = GetScratch1(conflictArenaPntr);
return scratchMark.arena;
}
WASM_EXPORT(cGetScratchArenaMark) u32 cGetScratchArenaMark(Arena* conflictArenaPntr)
{
ArenaMark scratchMark = GetScratch1(conflictArenaPntr);
return scratchMark.mark;
}
WASM_EXPORT(cEndScratchArena) void cEndScratchArena(Arena* arenaPntr, u32 mark)
{
ResetToMark(arenaPntr, mark);
}