delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/01/28/10:26:49

X-Authentication-Warning: kendall.sfbr.org: jeffw set sender to jeffw AT darwin DOT sfbr DOT org using -f
Date: Sun, 28 Jan 2001 09:28:49 -0600
From: JT Williams <jeffw AT darwin DOT sfbr DOT org>
To: djgpp-workers AT delorie DOT com
Subject: djasm patch #4 (enums)
Message-ID: <20010128092849.B27091@kendall.sfbr.org>
Mail-Followup-To: djgpp-workers AT delorie DOT com
Mime-Version: 1.0
User-Agent: Mutt/1.2.5i
Reply-To: djgpp-workers AT delorie DOT com

This patch adds support for enumeration types to djasm, in addition to
the structure and union types.  I will post a separate patch to update
the documentation accordingly.

-- 
jtw


--- djasm.y	Thu Jan 25 16:11:57 2001
+++ /home/jeffw/tmp/bcurrie/djasm-bc/djasm/djasm.y	Sat Jan 27 14:52:09 2001
@@ -139,6 +138,7 @@
 
 void destroy_symbol(Symbol *sym, int undef_error);
 void destroy_locals(void);
+void add_enum_element(Symbol *s);
 void add_struct_element(Symbol *s);
 void emit_struct(Symbol *ele, int tp, Symbol *struc);
 void emit_struct_abs(Symbol *ele, int tp, Symbol *struc, int offset);
@@ -234,7 +234,8 @@
 %token ALIGN ARPL
 %token BOUND BSS BSF BSR
 %token CALL CALLF CALLFD COPYRIGHT
-%token DB DD DEC DECB DECD DECW DUP DW ENDS ENTER
+%token DB DD DEC DECB DECD DECW DUP DW
+%token ENDS ENUM ENTER
 %token IN INC INCB INCD INCW INT INCLUDE
 %token JMPW JMPB JMPF JMPFD
 %token LAR LEA LINKCOFF LSL
@@ -340,7 +341,8 @@
   {".dd", DD, NO_ATTR},
   {".dup", DUP, NO_ATTR},
   {".dw", DW, NO_ATTR},
-  {".ends",ENDS, NO_ATTR},
+  {".ends", ENDS, NO_ATTR},
+  {".enum", ENUM, NO_ATTR},
   {".id", RCS_ID, NO_ATTR},
   {".include", INCLUDE, NO_ATTR},
   {".linkcoff", LINKCOFF, NO_ATTR},
@@ -669,6 +697,15 @@
 					  $<sym>4->next=symtab;
 					  symtab=$<sym>4;
 	  				}
+	| ENUM ID '\n'			{ struct_pc=0;
+					  struct_sym=$2->name;
+					  lineno++;
+					  $<sym>$=symtab;
+					  if (symtab==$2)
+					      symtab=symtab->next;
+					}
+	  enum_lines
+	  ENDS
 	| ID STRUCT ID			{ emit_struct($1,$2,$3); }
 	| ID STRUCT ID '(' const ')'	{ emit_struct_abs($1,$2,$3,$5); }
 	| error
@@ -1073,6 +1157,17 @@
 	  struct_db
 	;
 
+enum_lines
+	:
+	| enum_lines enum_line '\n' { lineno++; }
+	;
+
+enum_line
+	:
+	| ID				{ add_enum_element($1); }
+	| ID '=' const			{ struct_pc = $3; add_enum_element($1); }
+	;
+
 struct_db
 	: DB				{ if (struct_tp=='s') {
 					      struct_pc++;
@@ -1241,6 +1336,7 @@
 	| '-' const			{ $$ = -$2; }
 	| 				{ $$ = 0; }
 	;
+
 %% /***********************************************************************/
 
 typedef struct FileStack {
@@ -1611,6 +1729,23 @@
   return s;
 }
 
+void add_enum_element(Symbol *s)
+{
+  if (islocal(s->name) || istemp(s->name,0)) {
+    djerror("Cannot have local or temporary labels within an enum");
+  } else {
+    char *id=alloca(strlen(s->name)+strlen(struct_sym)+2);
+    strcpy(id,struct_sym);
+    strcat(id,".");  /* should this be "_" to disambiguate enums from structs? */
+    strcat(id,s->name);
+    if (!s->defined && !s->patches) {
+      /* only delete fresh symbols */
+      destroy_symbol(s,0);
+    }
+    set_symbol(get_symbol(id,1),struct_pc++);
+  }
+}
+
 void add_struct_element(Symbol *s)
 {
   if (islocal(s->name) || istemp(s->name,0)) {
@@ -1654,10 +1789,6 @@
 
 int set_structure_symbols(Symbol *ele, Symbol *struc, int tp, int base, int type)
 {
-  if (tp!='s') {
-    djerror("must use `.struct' to emit structures or unions");
-    return 0;
-  }
   if (!struc->defined) {
     djerror("undefined symbol used in struct");
     return 0;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019