X-Authentication-Warning: kendall.sfbr.org: jeffw set sender to jeffw AT darwin DOT sfbr DOT org using -f Date: Tue, 30 Jan 2001 09:40:57 -0600 From: JT Williams To: djgpp-workers AT delorie DOT com Subject: Re: djasm patch #4 (enums) Message-ID: <20010130094057.A29026@kendall.sfbr.org> Mail-Followup-To: djgpp-workers AT delorie DOT com References: <20010128092849 DOT B27091 AT kendall DOT sfbr DOT org> <7458-Sun28Jan2001203011+0200-eliz AT is DOT elta DOT co DOT il> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <7458-Sun28Jan2001203011+0200-eliz@is.elta.co.il>; from eliz@is.elta.co.il on Sun, Jan 28, 2001 at 08:30:12PM +0200 Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk -: Please try to preserve the style of the original code (which is also -: used throughout in the library). Here is the reformatted patch to add support for enumeration types to djasm. --- djasm.y Thu Jan 25 16:11:57 2001 +++ /home/jeffw/tmp/bcurrie/djasm-bc/djasm/djasm.y Tue Jan 30 09:29:36 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 @@ $4->next=symtab; symtab=$4; } + | ENUM ID '\n' { struct_pc=0; + struct_sym=$2->name; + lineno++; + $$=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,29 @@ 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 +1795,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;