mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Add prefix in function for label code
This commit is contained in:
@@ -906,7 +906,8 @@ void disassemble(const char *filename, options_t config) {
|
||||
|
||||
if (!strcmp(litf->fun, "MAIN")) {
|
||||
printf("MAIN:\n");
|
||||
printf("%s", litf->str);
|
||||
printf("%s", str_replace_substr_all(litf->str, ".lit FUNCTION ", ".lit FUNCTION (code=FUN_) "));
|
||||
|
||||
dis_disassemble_section(&prg, prg->pc, prg->len, 0, false, config);
|
||||
free(litf->fun);
|
||||
free(litf->str);
|
||||
@@ -915,8 +916,10 @@ void disassemble(const char *filename, options_t config) {
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("FUNCTION_%s:\n", litf->fun);
|
||||
printf("%s", litf->str);
|
||||
printf("FUN_%s:\n", litf->fun);
|
||||
char sbtr[strlen(litf->fun) + 19];
|
||||
sprintf(sbtr, ".lit FUNCTION (code=FUN_%s_) ", litf->fun);
|
||||
printf("%s", str_replace_substr_all(litf->str, ".lit FUNCTION ", sbtr));
|
||||
|
||||
queue_node_t *fqf = function_queue_front;
|
||||
while (fqf != NULL) {
|
||||
|
||||
@@ -58,3 +58,35 @@ void str_append(char **str, const char *app) {
|
||||
*str = realloc(*str, (strlen(*str) + strlen(app) + 1) * sizeof(char));
|
||||
memcpy((*str) + strlen(*str), app, strlen(app) + 1);
|
||||
}
|
||||
|
||||
char* str_replace_substr_all(char *mainstr, char *substr, char *newstr) {
|
||||
int lenmain, lensub, i, j, lennew, startindex = -1, c;
|
||||
lenmain = strlen(mainstr);
|
||||
lensub = strlen(substr);
|
||||
lennew = strlen(newstr);
|
||||
char *result = (char*) malloc(sizeof(char) * (lenmain + 200));
|
||||
for (c = 0, i = 0; i < lenmain; i++) {
|
||||
if (lenmain - i >= lensub && *(mainstr + i) == *(substr)) {
|
||||
startindex = i;
|
||||
for (j = 1; j < lensub; j++)
|
||||
if (*(mainstr + i + j) != *(substr + j)) {
|
||||
startindex = -1;
|
||||
break;
|
||||
}
|
||||
if (startindex != -1) {
|
||||
for (j = 0; j < lennew; j++, c++) {
|
||||
*(result + c) = *(newstr + j);
|
||||
}
|
||||
i = i + lensub - 1;
|
||||
} else {
|
||||
*(result + c) = *(mainstr + i);
|
||||
c++;
|
||||
}
|
||||
} else {
|
||||
*(result + c) = *(mainstr + i);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
*(result + c) = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -21,5 +21,6 @@ void dis_enqueue(void *x, queue_node_t **queue_front, queue_node_t **queue_rear,
|
||||
void dis_dequeue(queue_node_t **queue_front, queue_node_t **queue_rear, uint32_t *len);
|
||||
|
||||
void str_append(char **str, const char *app);
|
||||
char* str_replace_substr_all(char *mainstr, char *substr, char *newstr);
|
||||
|
||||
#endif /* UTILS_H_ */
|
||||
|
||||
Reference in New Issue
Block a user