Added cwasm_arena.c and cwasm_debug.c. Arena API hasn't been tested well yet. There's also something wrong with our DebugOutputLineBuffer usage for splitting lines to multiple Javascript output calls. Also added an int level to jsStdPrint and a bunch of macros to cwasm.h

This commit is contained in:
2025-08-31 17:33:48 -07:00
parent d0aa7a1d0e
commit cca61ea163
9 changed files with 566 additions and 11 deletions

66
cwasm.h
View File

@@ -31,6 +31,36 @@ Description:
#error This standard library implementation assumes little-endian byte order
#endif
// +--------------------------------------------------------------+
// | Check Configuration Macros |
// +--------------------------------------------------------------+
#ifndef CWASM_DEBUG
#define CWASM_DEBUG 0
#endif
#ifndef CWASM_ASSERTIONS_ENABLED
#define CWASM_ASSERTIONS_ENABLED CWASM_DEBUG
#endif
#ifndef CWASM_DEBUG_OUTPUT_LINE_BUFFER_SIZE
#define CWASM_DEBUG_OUTPUT_LINE_BUFFER_SIZE 1024 //chars
#endif
#ifndef CWASM_DEBUG_OUTPUT_PRINT_BUFFER_SIZE
#define CWASM_DEBUG_OUTPUT_PRINT_BUFFER_SIZE 1024 //chars
#endif
#ifndef CWASM_ENABLE_DBG_LEVEL_DEBUG
#define CWASM_ENABLE_DBG_LEVEL_DEBUG 1
#endif
#ifndef CWASM_ENABLE_DBG_LEVEL_INFO
#define CWASM_ENABLE_DBG_LEVEL_INFO 1
#endif
#ifndef CWASM_ENABLE_DBG_LEVEL_WARNING
#define CWASM_ENABLE_DBG_LEVEL_WARNING 1
#endif
#ifndef CWASM_ENABLE_DBG_LEVEL_ERROR
#define CWASM_ENABLE_DBG_LEVEL_ERROR 1
#endif
// +--------------------------------------------------------------+
// | Macros |
// +--------------------------------------------------------------+
@@ -65,6 +95,41 @@ Description:
#define WASM_EXPORT(functionName) MAYBE_EXTERN_C __attribute__((export_name(#functionName)))
#if LANGUAGE_IS_C
#define ZEROED {0}
#else
#define ZEROED {}
#endif
#define ArrayCount(array) (sizeof(array) / sizeof((array)[0]))
#define IsAlignedTo(pntr, alignment) ((alignment) == 0 || (((size_t)(pntr)) % (alignment)) == 0)
#define AlignOffset(pntr, alignment) ((alignment) == 0 ? 0 : (((alignment) - (((size_t)(pntr)) % (alignment))) % alignment))
// Shorthand for writing things like (4 * 1024 * 1024) as Megabytes(4).
// Can be used for more than just memory sizes but these powers of 1024 are often
// used when partitioning memory because they relate to binary bit patterns
#define Kilo(value) ((value) * 1024ULL)
#define Mega(value) (Kilo(value) * 1024ULL)
#define Giga(value) (Mega(value) * 1024ULL)
#define Tera(value) (Giga(value) * 1024ULL)
#define Kilobytes(value) Kilo(value)
#define Megabytes(value) Mega(value)
#define Gigabytes(value) Giga(value)
#define Terabytes(value) Tera(value)
#define Thousand(value) ((value) * 1000ULL)
#define Million(value) ((value) * 1000000ULL)
#define Billion(value) ((value) * 1000000000ULL)
#define Trillion(value) ((value) * 1000000000000ULL)
#if CWASM_ASSERTIONS_ENABLED
#define Assert(condition) assert(condition)
#define AssertMsg(condition, message) assert_msg((condition), (message))
#else
#define Assert(condition) sizeof(condition) //do nothing, but make sure anything used in condition is not treated as "unused" when assertions are disabled
#define AssertMsg(condition, message) sizeof(condition)
#endif
// +--------------------------------------------------------------+
// | Standard Includes |
// +--------------------------------------------------------------+
@@ -76,6 +141,7 @@ Description:
#include <stdbool.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <assert.h>