The MASM Forum

General => The Campus => Topic started by: jimg on February 23, 2020, 02:26:56 AM

Title: variable usage list
Post by: jimg on February 23, 2020, 02:26:56 AM
Before I reinvent the wheel, does anyone know of a utility to provide a listing of variables used in a masm program, and all the lines they are used on?

It been at least two decades since I've done such a thing using the old ProgrammersWorkBench source browser.

If not it wouldn't be too hard to modify my tidy program, but I'd rather spend my time elsewhere if such a thing exists.  Google was no help to me.
Title: Re: variable usage list
Post by: jj2007 on February 23, 2020, 03:12:09 AM
That rings a bell, but I can't find my source any more. What exactly do you want to achieve?

If you are just looking for specific variables, RichMasm's find listbox is an option - see the upper right corner. Given that MASM is case-sensitive, uncheck the case box and check the FW (full word). The list can be exported with Ctrl C.

(http://www.jj2007.eu/pics/RmGuide.jpg)
Title: Re: variable usage list
Post by: daydreamer on February 23, 2020, 03:18:43 AM
Quote from: jimg on February 23, 2020, 02:26:56 AM
Before I reinvent the wheel, does anyone know of a utility to provide a listing of variables used in a masm program, and all the lines they are used on?

It been at least two decades since I've done such a thing using the old ProgrammersWorkBench source browser.

If not it wouldn't be too hard to modify my tidy program, but I'd rather spend my time elsewhere if such a thing exists.  Google was no help to me.
I have VC++ and there you can get some performance analyze tools,you can choose,cputest,memtest,gputest
I think it tests different functions(PROC's name in C++) how freqently they are called to help programmer identify where for example 80%+ execution is happening so s/he can concentrate on optimize those functions instead of whole program,maybe memtest checks how freqently mem variables are used is the closest thing I can think of
Title: Re: variable usage list
Post by: jimg on February 23, 2020, 03:19:46 AM
Thanks jj.

I was just turning a large program into a small program that does much less, and wanted to delete all the variables that were no longer used.  In the old days, compilers would routinely give you a list of variables declared but not used.  I can search for each one, one at a time, but I thought there must be a program out there that does it these days for a masm program.
Title: Re: variable usage list
Post by: jj2007 on February 23, 2020, 04:04:55 AM
Do a find and replace for LOCAL -> ; LOCAL, then assemble the program, and you'll get a list of the variables used :thumbsup:

Post that source, it could be fun:
- look for all instances of endp (case-insensitive, full word)
- for each match, go up until you find the corresponding proc
- get a list of the locals, and check for each variable if they appear between the line after the last local and the endp
Title: Re: variable usage list
Post by: jimg on February 23, 2020, 04:27:38 AM
Just for you Jochen.

This is my findall program stripped down to be a super dir program.  So far I have just stripped out the stuff I didn't need and got it working so it produces a listing of files that meet the name criteria and the size of the file.  I haven't added any of the new stuff, e.g. filter on attributes, times, etc.
But here it is if you think it will be fun.  I'll leave it up for a day or so.  Bear in mind, this is a work in progress and currently a real mess.
edit: dead link deleted.
Title: Re: variable usage list
Post by: jj2007 on February 23, 2020, 05:22:23 AM
Thanks, Jim. In the meantime, I found my plugin:
- extract the DLL to \Masm32\MasmBasic\Plugins\AnalyseVariableUse.dll
- start \Masm32\MasmBasic\RichMasm.exe
- open a source
- goto menu System & plugins, Analyse variable use

Example output:
0617 chrg
0097 wParam
0086 hWnd
0060 lParam
0047 hwnd
0047 hFind
0045 msg
0044 hList
0038 hPipeEdit
0033 Utf8
0032 LcBuffer
...
0002 bubY
0002 BmText
0002 AddInOlly
0002 ActivateAs
0001 upRes3
0001 upRes2
0001 txThisIsJJ
0001 txInvoke
0001 txFont
0001 txErrCPro
0001 txCWC
0001 txAutoCode
0001 txAsmBcw
0001 tfRes2
0001 tfRes1
0001 SnippetTitle
0001 SLmy2
0001 SLmx2
0001 SigSize
0001 SigPattern
0001 SigMask
0001 SigCount
0001 ShowMSG
0001 rPiStart
0001 rPiSrcType
0001 rPiRepl
0001 rPiPipe
0001 rPiPath
0001 rPiOptions
0001 rPiNumBm
0001 rPiLen
0001 rPiFind
0001 rPiDirty
0001 rPiContent
0001 rPiBook
0001 rPiAux
0001 pvReserved
0001 pszFile
0001 prtMarginsMM
0001 pcFlag
0001 opStatic
0001 NullEnv
0001 NotificationUnhook
0001 NotificationHook
0001 nMaxFileTitle
0001 nMaxCustFilter
0001 nFileOffset
0001 MyPublicBuffer
0001 MyLocalBuffer
0001 MimeType
0001 lspTimeout
0001 lspCurPipe
0001 lspBufferStart
0001 lspBufferEnd
0001 lpThreadId
0001 lpTemplateName
0001 lpstrCustomFilter
0001 LocName
0001 ListRC
0001 lCustData
0001 LastVar
0001 LastMy
0001 jwDate
0001 jjMagic9
0001 jjMagic8
0001 jjMagic7
0001 jjMagic6
0001 jjct
0001 jfText
0001 jfLen
0001 ItemID
0001 infHist2
0001 hWriteIn
0001 hMenuWinStc
0001 hBrushMenuWin
0001 grc
0001 gpStringFormat2
0001 gpPen2
0001 gpOtherD
0001 gpOtherC
0001 gpOtherB
0001 gpOtherA
0001 gpOther2D
0001 gpOther2C
0001 gpOther2B
0001 gpOther2A
0001 gpLine2
0001 FormatID
0001 FormatDescription
0001 FlagsEx
0001 findpos
0001 FindArray
0001 FilenameExtension
0001 fbSaveAs
0001 EdRes2
0001 EdRes1
0001 DragFile
0001 DoNotInclude
0001 DllName
0001 DebugMsg
0001 cyBottomHeight
0001 cxRightWidth
0001 cxLeftWidth
0001 CodecName
0001 Clsid
0001 BufStart
0001 bubMarker
0001 AuxMenu
0001 AnotherVar


The lower variables are the ones you are looking for, I guess :biggrin:
Title: Re: variable usage list
Post by: jimg on February 23, 2020, 07:17:51 AM
Thanks.

And since you're a freebasic fan, here's the program I just modified to print out all the tokens and the lines they appear on.  A little crude since it counts constants (like 0, 1) and all instructions too, but okay for a first try.
edit: dead link deleted.
Title: Re: variable usage list
Post by: jj2007 on February 23, 2020, 08:39:48 AM
Thanks, Jim. It compiles but complains that it doesn't know "sort": Shell "sort unsorted.txt /o sorted.txt"
From the commandline the sort command works. I changed it to WinExec(), and that works, too, but the format of sorted.txt looks a bit odd:
.186 .186
.286 .286
.286c .286c
.286p .286p
.287 .287
.386 .386
.386p .386p
.387 .387
.486 .486
.486c .486c
.486p .486p
.586 .586
.586p .586p
.686 .686
.686p .686p
.8086 .8086
.8087 .8087
.alpha .alpha
.break .break
.breakif .breakif
.code .code
.const .const
.continue .continue
.cref .cref
.data .data
.data? .data?
.dosseg .dosseg
.else .else
.elseif .elseif
.endif .endif
.endw .endw

Title: Re: variable usage list
Post by: FORTRANS on February 23, 2020, 08:58:26 AM
Hi,

Quote from: jimg on February 23, 2020, 02:26:56 AM
Before I reinvent the wheel, does anyone know of a utility to provide a listing of variables used in a masm program, and all the lines they are used on?

   I may be showing a bit of obsolescence here, but
wasn't that CREF.EXE back in the "good old days"?

Cheers,

Steve N.
Title: Re: variable usage list
Post by: jimg on February 23, 2020, 10:00:49 AM
jj- i'll look into it, I just ran it with no problems, so something else is amiss.

Fortrans-  Yes, but it requires two files I no longer have any ability to produce.  I doubt I could get PWB working even if it was worth the effort :)
Title: Re: variable usage list
Post by: jimg on February 23, 2020, 10:08:51 AM
jj-
is calling you jj a problem?  If it irritates you, let me know.

anyway,  each line of the sort file contains the lower case version of the keyword, followed by what we want to change it to.  In this particular case, they happen to be the same, but not for other things I use the program for (e.g. great cow basic).

No idea why the shell command doesn't work for you.  I'm using the latest version of fb,  are you using an older version?
Title: Re: variable usage list
Post by: jj2007 on February 23, 2020, 12:03:12 PM
Quote from: jimg on February 23, 2020, 10:08:51 AM
jj-
is calling you jj a problem?  If it irritates you, let me know.

Not at all, Jim :thup:

Quoteanyway,  each line of the sort file contains the lower case version of the keyword, followed by what we want to change it to.  In this particular case, they happen to be the same, but not for other things I use the program for (e.g. great cow basic).

No idea why the shell command doesn't work for you.  I'm using the latest version of fb,  are you using an older version

Version 1.05 of January 2016. Google shell "Freebasic" to find some threads with similar problems. It's messy.
Title: Re: variable usage list
Post by: jimg on February 23, 2020, 12:23:57 PM
I'm using 1.07.1

I've made a lot of changes since I post last.  Grouped types in the reference list,  Variables, Labels, Keywords, and Literals.  I'll put a link in a bit after I get literals a little better.  Kinda fun doing basic again :)
Title: Re: variable usage list
Post by: jimg on February 23, 2020, 12:46:35 PM
updated asmtidy- edit: deleted dead link
Title: Re: variable usage list
Post by: Vortex on February 23, 2020, 08:36:10 PM
Hi Jochen,

Could you try the function system ?

#include once "crt.bi"

system_ "sort test.txt /o test2.txt"
Title: Re: variable usage list
Post by: jimg on February 24, 2020, 03:45:14 AM
I found a crusty old program-
ASMVARS v1.00a, (c)2001 Jeremy Collake
http://www.collakesoftware.com
jeremy@collakesoftware.com
--------------------------------------------------

This program is designed to scan assembly language projects
for unreferenced local and global variables.


it did a decent job.  I found it in an old radasm installation.  I'm not sure if it's legal to upload here but it's available here https://sourceforge.net/p/fbedit/code/HEAD/tree/RadASM/Addins/AsmVars (https://sourceforge.net/p/fbedit/code/HEAD/tree/RadASM/Addins/AsmVars)