This topic should continue the discussion of the bug #21 assembler support reported by Wasilios Goutas.
In the his code inline assembler is used that is actually not supported by Moritz.
It is not possible to extend the parser grammar with a standard solution working for all thinkable cases, since the coding of inline-assembler is very compiler specific and the assembler mnemonics are depending on the hardware-platform the code is written for.
Thus the solution has to be implemented as user specific grammar as discussed for a similar case in the topic User Extension of the C/Cpp Grammar .
For this I attach here a zip-archive that contains several configuration files I have modified to provide a demonstrator.
Please check the content of the archive with your virus-scanner before you open it.
The file contains sub-folders of the Moritz distribution directory "[MoritzRoot]\LangPack\ansi_c\"
This sub-folders contain modified files which should replace the existing once.
It may be useful to copy your original files before to restore the original distribution if you face some issues.
I will discuss here just the most important changes or implementations I have done:
The file ANSI_C_Source_C_only_grm.a2x contains a new syntax-rule called assembler.
This new rule will be called as part of a statement or a compound_statement.
The new rule is just a root for detecting 2 different types of inline-assembler coding assembler block or assembler macro used as possible examples .
Assembler Block
__asmmovr2,dpl;buffer.c if( head != (unsigned char)(tail-1) ) /* cast needed to avoid promotion to integer */mova,_taildecamovr3,amova,_headcjnea,ar3,00106$
ret00106$:
;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */movr3,_headinc_headmovdpl,r3movdph,#(_buf>>8)mova,r2movx @dptr,a00103$:
ret__endasm;
Assembler Macro
__asm__("mov r2,dpl");__asm__(";buffer.c if( head != (unsigned char)(tail-1) ) /* cast needed to avoid promotion to integer */");__asm__("mov a,_tail");__asm__("dec a");__asm__("mov r3,a");__asm__("mov a,_head");__asm__("cjne a,ar3,00106$");__asm__("ret");__asm__("00106$:");__asm__(";buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */");__asm__("mov r3,_head");__asm__("inc _head");__asm__("mov dpl,r3");__asm__("mov dph,#(_buf >> 8)");__asm__("mov a,r2");__asm__("movx @dptr,a");__asm__("00103$:");__asm__("ret");
But Wasilios Goutas is mentioning a 3rd type similar to the coding-stile defined b AT&T and used with GNU GCC.
To detect this grammar I have extended the file UserGrammar.a2x by the redefinition of the new syntax-rule assembler (Note:Iit is not necessary to remove the original definition done in the file ANSI_C_Source_C_only_grm.a2x ).
The new rule and the called rules used to detect the AT&T/GNU inline assembler as shown in the example above look like this:
Where the called syntax-rules String, ID, type_qualifier and semikolon are already provided by the standard-grammar (if not redefined in the user-grammar before).
All other files provided with the zip-archive are supporting the basic extension of the grammar by the new assembler rule-set. The files in the sub-folders x2a_nsd and x2a_uad are extended to show the inline-assembler in the diagrams.
Please note that this implementation is just a very simple one. The evaluation of the assembler-lines is not analysing the real meaning of each command and the resulting diagram-parts are treating each assembler-line just as a simple c-command like the call of a function.
This topic should continue the discussion of the bug #21 assembler support reported by Wasilios Goutas.
In the his code inline assembler is used that is actually not supported by Moritz.
It is not possible to extend the parser grammar with a standard solution working for all thinkable cases, since the coding of inline-assembler is very compiler specific and the assembler mnemonics are depending on the hardware-platform the code is written for.
Thus the solution has to be implemented as user specific grammar as discussed for a similar case in the topic User Extension of the C/Cpp Grammar .
For this I attach here a zip-archive that contains several configuration files I have modified to provide a demonstrator.
I will discuss here just the most important changes or implementations I have done:
The file ANSI_C_Source_C_only_grm.a2x contains a new syntax-rule called assembler.
Assembler Block
Assembler Macro
But Wasilios Goutas is mentioning a 3rd type similar to the coding-stile defined b AT&T and used with GNU GCC.
To detect this grammar I have extended the file UserGrammar.a2x by the redefinition of the new syntax-rule assembler (Note:Iit is not necessary to remove the original definition done in the file ANSI_C_Source_C_only_grm.a2x ).
The new rule and the called rules used to detect the AT&T/GNU inline assembler as shown in the example above look like this:
Where the called syntax-rules String, ID, type_qualifier and semikolon are already provided by the standard-grammar (if not redefined in the user-grammar before).
All other files provided with the zip-archive are supporting the basic extension of the grammar by the new assembler rule-set. The files in the sub-folders x2a_nsd and x2a_uad are extended to show the inline-assembler in the diagrams.
I wish you a happy new year. Take care about you and stay healthy,
Eckard.