Mail Archives: djgpp-workers/2001/02/01/11:40:03
OK ?
(I'll eventually post a complementary patch for djasm.txi, not
only to document .enum, but also to add rudimentary indexes.)
--
jtw
Index: wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.45
diff -p -3 -r1.45 wc204.txi
*** wc204.txi 2001/02/01 15:51:44 1.45
--- wc204.txi 2001/02/01 16:34:40
*************** of executables to zero (meaning not used
*** 245,247 ****
--- 245,250 ----
Allow one to allocate space in @code{djasm} using @code{.union}
(instead of @code{.struct}) when using a union. As there is no
checking, @code{.struct} and @code{.union} are interchangeable.
+
+ @pindex djasm AT r{, enumeration type}
+ Enumeration type added to @code{djasm}.
Index: djasm.y
===================================================================
RCS file: /cvs/djgpp/djgpp/src/stub/djasm.y,v
retrieving revision 1.7
diff -p -3 -r1.7 djasm.y
*** djasm.y 2001/02/01 15:52:28 1.7
--- djasm.y 2001/02/01 16:34:52
*************** int undefs = 0;
*** 139,144 ****
--- 139,145 ----
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);
*************** void write_MODEND(FILE *outfile, int mai
*** 234,240 ****
%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 IN INC INCB INCD INCW INT INCLUDE
%token JMPW JMPB JMPF JMPFD
%token LAR LEA LINKCOFF LSL
--- 235,242 ----
%token ALIGN ARPL
%token BOUND BSS BSF BSR
%token CALL CALLF CALLFD COPYRIGHT
! %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
*************** struct opcode opcodes[] = {
*** 340,346 ****
{".dd", DD, NO_ATTR},
{".dup", DUP, NO_ATTR},
{".dw", DW, NO_ATTR},
! {".ends",ENDS, NO_ATTR},
{".id", RCS_ID, NO_ATTR},
{".include", INCLUDE, NO_ATTR},
{".linkcoff", LINKCOFF, NO_ATTR},
--- 342,349 ----
{".dd", DD, NO_ATTR},
{".dup", DUP, NO_ATTR},
{".dw", DW, NO_ATTR},
! {".ends", ENDS, NO_ATTR},
! {".enum", ENUM, NO_ATTR},
{".id", RCS_ID, NO_ATTR},
{".include", INCLUDE, NO_ATTR},
{".linkcoff", LINKCOFF, NO_ATTR},
*************** line
*** 669,674 ****
--- 672,686 ----
$<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
*************** struct_line
*** 1073,1078 ****
--- 1085,1101 ----
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++;
*************** offset
*** 1241,1246 ****
--- 1264,1270 ----
| '-' const { $$ = -$2; }
| { $$ = 0; }
;
+
%% /***********************************************************************/
typedef struct FileStack {
*************** Symbol *get_symbol(char *name, int creat
*** 1609,1614 ****
--- 1633,1661 ----
s->first_used = lineno;
s->type = SYM_unknown;
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)
- Raw text -