You can argue until the blue on IDE vs Notepad / VIM / Emacs. Exactly as long as the IDE is. However, you can easily stumble upon a language (or dialect) that you have to use, and the IDE either does not exist for it, or is only paid and expensive, or is already so outdated that it runs only in a rare OS emulator. And you have to work. Fortunately, there are universal tools that you only need to select and “sharpen” by hand. The following describes the use of the VIM bundle, the translator, and some ctags for today's rare assembler version.
There is only a translator
Shortly after starting my work in the development team, I ran into an assembler for the 18062, roughly speaking PDP-11. Moreover, the target device is a kind of board with a handful of parts for converting and processing signals, and the instrumental machine is a Windows PC (with no options). The devices being developed are different, and the programs for them range from three hundred to three thousand lines of code.
When I joined this process, it turned out that the project corresponds to a folder with the name of the device. The folder contains an assembler file (all asm files have the same name, compilation is configured this way), a bat file without parameters, which calls another bat file with parameters, which in turn launches an exe file of an assembler (lying , right). In addition, in the project folder you can find a binary and listing, as well as a program for converting a binary into a firmware ROM file and an auxiliary text file for conversion, another utility for converting the firmware file into a format understandable to our programmer, the firmware file (outdated since they began to write the program in flash instead of the ROM), plus dirinfo.txt, in which very rarely anyone wrote anything.
The work was like this: in the console file manager, the program text was corrected by the built-in editor. After editing, the first batch file was launched (it is important not to confuse!). Next, we look at the console output for errors. If there are no syntax jambs - the program is poured into the ROM emulator, we check the performance on the hardware. So the program is appended and checked until it starts to perform what is expected of it. Then the generated firmware is written into the ROM (later the ROM was replaced with flash).
')
The first time I worked as usual. There was no convenience - you need to understand the command system, the features of the program, the hardware of the devices for which the software is written. When something began to turn out, thoughts of improvement began to arise. First of all, I wanted syntax highlighting, starting the compiler from the editor and normal search with replacement.
Flour choice
At first, I tried to find an IDE on all kinds of Internet sites, because this is the same PDP-11, that is, DVK, BK and UKSC, there must be something! And it was found, but it worked exclusively in the UKSC center emulator. I did not like either the console IDE, or the emulator, or the need to run the emulator for the environment, but this was not the most important thing. Worst of all, the resulting binaries differed from the ones created in the “traditional way”. I didn’t understand the reasons - there wasn’t enough time to finish the rarities in emulators, or, even worse, to write corrective software. I decided to organize my work space, with preference and courtesans.
Began to look for a text editor more seriously. From what I came across during the search, I liked UltraEdit the most (especially in the UEStudio version). It was all that I wanted, plus more plushki - comparing text files, transcoding, column selection, running not only the compiler, but also other constructed macros using the name of the current file, the toolbar extension. Everything is good - but for a fee, and then according to my income, then it is not cheap. I tried MiBEditor - an impressive product (for free and made in one helmet), but not that. Helped light hobby Linux. I learned about VIM, tried it, felt its capabilities and discovered the version for Wndows.
Presetting
The first thing I did was adjust the appearance and behavior in vimrc: the dark color scheme of wombat (light gray on black, corrected by his preferences), line numbering, increased to 85 by default width due to line numbers, smart indents and tabs , disabled bak-files, auto-change working folder by open file. I turned on the virtual call, which blinks, not beeps, turned off the toolbar (for some reason, left the menu, although I don’t use it), hid the mouse while typing, hung up switching between open split buffers on Ctrl-Tab.
I chose a font that has Russian characters:
set guifont=Courier_New:h10:cRUSSIAN "
I added something for the layout to make it convenient to work in Russian:
set keymap=russian-jcukenwin " set iskeyword=@,48-57,_,192-255 " . . set iminsert=0 " - - set imsearch=0 " — lang ctype Russian_Russia.1251
Hung layout switch on F12:
imap <F12> <C-^> cmap <F12> <C-^>
Now, with the English layout, all keyboard commands work fine, and you need to switch the input language not with the system Ctrl-Shift, but with VIM's F12, the current language is displayed in the bottom line:
“- INSERT -” for English, or
“- INSERT ( language) - " for Russian. A minor inconvenience is that I usually have a Russian keyboard layout, and here we must not forget to switch to VIM when starting VIM.
I wrote all of the above in a separate vimrc_rg, which I connected in the default settings file:
source $VIM/_vimrc_rg
I also installed several plugins, but I always use literally one - QuickBuf (qbuf.vim, script_id = 1910), which allows me to switch between open buffers in one window via F4. Now I don’t need tabs (for which I managed to get used to UltraEdit), and even seem inconvenient. Sometimes I remember about the installed Visual mark (script_id = 1026), which makes selected bookmarks, as in UltraEdit.
Thus began the use of VIM as the main editor for plain-text files. One of my requirements - normal search and replacement - is out of the box, just learn how to use it. Plus, highlighting of many languages ​​and auto-indents - it became very convenient to edit batch files, for example.
Setting the backlight and translator
Next, he introduced a new file type - a1806, for highlighting and embedding compilation. Created the filetype.vim file in the root of the vimfiles folder:
augroup filetypedetect au BufNewFile,BufRead *.msa setf a1806 au BufNewFile,BufRead *.a51 setf asm8051 augroup END
Then for some time I began to give the appropriate extensions to assembler files - msa for 1806, and 51 for the assembler MCS-51, so as not to be confused with asm, which is set by default for the Intel assembler.
Then in vimfiles \ syntax made the file a1806.vim, converted from the backlight file of some other language. Key words found on the Internet, text information on the PDP-11 in bulk. There are a couple of paper books on the UKSC and SM computers, but it is easier to copy from web pages.
Among other things, I inserted this line into this file:
syn match a1806Error "#@.*\|[a-zA-Z0-9_$]\{7,}:"
When typing and entering indirect addressing, I often confused @ # and # @, and this template highlights the error while typing. So you can identify other common typos.
Syntax highlighting is. Now compile. I sorted out the make and ctags utility, it became clear that they were not helpers here. There is an assembler, but there is no linker - the project cannot be split into module files. The goal for make will be only one, the file for it too, and there is nothing to bother with. It’s the same with ctags - the file is one, there’s really nothing to look for on it, the tags are so easily found with an asterisk. In long files, bookmarks are more useful than they are in VIM. But the assembler in each project folder is fi! I make the bin folder in the root of the C: \ drive, prescribe it in the PATH (then put the make and ctags for another assembler). There I put the assembler and mk1806.bat, where, in addition to the microhelp and checking the validity of the passed parameters, the binary and the listing are erased, and then the assembler is called:
:VALIDDIR CD %2 %3 %4 %5 %6 %7 %8 %9 :WORK2 if not exist *.bin goto NOBIN attrib -r *.bin del *.bin :NOBIN if not exist *.lst goto NOLST attrib -r *.lst del *.lst :NOLST if exist %1 C:\bin\cmplr1806\asm.exe %1 -m if not exist %1 echo Error: File %1 not exist!
The batch file takes two parameters - the file name and path to it. In order not to spoil the output of make, the mode for displaying commands in a file is disabled (@ ECHO OFF).
In vimfiles \ ftplugin made the file a1806.vim:
" Language: 1806 assembler " Maintainer: " Last Change: " lcd %:h " setlocal makeprg=C:\bin\mk1806.bat\ %:t\ %:p:h " setlocal autowrite nmap <buffer> <F9> :make<CR> imap <buffer> <F9> <Esc>:make<CR> " set efm=%-G,%-G\ BK-10/11%.%#,%-P\ Opened\ %f,%Eline\ %l\\,%.%#,%Z%m,%-GFile\ compiled%.%#
Errorformat was determined empirically (there is no documentation for asm.exe at all), that is, it started assembling the file without errors and with various specially made errors, studied the console output, compiled the VIM help template.
Example of output with an error (line numbers added manually for clarity):
1 2 BK-10/11 Assembler 3 4 Opened 1.ASM 5 Line 61,Address 000320: 6 Bad operator [AKSJDFH]. 7 Opened 1.lst 8 9 File compiled 346 bytes. 10
Then the error format will consist of the following elements:
- % -G, - ignore empty string if encountered. (“G” - information of a general nature, “% -” - to exclude from the output, and the absence of something after “G” means that an empty line is meant). It will be applied to 1, 3, 8 and 10 lines.
- % -G \ BK-10/11%.% #, Here '%.% #' Is used to create a regular expression pattern '. *', That is, a line starting with “BK-10/11” (space for “: set” commands are escaped by “\”), ignored. Will be applied to line 2.
- % -P \ Opened \% f, - a one-line message (% -P) with the file name (% f) after the word "Opened" is parsed, "% -P" says that the line is not output, but the file name is remembered, the following errors relate to it. Will be applied to lines 4 and 7.
- % Eline \% l \\,%.% #, Is the beginning of a multi-line error message (% E), where after the word "line" there is a line number (% l), then a comma ("\\," - the comma must be escaped a backslash, but it must be duplicated for the “: set” command), then some string (“%.% #” = “. *”) that participates in the output (in our case, the address, although it will be displayed as errors - “320 error”, this is not a bug, but a feature).
- % Z% m, is the end of a multi-line message (% Z) with the actual error message (% m). The% E and% Z templates work together for pairs of strings 5 ​​and 6.
- % -GFile \ compiled%.% # Again, general information, thrown out of the output, the rule for line 9.
In accordance with the efm templates, lines 1..4 and 7..10 are not displayed, although the file name is remembered in 4 and 7. If there are no lines 5 and 6 - the output is empty, there are no errors. Lines of type 5 and 6 may be several pairs. Each of these pairs will form an element of the list of error messages.
VoilĂ ! We have a compilation with autosave on F9. When a syntax error is detected, VIM immediately puts the cursor on the line of code corresponding to the first error from the list of found ones.
There is not enough debugger - but here it does not help, since too many things are tied to interrupts, direct memory access and extraneous hardware. I have not yet mastered the full comparison of files embedded in VIM, I mainly use WinMerge. And yet it became much more convenient.
Empowerment
And then in 1806, we began to gradually withdraw, and work began on devices based on the NM6403 processor. Also in assembly language. And, in order not to be perverted with inventing the next extension for the source files, I added the file asm.vim to vimfiles \ ftplugin:
if getline(1) =~
In assembly files with the extension .asm began to enter the first line
"; A1806" or "// a6403", respectively. I also added the syntax highlighting of vimfiles \ syntax \ a1806.vim (written very simply and quickly according to "Description of the assembly language") and such vimfiles \ ftplugin \ a6403.vim:
" Language: 6403 assembler " Maintainer: " Last Change: setlocal makeprg=c:\bin\make.exe " lcd %:h " setlocal autowrite nmap <buffer> <F9> :make<CR> imap <buffer> <F9> <Esc>:make<CR> nmap <buffer> <F10> :make TAGS<CR> imap <buffer> <F10> <Esc>:make TAGS<CR> set efm=\"%f\"\\,%l\ :\ %m
For this to work, I wrote a Makefile that lies in each project folder and is adjacent to the compiler's bat file used by other developers. In my Makefile there is a TAGS target, as well as a call to this target from the ALL target.
TAGS : @c:/bin/ctags.exe --options=c:/bin/a6403.ctags $(SRC_ASM) *.asi
ASM sources are listed in $ (SRC_ASM), and include files in * .asi.
In the mentioned folder C: \ bin lies make.exe, ctags.exe, and also a6403.ctags, passed as a parameter to ctags.exe:
--langdef=a6403 --langmap=a6403:.asm --language-force=a6405 --regex-a6403=/^<([a-zA-Z0-9_]+)>/\1/L,labels/ --regex-a6403=/^[ \t]*const[ \t]+([a-zA-Z0-9_]+)/\1/C,consts/ --regex-a6403=/^[ \t]*
The ctags out of the box have no idea about the NM6403. The first line defines the new language name. The second line is about the file extension. Extensions are written in succession, for example, “.asm.asi.inc”. A dot without a symbol behind it implies the use of files without an extension. However, the option is not particularly useful - I did not specify the .asi extension here, however I indicated * .asi when calling ctags - and the utility scanned everything that was needed. The fourth line makes use of the above extensions for this language, and not for the language embedded in ctags for the same extensions. The remaining lines describe a label like “<Label>”, a constant like “const Name”, a macro definition like “#define Expression” and a global variable like “global Name: word” respectively - those entities to whose definitions I would like to be able to “jump ". Here I want to remind you about the gf - go file command, the transition to the file whose name is under the cursor is very convenient for viewing include files.
Another subtlety: there are several different development tools installed on the work computer, including the IDE. Some of them carry their own make on board, and the paths to their binaries are set in PATH during installation. Moreover, some make nervously belong to the Makefile, made according to the rules of GNU make. In general, they may even be command files. So I had to go to the used make (and at the same time ctags) to write completely everywhere - it is easier and more reliable than reordering the PATH and controlling it after each installation of the next IDE / CAD.
Total
Now I have the opportunity to conveniently work with different assemblers, not bothering with file extensions, “jump” on the code scattered across different files, compile, without leaving the editor, fall on a line with a syntax error after compilation. By analogy, it is very easy to expand the scope of the VIM + translator + ctags bundle in other languages ​​if you have to use them. You can add convenience to working with tags by selecting the appropriate plugin. You can fasten make with the settings on the desired translator through the Makefile, you can also the translator itself directly. Well, not IDE, of course, but not a notebook!
It is a little sad that I use the convenience and power of VIM and ctags in the team alone. No one hooked. Maybe someone these developments will be useful?
PS Thanks to everyone who mastered to the end.