tmp: reformat nac3standalone/demo/demo.c
This commit is contained in:
parent
6a35203101
commit
9ac4c73797
|
@ -6,19 +6,33 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
double dbl_nan(void) { return NAN; }
|
||||
double dbl_nan(void) {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
double dbl_inf(void) { return INFINITY; }
|
||||
double dbl_inf(void) {
|
||||
return INFINITY;
|
||||
}
|
||||
|
||||
void output_bool(bool x) { puts(x ? "True" : "False"); }
|
||||
void output_bool(bool x) {
|
||||
puts(x ? "True" : "False");
|
||||
}
|
||||
|
||||
void output_int32(int32_t x) { printf("%" PRId32 "\n", x); }
|
||||
void output_int32(int32_t x) {
|
||||
printf("%" PRId32 "\n", x);
|
||||
}
|
||||
|
||||
void output_int64(int64_t x) { printf("%" PRId64 "\n", x); }
|
||||
void output_int64(int64_t x) {
|
||||
printf("%" PRId64 "\n", x);
|
||||
}
|
||||
|
||||
void output_uint32(uint32_t x) { printf("%" PRIu32 "\n", x); }
|
||||
void output_uint32(uint32_t x) {
|
||||
printf("%" PRIu32 "\n", x);
|
||||
}
|
||||
|
||||
void output_uint64(uint64_t x) { printf("%" PRIu64 "\n", x); }
|
||||
void output_uint64(uint64_t x) {
|
||||
printf("%" PRIu64 "\n", x);
|
||||
}
|
||||
|
||||
void output_float64(double x) {
|
||||
if (isnan(x)) {
|
||||
|
@ -38,7 +52,7 @@ void output_range(int32_t range[3]) {
|
|||
}
|
||||
|
||||
void output_asciiart(int32_t x) {
|
||||
static const char *chars = " .,-:;i+hHM$*#@ ";
|
||||
static const char* chars = " .,-:;i+hHM$*#@ ";
|
||||
if (x < 0) {
|
||||
putchar('\n');
|
||||
} else {
|
||||
|
@ -47,12 +61,12 @@ void output_asciiart(int32_t x) {
|
|||
}
|
||||
|
||||
struct cslice {
|
||||
void *data;
|
||||
void* data;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
void output_int32_list(struct cslice *slice) {
|
||||
const int32_t *data = reinterpret_cast<int32_t *>(slice->data);
|
||||
void output_int32_list(struct cslice* slice) {
|
||||
const int32_t* data = reinterpret_cast<int32_t*>(slice->data);
|
||||
|
||||
putchar('[');
|
||||
for (size_t i = 0; i < slice->len; ++i) {
|
||||
|
@ -66,29 +80,27 @@ void output_int32_list(struct cslice *slice) {
|
|||
putchar('\n');
|
||||
}
|
||||
|
||||
void output_str(struct cslice *slice) {
|
||||
const char *data = reinterpret_cast<const char *>(slice->data);
|
||||
void output_str(struct cslice* slice) {
|
||||
const char* data = reinterpret_cast<const char*>(slice->data);
|
||||
|
||||
for (size_t i = 0; i < slice->len; ++i) {
|
||||
putchar(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void output_strln(struct cslice *slice) {
|
||||
void output_strln(struct cslice* slice) {
|
||||
output_str(slice);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
uint64_t dbg_stack_address(__attribute__((unused)) struct cslice *slice) {
|
||||
uint64_t dbg_stack_address(__attribute__((unused)) struct cslice* slice) {
|
||||
int i;
|
||||
void *ptr = static_cast<void *>(&i);
|
||||
void* ptr = static_cast<void*>(&i);
|
||||
return (uintptr_t)ptr;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
exit(101);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
@ -105,18 +117,14 @@ struct Exception {
|
|||
int64_t param[3];
|
||||
};
|
||||
|
||||
uint32_t __nac3_raise(struct Exception *e) {
|
||||
uint32_t __nac3_raise(struct Exception* e) {
|
||||
printf("__nac3_raise called. Exception details:\n");
|
||||
printf(" ID: %" PRIu32 "\n", e->id);
|
||||
printf(" Location: %*s:%" PRIu32 ":%" PRIu32 "\n",
|
||||
static_cast<int>(e->file.len),
|
||||
reinterpret_cast<const char *>(e->file.data), e->line, e->column);
|
||||
printf(" Function: %*s\n", static_cast<int>(e->function.len),
|
||||
reinterpret_cast<const char *>(e->function.data));
|
||||
printf(" Message: \"%*s\"\n", static_cast<int>(e->message.len),
|
||||
reinterpret_cast<const char *>(e->message.data));
|
||||
printf(" Params: {0}=%" PRId64 ", {1}=%" PRId64 ", {2}=%" PRId64 "\n",
|
||||
e->param[0], e->param[1], e->param[2]);
|
||||
printf(" Location: %*s:%" PRIu32 ":%" PRIu32 "\n", static_cast<int>(e->file.len),
|
||||
reinterpret_cast<const char*>(e->file.data), e->line, e->column);
|
||||
printf(" Function: %*s\n", static_cast<int>(e->function.len), reinterpret_cast<const char*>(e->function.data));
|
||||
printf(" Message: \"%*s\"\n", static_cast<int>(e->message.len), reinterpret_cast<const char*>(e->message.data));
|
||||
printf(" Params: {0}=%" PRId64 ", {1}=%" PRId64 ", {2}=%" PRId64 "\n", e->param[0], e->param[1], e->param[2]);
|
||||
exit(101);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
@ -125,4 +133,6 @@ void __nac3_end_catch(void) {}
|
|||
|
||||
extern int32_t run(void);
|
||||
|
||||
int main(void) { run(); }
|
||||
int main(void) {
|
||||
run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue