Got a basic WebAssembly module compiling with support for calling jsStdPrint through printf implementation (provided by stb_sprintf.h). We have a single function "HelloFromWasm" exported for testing purposes. Pulled in a bunch of standard library headers from PigCore's wasm layer.
This commit is contained in:
56
std/string.h
Normal file
56
std/string.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
File: string.h
|
||||
Author: Taylor Robbins
|
||||
Date: 08\28\2025
|
||||
*/
|
||||
|
||||
#ifndef _STRING_H
|
||||
#define _STRING_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define WASM_STD_USE_BUILTIN_MEMSET 1
|
||||
#define WASM_STD_USE_BUILTIN_MEMCPY 1
|
||||
#define WASM_STD_USE_BUILTIN_MEMMOVE 1
|
||||
|
||||
MAYBE_START_EXTERN_C
|
||||
|
||||
#if WASM_STD_USE_BUILTIN_MEMSET
|
||||
// Basically converts to memory.fill instruction
|
||||
#define memset(pntr, value, numBytes) __builtin_memset((pntr), (value), (numBytes));
|
||||
#else
|
||||
void* _memset(void* pntr, int value, size_t numBytes);
|
||||
#define memset(pntr, value, numBytes) _memset((pntr), (value), (numBytes))
|
||||
#endif
|
||||
|
||||
#if WASM_STD_USE_BUILTIN_MEMCPY
|
||||
// Basically converts to memory.copy instruction
|
||||
#define memcpy(dest, source, numBytes) __builtin_memcpy((dest), (source), (numBytes));
|
||||
#else
|
||||
void* _memcpy(void* dest, const void* source, size_t numBytes);
|
||||
#define memcpy(dest, source, numBytes) _memcpy((dest), (source), (numBytes))
|
||||
#endif
|
||||
|
||||
#if WASM_STD_USE_BUILTIN_MEMMOVE
|
||||
// Basically converts to memory.copy instruction
|
||||
#define memmove(dest, source, numBytes) __builtin_memmove((dest), (source), (numBytes));
|
||||
#else
|
||||
void* _memmove(void* dest, const void* source, size_t numBytes);
|
||||
#define memmove(dest, source, numBytes) _memmove((dest), (source), (numBytes))
|
||||
#endif
|
||||
|
||||
int memcmp(const void* left, const void* right, size_t numBytes);
|
||||
char* strcpy(char* dest, const char* source);
|
||||
// TODO: char* strstr(const char* haystack, const char* needle);
|
||||
|
||||
int strcmp(const char* left, const char* right);
|
||||
int strncmp(const char* left, const char* right, size_t numBytes);
|
||||
size_t strlen(const char* str);
|
||||
// TODO: size_t wcslen(const wchar_t* str);
|
||||
|
||||
//TODO: char *strchr (const char *, int); //NEEDED for slre.c
|
||||
//TODO: char *strrchr (const char *, int); //NEEDED for slre.c
|
||||
|
||||
MAYBE_END_EXTERN_C
|
||||
|
||||
#endif // _STRING_H
|
||||
Reference in New Issue
Block a user