From 4a0db39473c1e832a6c17dfab4731745ecc36c7b Mon Sep 17 00:00:00 2001 From: churchianity Date: Mon, 1 May 2023 21:15:41 -0400 Subject: [PATCH] working on moving rendering to js --- base-index.html | 209 +++++++++++++++++++++++++++++++++++++++++++++- index.html | 215 +++++++++++++++++++++++++++++++++++++++++++++++- main.c | 26 +++++- table.h | 99 ++++++++-------------- visualization.h | 91 ++++++++------------ 5 files changed, 509 insertions(+), 131 deletions(-) diff --git a/base-index.html b/base-index.html index 2e9d5dd..ae62a1e 100644 --- a/base-index.html +++ b/base-index.html @@ -32,6 +32,7 @@ height: 100vh; overscroll-behavior: none; background: #F0EAD6; + padding-top: 10px; direction: ltr; font: 16px HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; @@ -119,6 +120,10 @@ width: 30px; height: 45px; } + .struct-info-byte-alignment { + background-color: seagreen; + opacity: 0.4; + } .struct-info-byte-first { border-left-width: 3px; } @@ -137,8 +142,206 @@ font-weight: bold; color: white; } + + dialog { + position: sticky; + top: 50vh; + left: 50vw; + transform: translate(-50%, -50%); + padding: 20px; + + border: none; + border-radius: 3px; + background-color: #F0EAD6; + box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75); + + max-width: 80vw; + max-height: 80vh; + } + + input:not([type=checkbox]):not([type=radio]) { + display: block; + height: 2em; + } + + p { + margin: 20px; + } + + input[type=checkbox] { + width: 1.2rem; + height: 1.2rem; + } + + label { + display: block; + } + + label > input { + margin: 5px 15px 15px 15px; + } + + .fix-missing-declaration-dialog-footer { + width: 100%; + + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + } + + button { + width: 10rem; + height: 2rem; + } + + .help-idk { + color: darkslategray; + font-size: 0.9rem; + } + + .help-idk-container { + width: 100%; + margin-bottom: 10px; + + display: flex; + flex-direction: row; + justify-content: flex-end; + align-items: center; + } - + - + +

What's the size and alignment of this type on your architecture?

+
+

+ Help, I don't know! +

+
+ + + + + + + +
+ +
+
+ + + diff --git a/index.html b/index.html index faa1e21..46477df 100644 --- a/index.html +++ b/index.html @@ -32,6 +32,7 @@ height: 100vh; overscroll-behavior: none; background: #F0EAD6; + padding-top: 10px; direction: ltr; font: 16px HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; @@ -119,6 +120,10 @@ width: 30px; height: 45px; } + .struct-info-byte-alignment { + background-color: seagreen; + opacity: 0.4; + } .struct-info-byte-first { border-left-width: 3px; } @@ -137,9 +142,211 @@ font-weight: bold; color: white; } + + dialog { + position: sticky; + top: 50vh; + left: 50vw; + transform: translate(-50%, -50%); + padding: 20px; + + border: none; + border-radius: 3px; + background-color: #F0EAD6; + box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75); + + max-width: 80vw; + max-height: 80vh; + } + + input:not([type=checkbox]):not([type=radio]) { + display: block; + height: 2em; + } + + p { + margin: 20px; + } + + input[type=checkbox] { + width: 1.2rem; + height: 1.2rem; + } + + label { + display: block; + } + + label > input { + margin: 5px 15px 15px 15px; + } + + .fix-missing-declaration-dialog-footer { + width: 100%; + + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + } + + button { + width: 10rem; + height: 2rem; + } + + .help-idk { + color: darkslategray; + font-size: 0.9rem; + } + + .help-idk-container { + width: 100%; + margin-bottom: 10px; + + display: flex; + flex-direction: row; + justify-content: flex-end; + align-items: center; + } - + - -
char type[64]
char name[64]
ssize_t size
ssize_t align
bool isBitfield
char name[64]
char alias[64]
char* filename
int lineNumber
ssize_t size
?
struct Declaration declarations[16]
...
int numDeclarations
unsigned int length
unsigned int capacity
void* data
struct TableEntry* next
?
char key TABLE_KEY_SIZE
...
ssize_t size
ssize_t align
TableEntry** entries
char* input_stream
char* eof
char* parse_point
char* string_storage
int string_storage_len
char* where_firstchar
char* where_lastchar
long token
double real_number
long int_number
char* string
int string_len
int line_number
int line_offset
\ No newline at end of file + +

What's the size and alignment of this type on your architecture?

+
+

+ Help, I don't know! +

+
+ + + + + + + +
+ +
+
+ + + + + \ No newline at end of file diff --git a/main.c b/main.c index d4171ec..c1b3a0f 100644 --- a/main.c +++ b/main.c @@ -66,14 +66,21 @@ #include // strtoimax #include +#include //assert #include // fread, fseek, ftell #include // malloc, free #include // va_start, va_list, va_end -#include +#include // intxx_t, etc. #include // memcmp -#include +#include // bool +struct Dummy { + char *p; + char c; + int x; +}; + static inline void die(const char* format, ...) { va_list args; va_start(args, format); @@ -140,6 +147,18 @@ static inline int strWrite(char *dest, const char *src, int maxCount) { dest[i] = '\0'; return i; } + +static ssize_t alignForward(ssize_t ptr, ssize_t align) { + ssize_t p, a, modulo; + p = ptr; + a = align; + modulo = p % a; + if (modulo != 0) { + p += a - modulo; + } + return p; +} + struct Declaration { char type[64]; char name[64]; @@ -341,7 +360,8 @@ void parseStructDeclaration(struct StructInfo *structInfo, stb_lexer *lexer) { case ']': arrayVal = strtoimax(lastOpenBracket + 1, &lexer->where_firstchar, 10); - if (arrayVal == 0) arrayVal = -1; + // happens if there is no value between, in which case it's a "name[]" decl + if (arrayVal == 0) arrayVal = -1; break; case ';': { diff --git a/table.h b/table.h index 79a80bf..a1d28b7 100644 --- a/table.h +++ b/table.h @@ -92,72 +92,41 @@ static inline Table* initTable() { Table *table = malloc(sizeof(Table)); table->entries = (TableEntry**) calloc(sizeof(TableEntry*), TABLE_NUM_LANES); - insertPadZeroes(table, "char", sizeof(char), sizeof(char)); - insertPadZeroes(table, "signed char", sizeof(signed char), sizeof(signed char)); - insertPadZeroes(table, "unsigned char", sizeof(unsigned char), sizeof(unsigned char)); - insertPadZeroes(table, "short", sizeof(short), sizeof(short)); - insertPadZeroes(table, "short int", sizeof(short int), sizeof(short int)); - insertPadZeroes(table, "signed short", sizeof(signed short), sizeof(signed short)); - insertPadZeroes(table, "signed short int", sizeof(signed short int), sizeof(signed short int)); - insertPadZeroes(table, "unsigned short", sizeof(unsigned short), sizeof(unsigned short)); - insertPadZeroes(table, "unsigned short int", sizeof(unsigned short int), sizeof(unsigned short int)); - insertPadZeroes(table, "int", sizeof(int), sizeof(int)); - insertPadZeroes(table, "signed", sizeof(signed), sizeof(signed)); - insertPadZeroes(table, "signed int", sizeof(signed int), sizeof(signed int)); - insertPadZeroes(table, "unsigned", sizeof(unsigned), sizeof(unsigned)); - insertPadZeroes(table, "unsigned int", sizeof(unsigned int), sizeof(unsigned int)); - insertPadZeroes(table, "long", sizeof(long), sizeof(long)); - insertPadZeroes(table, "long int", sizeof(long int), sizeof(long int)); - insertPadZeroes(table, "signed long", sizeof(signed long), sizeof(signed long)); - insertPadZeroes(table, "signed long int", sizeof(signed long int), sizeof(signed long int)); - insertPadZeroes(table, "unsigned long", sizeof(unsigned long), sizeof(unsigned long)); - insertPadZeroes(table, "unsigned long int", sizeof(unsigned long int), sizeof(unsigned long int)); - insertPadZeroes(table, "long long", sizeof(long long), sizeof(long long)); - insertPadZeroes(table, "long long int", sizeof(long long int), sizeof(long long int)); - insertPadZeroes(table, "signed long long", sizeof(signed long long), sizeof(signed long long)); - insertPadZeroes(table, "signed long long int", sizeof(signed long long int), sizeof(signed long long int)); - insertPadZeroes(table, "unsigned long long", sizeof(unsigned long long), sizeof(unsigned long long)); + // alignof === sizeof for primitive data types, C99 doesn't have 'alignof' + insertPadZeroes(table, "char", sizeof(char), sizeof(char)); + insertPadZeroes(table, "signed char", sizeof(signed char), sizeof(signed char)); + insertPadZeroes(table, "unsigned char", sizeof(unsigned char), sizeof(unsigned char)); + insertPadZeroes(table, "short", sizeof(short), sizeof(short)); + insertPadZeroes(table, "short int", sizeof(short int), sizeof(short int)); + insertPadZeroes(table, "signed short", sizeof(signed short), sizeof(signed short)); + insertPadZeroes(table, "signed short int", sizeof(signed short int), sizeof(signed short int)); + insertPadZeroes(table, "unsigned short", sizeof(unsigned short), sizeof(unsigned short)); + insertPadZeroes(table, "unsigned short int", sizeof(unsigned short int), sizeof(unsigned short int)); + insertPadZeroes(table, "int", sizeof(int), sizeof(int)); + insertPadZeroes(table, "signed", sizeof(signed), sizeof(signed)); + insertPadZeroes(table, "signed int", sizeof(signed int), sizeof(signed int)); + insertPadZeroes(table, "unsigned", sizeof(unsigned), sizeof(unsigned)); + insertPadZeroes(table, "unsigned int", sizeof(unsigned int), sizeof(unsigned int)); + insertPadZeroes(table, "long", sizeof(long), sizeof(long)); + insertPadZeroes(table, "long int", sizeof(long int), sizeof(long int)); + insertPadZeroes(table, "signed long", sizeof(signed long), sizeof(signed long)); + insertPadZeroes(table, "signed long int", sizeof(signed long int), sizeof(signed long int)); + insertPadZeroes(table, "unsigned long", sizeof(unsigned long), sizeof(unsigned long)); + insertPadZeroes(table, "unsigned long int", sizeof(unsigned long int), sizeof(unsigned long int)); + insertPadZeroes(table, "long long", sizeof(long long), sizeof(long long)); + insertPadZeroes(table, "long long int", sizeof(long long int), sizeof(long long int)); + insertPadZeroes(table, "signed long long", sizeof(signed long long), sizeof(signed long long)); + insertPadZeroes(table, "signed long long int", sizeof(signed long long int), sizeof(signed long long int)); + insertPadZeroes(table, "unsigned long long", sizeof(unsigned long long), sizeof(unsigned long long)); insertPadZeroes(table, "unsigned long long int", sizeof(unsigned long long int), sizeof(unsigned long long int)); - insertPadZeroes(table, "float", sizeof(float), sizeof(float)); - insertPadZeroes(table, "double", sizeof(double), sizeof(double)); - insertPadZeroes(table, "long double", sizeof(long double), sizeof(long double)); - - insertPadZeroes(table, "size_t", sizeof(size_t), sizeof(size_t)); - insertPadZeroes(table, "ssize_t", sizeof(ssize_t), sizeof(ssize_t)); - insertPadZeroes(table, "bool", sizeof(bool), sizeof(bool)); - insertPadZeroes(table, "_Bool", sizeof(_Bool), sizeof(_Bool)); - - //char - //signed char - //unsigned char - //short - //short int - //signed short - //signed short int - //unsigned short - //unsigned short int - //int - //signed - //signed int - //unsigned - //unsigned int - //long - //long int - //signed long - //signed long int - //unsigned long - //unsigned long int - //long long - //long long int - //signed long long - //signed long long int - //unsigned long long - //unsigned long long int - //float - //double - //long double - - //traversePrint(table); + insertPadZeroes(table, "float", sizeof(float), sizeof(float)); + insertPadZeroes(table, "double", sizeof(double), sizeof(double)); + insertPadZeroes(table, "long double", sizeof(long double), sizeof(long double)); + + insertPadZeroes(table, "size_t", sizeof(size_t), sizeof(size_t)); + insertPadZeroes(table, "ssize_t", sizeof(ssize_t), sizeof(ssize_t)); + insertPadZeroes(table, "bool", sizeof(bool), sizeof(bool)); + insertPadZeroes(table, "_Bool", sizeof(_Bool), sizeof(_Bool)); return table; } diff --git a/visualization.h b/visualization.h index 2d28911..cc82176 100644 --- a/visualization.h +++ b/visualization.h @@ -2,6 +2,7 @@ static size_t indexHtmlSize = 0; static char* indexHtml = NULL; +// @NOTE the assumption that we won't concat more than 1024 bytes at once. #define sb_concatf(fmt, ...) \ if ((sbc - sbi) < 1024) { \ sbc *= 1.5; \ @@ -20,74 +21,52 @@ static void outputHtml() { if (indexHtml == NULL) indexHtml = readWholeFile("base-index.html", &indexHtmlSize); int result = 0; - sb_concatf("%s", indexHtml); - + sb_concatf("%s\n"); // write the index.html file out to disk FILE* fp = fopen("index.html", "wb"); if (fp == NULL) { die("failed to open the file index.html"); } - size_t writtenCount = fwrite(stringBuffer, 1, sbi, fp); fclose(fp); - if (writtenCount != sbi) { die("wrote only partially"); }