changeset 258:23d6a8deb2d6

[project @ 2003-04-28 21:23:53 by bellard] various asm directives - char support (Dave Long)
author bellard
date Mon, 28 Apr 2003 21:23:53 +0000
parents 9aefaa6735e3
children 1835379353e4
files tccasm.c tcctok.h
diffstat 2 files changed, 83 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tccasm.c	Sun Apr 27 11:46:10 2003 +0000
+++ b/tccasm.c	Mon Apr 28 21:23:53 2003 +0000
@@ -85,6 +85,12 @@
         else
             pe->v = ~pe->v;
         break;
+    case TOK_CCHAR:
+    case TOK_LCHAR:
+	pe->v = tokc.i;
+	pe->sym = NULL;
+	next();
+	break;
     default:
         if (tok >= TOK_IDENT) {
             /* label case : if the label was not found, add one */
@@ -276,6 +282,15 @@
     st->asm_labels = NULL;
 }
 
+static void use_section(TCCState *s1, const char *name)
+{
+    Section *sec;
+    sec = find_section(s1, name);
+    cur_text_section->data_offset = ind;
+    cur_text_section = sec;
+    ind = cur_text_section->data_offset;
+}
+
 static void asm_parse_directive(TCCState *s1)
 {
     int n, offset, v, size, tok1;
@@ -346,8 +361,69 @@
             next();
         }
         break;
+    case TOK_ASM_globl:
+	{ 
+            Sym *sym;
+
+            next();
+            sym = label_find(tok);
+            if (!sym) {
+                sym = label_push(&s1->asm_labels, tok, 0);
+                sym->type.t = VT_VOID;
+            }
+            sym->type.t &= ~VT_STATIC;
+            next();
+	}
+	break;
+    case TOK_ASM_string:
+        {
+            const uint8_t *p;
+            int i;
+
+            next();
+            if (tok != TOK_STR)
+                expect("string constant");
+            p = tokc.cstr->data;
+            for(i = 0; i < tokc.cstr->size; i++)
+                g(p[i]);
+            next();
+	}
+	break;
+    case TOK_ASM_text:
+    case TOK_ASM_data:
+    case TOK_ASM_bss:
+	{ 
+            char sname[64];
+            tok1 = tok;
+            n = 0;
+            next();
+            if (tok != ';' && tok != TOK_LINEFEED) {
+		n = asm_int_expr(s1);
+		next();
+            }
+            sprintf(sname, (n?".%s%d":".%s"), get_tok_str(tok1, NULL), n);
+            use_section(s1, sname);
+	}
+	break;
+    case TOK_SECTION1:
+        {
+            char sname[256];
+
+            /* XXX: support more options */
+            next();
+            sname[0] = '\0';
+            while (tok != ';' && tok != TOK_LINEFEED && tok != ',') {
+                if (tok == TOK_STR)
+                    pstrcat(sname, sizeof(sname), tokc.cstr->data);
+                else
+                    pstrcat(sname, sizeof(sname), get_tok_str(tok, NULL));
+                next();
+            }
+            use_section(s1, sname);
+        }
+        break;
     default:
-        error("unknown assembler directive .%s", get_tok_str(tok, NULL));
+        error("unknown assembler directive '.%s'", get_tok_str(tok, NULL));
         break;
     }
 }
--- a/tcctok.h	Sun Apr 27 11:46:10 2003 +0000
+++ b/tcctok.h	Mon Apr 28 21:23:53 2003 +0000
@@ -144,12 +144,17 @@
      DEF(TOK_strcpy, "strcpy")
 #endif
 
-/* Tiny Assembler for x86 */
+/* Tiny Assembler */
 
  DEF_ASM(byte)
  DEF_ASM(align)
  DEF_ASM(skip)
  DEF_ASM(space)
+ DEF_ASM(string)
+ DEF_ASM(globl)
+ DEF_ASM(text)
+ DEF_ASM(data)
+ DEF_ASM(bss)
 
 #ifdef TCC_TARGET_I386