📄 nammgr.asm
字号:
TITLE NamMgr.asm - Name Table manager
;****************************************************************************
; Copyright <C> 1985, Microsoft Corporation
;Purpose:
; This module contains the routines necessary to create and manage the
; symbol name table. These routines are:
;
; CopyONamPb
; Copies the ASCII chars of a symbol from mrsCur.tNam.oNam.name
; to [pb]. The length of the string is returned.
;
; CopyONamBd
; Allocates a heap entry for the uninitialized Bd and then
; does a CopyONamPb to Bd.pb.
;
; GetVarNamChar
; Returns a first logical char of name and a flag which
; indicates whether the name starts with 'FN'.
;
; FlagOfONam
; Returns the raw symbol mask of mrsCur.tNam.oNam. This value
; can then be used to determine the various flag settings.
;
; LnOfONam
; If oNam is a line number offset
; THEN AX=mrsCur.tNam.oNam.LnW
; ELSE AX=UNDEFINED
;
; ONamOfPbCb
; Returns the offset of a symbol in mrsCur.tNam. If the symbol
; doesn't exist, then it is added. If a symbol match is found,
; but the case is different, then the new case is used to
; replace the old symbol.
;
; ONamOfPsd
; Returns the offset of a symbol in mrsCur.tNam. If the symbol
; doesn't exist, then it is added. If a symbol match is found,
; but the case is different, then the new case is used to
; replace the old symbol.
;
; ONamOfLn
; Returns the offset of a line number in mrsCur.tNam. If the
; line number doesn't exist, then it is added.
;
; ResetTNamMask
; Resets the all but the selected flag bits in all symbols of
; mrsCur.tNam (the symbol's flags are ANDed with the given
; byte mask).
;
; ResetONamMask
; Resets the maskW selected flag bits of mrsCur.tNam.oNam
; (The symbol's flags are ANDed with the NOT of maskW).
;
; SetONamMask
; Sets the maskW selected flag bits of mrsCur.tNam.oNam
; (The symbol's flags are ORed with maskW).
;
; SetONamSpace
; Sets the 2 "name space" bits of the flags byte to some
; NMSP_ value. Returns 0 if no error, or ER_DD if either of
; those bits were already set.
;
; CheckONamSpace
; Same error checking as SetONamSpace, but doesn't actually
; modify any namespace bits.
;
; TNamInit
; Initializes the symbol table (mrsCur.tNam).
;
; OgNamOfPsd
; Same as ONamOfPsd, but returns an ogNam.
; OgNamOfPbCb
; Same as OgNamOfPbCb, but returns an ogNam.
; CopyOgNamPb
; Same as CopyONamPb, but takes an ogNam instead of an oNam.
; CopyOgNamPbNear
; Same as CopyOgNamPb, but near rather than far interface.
; FpNamOfOgNam
; Given an ogNam, returns a far pointer to the name (in the
; actual table) and the length of the name.
; OgNamOfONam
; Given an oNam for the current module, returns the ogNam
; for this name.
; ONamOfOgNam
; Given an ogNam, returns the oNam for the current module
; for this name.
; CharOfOgNam
; Given an ogNam, returns the first char in the name.
; CbOfOgNam
; Given an ogNam, returns the length of the name.
; BdAppendOgNam
; Given an ogNam and a pBd, appends the name to the end of
; of the bd.
; CmpOgNamIns
; Given two ogNam's, performs a case-insensitive comparison
; of the two names.
; ogNamOfHst
; Same as OgNamOfPbCb, but accepts a hst as input instead of
; a pb and cb.
; hstNamOfOgNam
; Given an ogNam, returns a far pointer to a hst for the name.
;
; IsOgNamOfPbCb
; Given an string, return OgNam of string if it exists, but
; don't add the string if not found in the name table.
; IsONamOfPbCb
; Given an string, return ONam of string if it exists, but
; don't add the string if not found in the name table.
;
; The symbol table is refered to as tNam. It is a large far heap entry (and
; therefore restricted to 64K). The first part of tNam is a table of chain
; pointers that are used to select the chain to be searched. This is actually
; two such tables: the first (and larger one) is for all names except for
; line numbers, while the second is just for line numbers. A hashing function
; is applied to inputs to hash them into a given chain. Unknown symbols are
; added to the end of the appropriate chain.
;
; tNam structure:
;
; |-----------------------|
; | Chain Header Tables |
; |-----------------------|
; | Local variables |
; |-----------------------|
; | symbol chains |
; |-----------------------|
; | unused |
; |-----------------------|
;
; Chain Header Tables: (pointers are NULL if no entries in chain)
; pNameChain0 - first name chain
; pNameChain1
; pNameChain2
; .
; .
; pNameChain31 - last name chain
; pNameChain32 - first line number chain
; .
; .
; pNameChain39 - last line number chain
;
; Local Variables:
; CurONamHdr - current tNam 1st char index - used by GetNextONam
; cbUsed - # of bytes allocated to tables & entries
;
; Each element of a symbol chain has the following format:
;
; NextW - ptr to next symbol on chain (NULL if end of chain)
; FlagsB - symbol flag byte
; cbB - # of bytes in the 'name' field
; name - ASCII chars of symbol name (or binary value for line numbers)
;
; Each chain is terminated by a NULL Next. New symbols are added to the
; end of the appropriate chain. A symbol can never be deleted or moved.
; A symbol can't have more than CB_MAX_NAMENTRY chars. Each char in the
; name part of the symbol can be any valid ASCII (0-127) except the
; following:
; <Control Char> < ' > < { > < | > < } > < ~ > <DEL>
;
; Each module name table is limited to 32k. This limitation was imposed
; based on the pcode generated for opAsTypeExp; as of June '87 that's
; the only known reason for the limitation. In the (unlikely) event
; that the 32k limit is ever a problem, this pcode restriction could
; doubtless be removed.
;
;
;****************************************************************************
.xlist
NAMMGR_ASM = 1
include version.inc
includeOnce architec
includeOnce context
includeOnce heap
includeOnce names
includeOnce qbimsgs
includeOnce ui
includeOnce util
.list
assumes DS,DATA
assumes SS,DATA
assumes ES,NOTHING
sBegin DATA
globalW oRsNam,0 ;[10] used to access appropriate tNam
sEnd DATA
sBegin CP
assumes CS,CP
;***
;Use_GMrs
;Purpose:
; Added as part of revision [10].
;
; Set oRsNam to point to the global module so generic routines can be
; used to support the global name table.
;
; NOTE: Not all of the nammgr routines check for a non-zero offset in
; NOTE: oRsNam - - - only those that are currently used in conjunction
; NOTE: with a call to this routine. If you want to use this indirection
; NOTE: mechanism for some nammgr support routine, ensure that it will
; NOTE: access the name table via oRsNam.
;Entry:
; None.
;Exit:
; static oRsNam is an offset to the global name table in the Rs table.
;Preserves:
; AX, BX, DX
;Exceptions:
; none
;***************************************************************************
cProc Use_GMrs,<NEAR,NODATA>
cBegin Use_GMrs
DbAssertRel grs.GRS_oMrsCur,nz,OMRS_GLOBAL,CP,<Use_GMrs: global mrs is active>
sub cx,cx ; assume global mrs is active
cmp [grs.GRS_oMrsCur],OMRS_GLOBAL ;[23] is global mrs active?
jz Activate_Exit ; brif so
mov cx,MRS_bdlNam + OMRS_GLOBAL ;[23] offset in the global mrs
;[23] to the name table.
Activate_Exit:
mov [oRsNam],cx
cEnd Use_GMrs
;***
;FetchPNam
; Fetch a pointer to desired name table.
; If the static oRsNam is non-zero, it is assumed to contain an
; offset in the Rs table to the desired name table; otherwise, the
; desired name table is assumed to reside in mrsCur.
;
; Added as part of revision [10] to share/consolidate code, and
; to limit access to the mrs to a specific point.
;Purpose:
;Entry:
; none
;Exit:
; es:bx is a pointer to the appropriate bdlNam
;Uses:
; none
;***************************************************************************
cProc FetchPNam,<NEAR,NODATA>
cBegin
GETRS_SEG es,bx,<SIZE,LOAD> ;[25] NOTE: can trash bx?
mov bx,[oRsNam]
or bx,bx
jz Get_PMrs
RS_BASE add,bx
jmp short Got_PMrs
Get_PMrs:
SETSEG_EQ_SS es
mov bx,dataOFFSET mrsCur.MRS_bdlNam
Got_PMrs:
cEnd
;***
;LnOfONam LnW = LnOfONam
;Purpose:
; If given oNam is a line number offset
; THEN return AX=mrsCur.tNam.oNam.LnW
; ELSE return AX=UNDEFINED
;Register conventions:
; DS - Line# segment
; ES - tNam segment
;Entry:
; oNam on stack
; The following globals are referenced:
; mrsCur.bdlNam => current module's name table
;
;Exit:
; if oNam represents a binary line number,
; AX = line number
; else (oNam represents an alpha name)
; AX = UNDEFINED, DL = 1st letter of name
;
;Uses:
; none
;***************************************************************************
cProc LnOfONam,<PUBLIC,FAR,NODATA>
parmW oNam
cBegin
DbChk ConStatStructs
DbChk tNam
DbChk oNam,oNam ; sanity check on input oNam
GETSEG ES,[mrsCur.MRS_bdlNam_seg],,<LOAD,SIZE> ;[25]
mov bx,[oNam]
mov ax,ES:NM_NAME[bx] ;return the 16 bit line number
mov dx,ax ;dl = 1st letter of alpha name
test ES:NM_FLAGS[bx],byte ptr NM_fLineNum ;is it a line #
jne LnExit ;brif a line# - AX=line number
mov ax,UNDEFINED ;return UNDEFINED for alpha name
LnExit:
cEnd
;***
;ONamOfLn oNamW = ONamOfLn
;Purpose:
; To return the Name Table offset of a line number. If the line number
; isn't already in the Name Table, then it is added. Line numbers are
; kept in their own seperate chains in tNam. A '0' is returned in AX to
; indicate an error condition (out of memory, etc).
;
; NOTE: Shares a common exit with ONamOfPbCb, so these must have identical
; entries.
;Entry:
; AX = 16 bit line number
; The following globals are referenced
; mrsCur.bdlNam => current module's name table
;
;Exit:
; AX - Name table offset of LnW
; 0 is returned for error conditions (out of memory)
; DL = tNam.oNam.flags if AX != 0
; PSW flags set via an OR AX,AX on exit
;Uses:
; none
;Exceptions:
; none
;***************************************************************************
cProc ONamOfLn,<PUBLIC,NEAR,NODATA>,<DI>
LocalW pbName ; These locals match those in
LocalW cbName ; ONamOfPbCb because we share a
LocalW pNamCur ; common exit
LocalB fGrowTNam
LocalB fDontReplaceNam
LocalW lineNum
LocalV bdlTmp,<SIZE BDL>
cBegin
mov [lineNum],ax
lea ax,[lineNum] ;parm to ONamOfPbCb (ptr to 'name')
mov cx,2 ;parm to ONamOfPbCb (size of 'name')
mov di,LineNumHdr1st ;ptr to first line number hash chain
mov dl,7 ;only 8 chains for line numbers
mov bx,0FFFFH ;ensure we match only the correct number
jmp short ONamOf_Common
cEnd <nogen>
;***
;ONamOfPsd oNamW = ONamOfPsd(psdW)
;Purpose:
; To return the Name Table offset of a symbol. If the symbol isn't
; already in the Name Table, then it is added. The symbol's case is
; preserved in tNam , but it is ignored while searching for a match
; (FoO is the same as fOo). If the cases don't match exactly, then the
; new symbol will replace the old one in tNam. A 0 is returned in AX
; to indicate an error condition (out of memory, etc).
;
; NOTE: shares code with and exits via ONamOfPbCb.
;Assumptions:
; )symbols can never be removed from tNam
; )Each char in the name part of the symbol can be any valid
; ASCII (0-127) except the following:
; <Control Char> < ' > < { > < | > < } > < ~ > <DEL>
; )0 < cb < CB_MAX_NAMENTRY
;Entry:
; The stack contains the following parameters (PLM calling convention)
; ParmW - ptr to a string descriptor
; The following globals are referenced
; mrsCur.bdlNam => current module's name table
;
;Exit:
; AX - Name table offset of name in psd
; 0 is returned for error conditions (out of memory)
; DL = tNam.oNam.flags if AX != 0
; PSW flags set via an OR AX,AX on exit
;Uses:
; none
;Exceptions:
; none
;***************************************************************************
cProc ONamOfPsd,<PUBLIC,NEAR,NODATA>
cBegin <nogen>
pop dx ;return address to caller
pop bx ;psd parm passed by caller
mov ax,[bx.BD_pb] ;ptr to string contents
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -