]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
argsize parsing for assembler
authorDale Weiler <killfieldengine@gmail.com>
Wed, 2 May 2012 19:48:00 +0000 (15:48 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Wed, 2 May 2012 19:48:00 +0000 (15:48 -0400)
asm.c
code.c
data/test.qs

diff --git a/asm.c b/asm.c
index 4f7e396a0d7cb8ae0308fb738c0a1d980725265b..adb7678abd0a43653b2a3c164347a84a221fe559 100644 (file)
--- a/asm.c
+++ b/asm.c
@@ -284,6 +284,7 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state
              * the `#` (pound sign).
              */
             int   args = 0;
+            int   size = 0;
             char *find = strchr(name, '#');
             char *peek = find;
             
@@ -305,7 +306,7 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state
                  * invalid and shouldn't be allowed.  The QuakeC VM only
                  * allows a maximum of eight arguments.
                  */
-                if (strlen(find) > 1 || *find == '9') {
+                if (*find == '9') {
                     printf("invalid number of arguments, must be a valid number from 0-8\n");
                     mem_d(copy);
                     mem_d(name);
@@ -325,8 +326,37 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state
                         case '2': args++; case '1': args++;
                     }
                 }
+                /*
+                 * We need to parse the argument size now by determining
+                 * the argument identifer list used after the amount of
+                 * arguments.
+                 */
+                memset(function.argsize, 0, sizeof(function.argsize));
+                find ++; /* skip the number */
+                while (*find == ' ' || *find == '\t') find++;
+                while (size < args) {
+                    switch (*find) {
+                        case 'V': case 'v': function.argsize[size]=3; break;
+                        case 'S': case 's':
+                        case 'F': case 'f':
+                        case 'E': case 'e': function.argsize[size]=1; break;
+                        case '\0':
+                            printf("missing argument identifer, expected %d\n", args);
+                            return false;
+                        default:
+                            printf("error invalid function argument identifier\n");
+                            return false;
+                    }
+                    size++,find++;
+                }
+                while (*find == ' ' || *find == '\t') find++;
+                if (*find != '\0') {
+                    printf("too many function argument identifers expected %d\n", args);
+                    return false;
+                }
             } else {
                 printf("missing number of argument count in function %s\n", name);
+                return false;
             }
 
             /*
@@ -360,7 +390,6 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state
             def.type            = TYPE_FUNCTION;
             def.offset          = code_globals_elements;
             def.name            = code_chars_elements;
-            memset(function.argsize, 0, sizeof(function.argsize));
             code_functions_add(function);
             code_globals_add(code_statements_elements);
             code_chars_put    (name, strlen(name));
diff --git a/code.c b/code.c
index fe0833eb598f2d1e233ecff16e777bf0ca1468fa..4c35b32843d34a399b8b9f2aba5b1d4757f9a452 100644 (file)
--- a/code.c
+++ b/code.c
@@ -208,7 +208,7 @@ void code_write() {
     util_debug("GEN", "FUNCTIONS:\n");
     for (; it < code_functions_elements; it++) {
         size_t j = code_functions_data[it].entry;
-        util_debug("GEN", "    {.entry =% 5d, .firstlocal =% 5d, .locals =% 5d, .profile =% 5d, .name =% 5d, .file =% 5d, .nargs =% 5d, .argsize =%0X }\n",
+        util_debug("GEN", "    {.entry =% 5d, .firstlocal =% 5d, .locals =% 5d, .profile =% 5d, .name =% 5d, .file =% 5d, .nargs =% 5d, .argsize ={%d,%d,%d,%d,%d,%d,%d,%d} }\n",
             code_functions_data[it].entry,
             code_functions_data[it].firstlocal,
             code_functions_data[it].locals,
@@ -216,7 +216,15 @@ void code_write() {
             code_functions_data[it].name,
             code_functions_data[it].file,
             code_functions_data[it].nargs,
-            *((int32_t*)&code_functions_data[it].argsize)
+            code_functions_data[it].argsize[0],
+            code_functions_data[it].argsize[1],
+            code_functions_data[it].argsize[2],
+            code_functions_data[it].argsize[3],
+            code_functions_data[it].argsize[4],
+            code_functions_data[it].argsize[5],
+            code_functions_data[it].argsize[6],
+            code_functions_data[it].argsize[7]
+            
         );
         util_debug("GEN", "    NAME: %s\n", &code_chars_data[code_functions_data[it].name]);
         /* Internal functions have no code */
index b714ba1f3949bce03542663fc47532fe0871b0ee..0852b5015f50711b8e22afd711de27cf5784432c 100644 (file)
@@ -89,14 +89,13 @@ FUNCTION: checkextension, $99
 ;code_chars_put("m_toggle",      0x8);
 ;code_chars_put("m_shutdown",    0xA);
 
-FUNCTION: m_init     #1
+FUNCTION: m_init     #3VVV    
        DONE
-FUNCTION: m_keydown  #1
+FUNCTION: m_keydown  #1S
        DONE
-FUNCTION: m_draw     #1
+FUNCTION: m_draw     #1S
        DONE
-FUNCTION: m_toggle   #1
-       DONE
-FUNCTION: m_shutdown #1
+FUNCTION: m_toggle   #1S
        DONE
+FUNCTION: m_shutdown #1S