From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Dall To: gas2@cygnus.com Subject: Target dependent frag fields (proposed change) Date: Tue, 04 Nov 1997 05:56:00 -0000 Message-id: <199711041355.AAA14448@sibyl.chez-dall.org.au> X-SW-Source: 1997/msg00021.html Following the comments in as.h, I decided to have a look at making the fields needed for the ns32k configurable. This turned out to not be very hard. Basically the problem is that you would want targ-*.h to define TC_FRAG_TYPE (like TC_FIX_TYPE for the fix structure), but the targ-*.h use the frag structure quite a bit so it has to be defined before the targ-*.h. The solution to to have an incomplete definition struct frag; before including the targ-*.h and defer a complete definition until afterwards. I don't have the resources to test this for all targets, but it works for the ns32k and looks safe for other targets. Ian ChangeLog Entry: Wed Nov 5 00:00:20 1997 Ian Dall * as.h: Move struct frag definition to after targ-*.h is included. Leave incomplete definition at old place. (struct frag): Add TC_FRAG_TYPE analagously to TC_FIX_TYPE. * config/tc-ns32k.h (TC_FRAG_TYPE): Define to contain ns32k target dependent frag fields. (frag_opcode_frag, frag_opcode_offset, frag_bsr): change to reflect TC_FRAG_TYPE definition. Patch: diff -rc ../gas-build/gas/as.h ./gas/as.h *** ../gas-build/gas/as.h Wed Oct 29 22:57:20 1997 --- ./gas/as.h Tue Nov 4 22:45:52 1997 *************** *** 395,472 **** typedef addressT relax_addressT; ! /* frags.c */ ! ! /* ! * A code fragment (frag) is some known number of chars, followed by some ! * unknown number of chars. Typically the unknown number of chars is an ! * instruction address whose size is yet unknown. We always know the greatest ! * possible size the unknown number of chars may become, and reserve that ! * much room at the end of the frag. ! * Once created, frags do not change address during assembly. ! * We chain the frags in (a) forward-linked list(s). The object-file address ! * of the 1st char of a frag is generally not known until after relax(). ! * Many things at assembly time describe an address by {object-file-address ! * of a particular frag}+offset. ! ! BUG: it may be smarter to have a single pointer off to various different ! notes for different frag kinds. See how code pans ! */ ! typedef struct frag fragS; - struct frag - { - /* Object file address. */ - addressT fr_address; - /* Chain forward; ascending address order. Rooted in frch_root. */ - struct frag *fr_next; - - /* (Fixed) number of chars we know we have. May be 0. */ - offsetT fr_fix; - /* (Variable) number of chars after above. May be 0. */ - offsetT fr_var; - /* For variable-length tail. */ - struct symbol *fr_symbol; - /* For variable-length tail. */ - offsetT fr_offset; - /* Points to opcode low addr byte, for relaxation. */ - char *fr_opcode; - - #ifndef NO_LISTING - struct list_info_struct *line; - #endif - - /* What state is my tail in? */ - relax_stateT fr_type; - relax_substateT fr_subtype; - - union { - /* These are needed only on the NS32K machines. But since we don't - include targ-cpu.h until after this structure has been defined, - we can't really conditionalize it. This code should be - rearranged a bit to make that possible. */ - struct { - fragS *fr_opcode_fragP; - unsigned int fr_opcode_offset; - char fr_bsr; - } fr_ns32k; - #ifdef USING_CGEN - /* Don't include this unless using CGEN to keep frag size down. */ - struct { - const struct cgen_insn *insn; - unsigned char opindex, opinfo; - } cgen; - #endif - } fr_targ; - - /* Where the frag was created, or where it became a variant frag. */ - char *fr_file; - unsigned int fr_line; - - /* Data begins here. */ - char fr_literal[1]; - }; #define SIZEOF_STRUCT_FRAG \ ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag) --- 395,404 ---- typedef addressT relax_addressT; ! struct frag; /* Complete definition after target ! dependent includes */ typedef struct frag fragS; #define SIZEOF_STRUCT_FRAG \ ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag) *************** *** 656,661 **** --- 588,660 ---- /* this one starts the chain of target dependant headers */ #include "targ-env.h" + + /* frags.c */ + + /* + * A code fragment (frag) is some known number of chars, followed by some + * unknown number of chars. Typically the unknown number of chars is an + * instruction address whose size is yet unknown. We always know the greatest + * possible size the unknown number of chars may become, and reserve that + * much room at the end of the frag. + * Once created, frags do not change address during assembly. + * We chain the frags in (a) forward-linked list(s). The object-file address + * of the 1st char of a frag is generally not known until after relax(). + * Many things at assembly time describe an address by {object-file-address + * of a particular frag}+offset. + + BUG: it may be smarter to have a single pointer off to various different + notes for different frag kinds. See how code pans + */ + + struct frag + { + /* Object file address. */ + addressT fr_address; + /* Chain forward; ascending address order. Rooted in frch_root. */ + struct frag *fr_next; + + /* (Fixed) number of chars we know we have. May be 0. */ + offsetT fr_fix; + /* (Variable) number of chars after above. May be 0. */ + offsetT fr_var; + /* For variable-length tail. */ + struct symbol *fr_symbol; + /* For variable-length tail. */ + offsetT fr_offset; + /* Points to opcode low addr byte, for relaxation. */ + char *fr_opcode; + + #ifndef NO_LISTING + struct list_info_struct *line; + #endif + + /* What state is my tail in? */ + relax_stateT fr_type; + relax_substateT fr_subtype; + + #ifdef TC_FRAG_TYPE + TC_FRAG_TYPE tc_frag_data; + #endif + + #ifdef USING_CGEN + /* Don't include this unless using CGEN to keep frag size down. + Change tc file to use TC_FRAG_TYPE */ + union { + struct { + const struct cgen_insn *insn; + unsigned char opindex, opinfo; + } cgen; + } fr_targ; + #endif + + /* Where the frag was created, or where it became a variant frag. */ + char *fr_file; + unsigned int fr_line; + + /* Data begins here. */ + char fr_literal[1]; + }; #include "struc-symbol.h" #include "write.h" diff -rc ../gas-build/gas/config/tc-ns32k.h ./gas/config/tc-ns32k.h *** ../gas-build/gas/config/tc-ns32k.h Wed Oct 29 22:57:23 1997 --- ./gas/config/tc-ns32k.h Mon Nov 3 23:30:53 1997 *************** *** 102,128 **** #define TC_FIX_DATA_PRINT(FILE, TC_FIX) \ ! do \ ! { \ ! fprintf((FILE), "\nopcode_frag=%p operand offset=%d, \ ! bsr=%d" , (TC_FIX).opcode_fragP, (TC_FIX).opcode_offset, \ ! (TC_FIX).bsr); \ ! } \ ! while(0) #define TC_FRAG_INIT(X) \ ! do \ ! { \ ! frag_opcode_frag(X) = NULL; \ ! frag_opcode_offset(X) = 0; \ ! frag_bsr(X) = 0; \ ! } \ ! while(0) /* Accessor macros for things which may move around */ ! #define frag_opcode_frag(X) (X)->fr_targ.fr_ns32k.fr_opcode_fragP ! #define frag_opcode_offset(X) (X)->fr_targ.fr_ns32k.fr_opcode_offset ! #define frag_bsr(X) (X)->fr_targ.fr_ns32k.fr_bsr #define TC_FIX_TYPE \ struct \ --- 102,135 ---- #define TC_FIX_DATA_PRINT(FILE, TC_FIX) \ ! do \ ! { \ ! fprintf((FILE), "\nopcode_frag=%p operand offset=%d, bsr=%d", \ ! (TC_FIX).opcode_fragP, (TC_FIX).opcode_offset, (TC_FIX).bsr); \ ! } \ ! while(0) #define TC_FRAG_INIT(X) \ ! do \ ! { \ ! frag_opcode_frag(X) = NULL; \ ! frag_opcode_offset(X) = 0; \ ! frag_bsr(X) = 0; \ ! } \ ! while(0) ! ! #define TC_FRAG_TYPE \ ! struct { \ ! fragS *fr_opcode_fragP; \ ! unsigned int fr_opcode_offset; \ ! char fr_bsr; \ ! } ! /* Accessor macros for things which may move around */ ! #define frag_opcode_frag(X) (X)->tc_frag_data.fr_opcode_fragP ! #define frag_opcode_offset(X) (X)->tc_frag_data.fr_opcode_offset ! #define frag_bsr(X) (X)->tc_frag_data.fr_bsr #define TC_FIX_TYPE \ struct \