]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - asm.c
Working on the assembler
[xonotic/gmqcc.git] / asm.c
diff --git a/asm.c b/asm.c
index 2fd10046034b939d05f0d938b8ab78ee56205b4d..1ab8275836d5ed4d821a7e3ed7aa17f709629437 100644 (file)
--- a/asm.c
+++ b/asm.c
@@ -78,132 +78,20 @@ void asm_clear() {
     mem_d(assembly_constants_data);
 }
 
-int asm_parsetype(const char *key, char **skip, long line) {
-    size_t keylen = strlen(key);
-    if (!strncmp(key, *skip, keylen)) {
-        if ((*skip)[keylen] != ':'){
-            printf("%li: Missing `:` after decltype\n", line);
-            exit(1);
-        }
-        *skip += keylen+1;
-        /* skip whitespace */
-        while (**skip == ' ' || **skip == '\t')
-            (*skip)++;
-        
-        if (!isalpha(**skip)) {
-            printf("%li: Invalid identififer: %s\n", line, *skip);
-            exit(1);
-        } else {
-            assembly_constants_add((globals) {
-                .name   = util_strdup("empty"),
-                .offset = code_globals_elements
-            });
-            return 1;
-        }
-    }
-    return 0;
-}
-
 void asm_parse(FILE *fp) {
     char     *data  = NULL;
-    char     *skip  = NULL;
     long      line  = 1; /* current line */
     size_t    size  = 0; /* size of line */
     asm_state state = ASM_NULL;
     
-    while ((data = skip = asm_getline(&size, fp)) != NULL) {
-        /* remove any whitespace at start  */
-        while (*skip == ' ' || *skip == '\t')
-            skip++;
-        /* remove newline at end of string */
-        *(skip+*(&size)-1) = '\0';
-        
-        if (asm_parsetype(asm_keys[5], &skip, line)) {
-            if (state != ASM_NULL) {
-                printf("%li: Error unfinished function block, expected DONE or RETURN\n", line);
-                goto end;
-            }
-            state = ASM_FUNCTION;
-            code_defs_add((prog_section_def){
-                .type   = TYPE_VOID,
-                .offset = code_globals_elements,
-                .name   = code_chars_elements
-            });
-            code_globals_add(code_functions_elements);
-            code_functions_add((prog_section_function) {
-                .entry      =  code_statements_elements,      
-                .firstlocal =  0,
-                .locals     =  0,
-                .profile    =  0,
-                .name       =  code_chars_elements,
-                .file       =  0,
-                .nargs      =  0,
-                .argsize    = {0}
-            });
-            code_chars_put(skip, strlen(skip));
-        };
+    while ((data = asm_getline(&size, fp)) != NULL) {
+        data = util_strsws(data); /* skip   whitespace */
+        data = util_strrnl(data); /* delete newline    */
 
-        #if 0
-        /* if we make it this far then we have statements */
-        {
-            size_t i = 0;    /* counter   */
-            size_t o = 0;    /* operands  */
-            size_t c = 0;    /* copy      */
-            char  *t = NULL; /* token     */
-            
-            /*
-             * Most ops a single statement can have is three.
-             * lets allocate some space for all of those here.
-             */
-            char op[3][32768] = {{0},{0},{0}};
-            for (; i < sizeof(asm_instr)/sizeof(*asm_instr); i++) {
-                if (!strncmp(skip, asm_instr[i].m, asm_instr[i].l)) {
-                    if (state != ASM_FUNCTION) {
-                        printf("%li: Statement not inside function block\n", line);
-                        goto end;
-                    }
-                    
-                    /* update parser state */
-                    if (i == INSTR_DONE || i == INSTR_RETURN) {
-                        goto end;
-                        state = ASM_NULL;
-                    }
-                    
-                    /* parse the statement */
-                    c     = i;
-                    o     = asm_instr[i].o; /* operands         */
-                    skip += asm_instr[i].l; /* skip instruction */
-                    t     = strtok(skip, " ,");
-                    i     = 0;
-                    while (t != NULL && i < 3) {
-                        strcpy(op[i], t);
-                        t = strtok(NULL, " ,");
-                        i ++;
-                    }
-                    
-                    /* check */
-                    if (i != o) {
-                        printf("not enough operands, expected: %li, got %li\n", o, i);
-                    }
-                    
-                    /* TODO: hashtable value LOAD .... etc */
-                    code_statements_add((prog_section_statement){
-                        c,
-                        { atof(op[0]) },
-                        { atof(op[1]) },
-                        { atof(op[2]) }
-                    });
-                    goto end;
-                }
-            }
-        }
-        #endif
-        
-        /* if we made it this far something is wrong */
-        if (*skip != '\0')
-            printf("%li: Invalid statement %s, expression, or decleration\n", line, skip);
-        
-        end:
+        /* TODO: everything */
+        (void)state;
+        goto end;
+    end:
         mem_d(data);
         line ++;
     }