forked from M-Labs/nac3
1
0
Fork 0

standalone: Fix indentation of demo.c

This commit is contained in:
David Mak 2023-10-30 17:22:32 +08:00 committed by sb10q
parent bb5147521f
commit bb27e3d400
1 changed files with 42 additions and 42 deletions

View File

@ -5,91 +5,91 @@
#include <string.h> #include <string.h>
#if __SIZEOF_POINTER__ == 8 #if __SIZEOF_POINTER__ == 8
#define usize uint64_t #define usize uint64_t
#elif __SIZEOF_POINTER__ == 4 #elif __SIZEOF_POINTER__ == 4
#define usize uint32_t #define usize uint32_t
#else #else
#error "Unsupported platform - Platform is not 32-bit or 64-bit" #error "Unsupported platform - Platform is not 32-bit or 64-bit"
#endif #endif
void output_bool(bool x) { void output_bool(bool x) {
puts(x ? "True" : "False"); puts(x ? "True" : "False");
} }
void output_int32(int32_t x) { void output_int32(int32_t x) {
printf("%d\n", x); printf("%d\n", x);
} }
void output_int64(int64_t x) { void output_int64(int64_t x) {
printf("%ld\n", x); printf("%ld\n", x);
} }
void output_uint32(uint32_t x) { void output_uint32(uint32_t x) {
printf("%d\n", x); printf("%d\n", x);
} }
void output_uint64(uint64_t x) { void output_uint64(uint64_t x) {
printf("%ld\n", x); printf("%ld\n", x);
} }
void output_float64(double x) { void output_float64(double x) {
printf("%f\n", x); printf("%f\n", x);
} }
void output_asciiart(int32_t x) { void output_asciiart(int32_t x) {
static const char *chars = " .,-:;i+hHM$*#@ "; static const char *chars = " .,-:;i+hHM$*#@ ";
if (x < 0) { if (x < 0) {
putchar('\n'); putchar('\n');
} else { } else {
putchar(chars[x]); putchar(chars[x]);
} }
} }
struct cslice { struct cslice {
void *data; void *data;
usize len; usize len;
}; };
void output_int32_list(struct cslice *slice) { void output_int32_list(struct cslice *slice) {
const int32_t *data = (int32_t *) slice->data; const int32_t *data = (int32_t *) slice->data;
putchar('['); putchar('[');
for (usize i = 0; i < slice->len; ++i) { for (usize i = 0; i < slice->len; ++i) {
if (i == slice->len - 1) { if (i == slice->len - 1) {
printf("%d", data[i]); printf("%d", data[i]);
} else { } else {
printf("%d, ", data[i]); printf("%d, ", data[i]);
}
} }
} putchar(']');
putchar(']'); putchar('\n');
putchar('\n');
} }
void output_str(struct cslice *slice) { void output_str(struct cslice *slice) {
const char *data = (const char *) slice->data; const char *data = (const char *) slice->data;
for (usize i = 0; i < slice->len; ++i) { for (usize i = 0; i < slice->len; ++i) {
putchar(data[i]); putchar(data[i]);
} }
putchar('\n'); putchar('\n');
} }
uint64_t dbg_stack_address(__attribute__((unused)) struct cslice *slice) { uint64_t dbg_stack_address(__attribute__((unused)) struct cslice *slice) {
int i; int i;
void *ptr = (void *) &i; void *ptr = (void *) &i;
return (uintptr_t) ptr; return (uintptr_t) ptr;
} }
uint32_t __nac3_personality(uint32_t state, uint32_t exception_object, uint32_t context) { uint32_t __nac3_personality(uint32_t state, uint32_t exception_object, uint32_t context) {
printf("__nac3_personality(state: %u, exception_object: %u, context: %u\n", state, exception_object, context); printf("__nac3_personality(state: %u, exception_object: %u, context: %u\n", state, exception_object, context);
exit(101); exit(101);
__builtin_unreachable(); __builtin_unreachable();
} }
uint32_t __nac3_raise(uint32_t state, uint32_t exception_object, uint32_t context) { uint32_t __nac3_raise(uint32_t state, uint32_t exception_object, uint32_t context) {
printf("__nac3_raise(state: %u, exception_object: %u, context: %u\n", state, exception_object, context); printf("__nac3_raise(state: %u, exception_object: %u, context: %u\n", state, exception_object, context);
exit(101); exit(101);
__builtin_unreachable(); __builtin_unreachable();
} }
void __nac3_end_catch(void) {} void __nac3_end_catch(void) {}
@ -97,5 +97,5 @@ void __nac3_end_catch(void) {}
extern int32_t run(void); extern int32_t run(void);
int main(void) { int main(void) {
run(); run();
} }