code_cachedstring

This commit is contained in:
Wolfgang Bumiller 2012-05-05 00:28:30 +02:00 committed by Wolfgang (Blub) Bumiller
parent edcb976053
commit 1fd7e30de6
2 changed files with 20 additions and 3 deletions

16
code.c
View file

@ -113,6 +113,22 @@ uint32_t code_genstring(const char *str)
return off;
}
uint32_t code_cachedstring(const char *str)
{
size_t s = 0;
/* We could implement knuth-morris-pratt or something
* and also take substrings, but I'm uncomfortable with
* pointing to subparts of strings for the sake of clarity...
*/
while (s < code_chars_elements) {
if (!strcmp(str, code_chars_data + s))
return s;
while (code_chars_data[s]) ++s;
++s;
}
return code_genstring(str);
}
void code_test() {
prog_section_def d1 = { TYPE_VOID, 28, 1 };
prog_section_def d2 = { TYPE_FUNCTION, 29, 8 };

View file

@ -533,9 +533,10 @@ VECTOR_PROT(char, code_chars );
* code_write -- writes out the compiled file
* code_init -- prepares the code file
*/
bool code_write (const char *filename);
void code_init ();
uint32_t code_genstring (const char *string);
bool code_write (const char *filename);
void code_init ();
uint32_t code_genstring (const char *string);
uint32_t code_cachedstring(const char *string);
/*===================================================================*/
/*========================= assembler.c =============================*/