'#pragma reserve' statement to reserve backend keywords
Re: '#pragma reserve' statement to reserve backend keywords
fxm, both of your examples give the error 4: Duplicated definition at the appropriate line.
Last edited by srvaldez on Oct 18, 2021 15:34, edited 1 time in total.
Re: '#pragma reserve' statement to reserve backend keywords
The compile errors are what was expected, like the comment in the source code.
I am using the last build of St_W from last night (2021-10-17).
My question was rather for Jeff.
My aim was to demonstrate the difference between '#pragma reserve' and '#pragma reserve (shared)'.
I am using the last build of St_W from last night (2021-10-17).
My question was rather for Jeff.
My aim was to demonstrate the difference between '#pragma reserve' and '#pragma reserve (shared)'.
Re: '#pragma reserve' statement to reserve backend keywords
Jeff, what do you have to say about this post ? : viewtopic.php?p=286205#p286205
Re: '#pragma reserve' statement to reserve backend keywords
There is still buggy behaviour there, I think.fxm wrote:Jeff, what do you have to say about this post ? : viewtopic.php?p=286205#p286205
One issue might be the scope resolution at the time of processing '#pragma reserve'. Some of the parser context it is stored in global state and some of the context is passed as arguments through the parsers. Because #pragma is handled by the pre-processor, it can only access the global state. I might have some bad logic there.
Another issue might be that I'm confusing myself which rules to follow. Duplicate symbols depend on the symbol class. For example, variables can be shadowed, but not constants.
'' variables
Code: Select all
var shared V = 0
sub A
var V = 1
end sub
namespace ns
var shared V = 0
sub A
var V = 1
end sub
end namespace
Code: Select all
const C = 0
sub A
const C = 1 '' duplicate definition
end sub
namespace ns
const C = 0
sub A
const C = 1 '' duplicate definition
end sub
end namespace
Re: '#pragma reserve' statement to reserve backend keywords
From a user point of view, it would be annoying to have 2 separate commands, which would do different things under the hood, but which would induce the same behavior in the code when used.#pragma reserve symbol
and
#pragma reserve (shared) symbol
Re: '#pragma reserve' statement to reserve backend keywords
It has been a useful exploration for me, but I'm going to remove the '(shared)' variant and clean-up the compiler code. We already have the solution to reserve words used by ASM and backends, and there is no need to complicate this further.fxm wrote:From a user point of view, it would be annoying to have 2 separate commands, which would do different things under the hood, but which would induce the same behavior in the code when used.
'#pragma reserve (asm) symbol'
- reserves a symbol in ASM statements and ASM blocks to avoid errors in the gas backends
'#pragma reserve symbol'
- reserves a symbol in the current namespace / scope. When used at module level, prevents symbol from interfering with reserved words in the backend.
Next will we just need to add the symbols automatically which should allow us to close the bug #515 Reserved variable names (0.21.1)
Re: '#pragma reserve' statement to reserve backend keywords
Update: I've cleaned up the code and removed the #pragma reserve (shared) variant and I've added the reserved words for within ASM blocks, and this is pushed to fbc/master.
Bug #515 is still not fixed. because I didn't add the checks for 'dim shared cs ...' etc. It will have to be a separate look-up list and can't be stored in the global namespace.
Bug #515 is still not fixed. because I didn't add the checks for 'dim shared cs ...' etc. It will have to be a separate look-up list and can't be stored in the global namespace.
Re: '#pragma reserve' statement to reserve backend keywords
I will update the documentation when I have the corresponding fbc build (from St_W site):
- #PRAGMA RESERVE
- Identifier Rules
- #PRAGMA RESERVE
- Identifier Rules
Re: '#pragma reserve' statement to reserve backend keywords
I will try to finish this feature / bug-fix today before the nightly build. I'm going to replace (shared) with (extern) as it better indicates purpose. Hopefully I will have some examples soon.
Maybe next time, a new problem to fix first. #944 Array descriptors are defined more than once (gcc backend)
Maybe next time, a new problem to fix first. #944 Array descriptors are defined more than once (gcc backend)
Re: '#pragma reserve' statement to reserve backend keywords
KeyPgPpPragmaReserve → fxm [updated syntax]coderJeff wrote:I will try to finish this feature / bug-fix today before the nightly build.
???coderJeff wrote:I'm going to replace (shared) with (extern) as it better indicates purpose.
But there is no compiler error message yet when using these keywords as fbc procedure names ?
Re: '#pragma reserve' statement to reserve backend keywords
I didn't get it done in time. Too many troubles. And I don't have time now. Hopefully I will have time today after work to get it added to fbc/master.coderJeff wrote:I will try to finish this feature / bug-fix today before the nightly build.
I preferred to use a warning message instead of an error just in case the logic is wrong for automatically added asm symbol names (like cs, eax, etc).
Code: Select all
#pragma reserve (extern) symbol1
#pragma reserve (extern) symbol2
dim shared symbol1 as integer
sub symbol2
end sub
/'
extern.bas(4) warning 47(1): Use of reserved global or backend symbol, symbol1
extern.bas(6) warning 47(1): Use of reserved global or backend symbol, symbol2
'/
- asm adds it to the list of reserved words for the inline assembler
- extern adds it to the list of external or global words
Re: '#pragma reserve' statement to reserve backend keywords
I finally had some time to get changes committed:
Reserved symbols for INLINE ASM are combination of LIST A and LIST B on all targets. Note: this is not correct for non-x86 targets. There is an old reminder in the source code: "' TODO: support x86_64, arm, aarch64; select keyword list based on compilation target". Currently, LIST A+B is always selected for inline ASM statements and ASM blocks.
Reserved symbols for global/external/backend and as reported in bug #515, are from LIST A only. This is new for fbc-1.09.0. And use of these symbols for module level procedures and shared variables will generate a compile warning.
List A (inline asm and global/external/backend symbols):
Reserved symbols for INLINE ASM are combination of LIST A and LIST B on all targets. Note: this is not correct for non-x86 targets. There is an old reminder in the source code: "' TODO: support x86_64, arm, aarch64; select keyword list based on compilation target". Currently, LIST A+B is always selected for inline ASM statements and ASM blocks.
Reserved symbols for global/external/backend and as reported in bug #515, are from LIST A only. This is new for fbc-1.09.0. And use of these symbols for module level procedures and shared variables will generate a compile warning.
List A (inline asm and global/external/backend symbols):
List B (inline asm):dl, di, si, cl, bl, al, bp, sp, dx, cx, bx, ax, edx, edi, esi, ecx, ebx, eax, ebp, esp, st, cs, ds, es, fs, gs, ss, mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, word, dword, qword, fword, mmword, oword, r8, r9, r10, r11, r12, r13, r14, r15, r8w, r9w, r10w, r11w, r12w, r13w, r14w, r15w, rax, rbp, rbx, rcx, rdi, rdx, rsi, rsp, tbyte, xmmword, ymmword, zmmword, ah, axl, bh, bpl, bxl, ch, cxl, dh, dil, dr0, dr1, dr2, dr3, dr4, dr5, dr6, dr7, dxl, eip, eq, ge, gt, le, lt, ne, r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b, r8d, r9d, r10d, r11d, r12d, r13d, r14d, r15d, rip, sil, spl, ymm0, ymm1, ymm2, ymm3, ymm4, ymm5, ymm6, ymm7, ymm8, ymm9, ymm10, ymm11, ymm12, ymm13, ymm14, ymm15, zmm0, zmm1, zmm2, zmm3, zmm4, zmm5, zmm6, zmm7, zmm8, zmm9, zmm10, zmm11, zmm12, zmm13, zmm14, zmm15, zmm16, zmm17, zmm18, zmm19, zmm20, zmm21, zmm22, zmm23, zmm24, zmm25, zmm26, zmm27, zmm28, zmm29, zmm30, zmm31
byte, ptr, offset, aaa, aad, aam, aas, adc, add, addpd, addps, addsd, addss, and, andpd, andps, andnpd, andnps, arpl, bound, bsf, bsr, bswap, bt, btc, btr, bts, call, cbw, cwde, cdq, clc, cld, clflush, cli, clts, cmc, cmova, cmovae, cmovb, cmovbe, cmovc, cmove, cmovg, cmovge, cmovl, cmovle, cmovna, cmovnae, cmovnb, cmovnbe, cmovnc, cmovne, cmovng, cmovnge, cmovnl, cmovnle, cmovno, cmovnp, cmovns, cmovnz, cmovo, cmovp, cmovpe, cmovpe, cmovpo, cmovs, cmovz, cmp, cmppd, cmpps, cmps, cmpsb, cmpsw, cmpsd, cmpss, cmpxchg, cmpxchg8b, comisd, comiss, cpuid, cvtdq2pd, cvtdq2ps, cvtpd2dq, cvtpd2pi, cvtpd2ps, cvtpi2pd, cvtpi2ps, cvtps2dq, cvtps2pd, cvtps2pi, cvtsd2si, cvtsd2ss, cvtsi2sd, cvtsi2ss, cvtss2sd, cvtss2si, cvttpd2pi, cvttpd2dq, cvttps2dq, cvttps2pi, cvttsd2si, cvttss2si, cwd, daa, das, dec, div, divpd, divps, divss, emms, enter, f2xm1, fabs, fadd, faddp, fiadd, fbld, fbstp, fchs, fclex, fnclex, fcmovb, fcmove, fcmovbe, fcmovu, fcmovnb, fcmovne, fcmovnbe, fcmovnu, fcom, fcomp, fcompp, fcomi, fcomip, fucomi, fucomip, fcos, fdecstp, fdiv, fdivp, fidiv, fdivr, fdivrp, fidivr, ffree, ficom, ficomp, fild, fincstp, finit, fninit, fist, fistp, fld, fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, fldcw, fldenv, fmul, fmulp, fimul, fnop, fpatan, fprem, fprem1, fptan, frndint, frstor, fsave, fnsave, fscale, fsin, fsincos, fsqrt, fst, fstp, fstcw, fnstcw, fstenv, fnstenv, fstsw, fnstsw, fsub, fsubp, fisub, fsubr, fsubrp, fisubr, ftst, fucom, fucomp, fucompp, fwait, fxam, fxch, fxrstor, fxsave, fxtract, fyl2x, fyl2xp1, hlt, idiv, imul, in, inc, ins, insb, insw, insd, int, into, invd, invlpg, iret, iretd, ja, jae, jb, jbe, jc, jcxz, jecxz, je, jg, jge, jl, jle, jna, jnae, jnb, jnbe, jnc, jne, jng, jnge, jnl, jnle, jno, jnp, jns, jnz, jo, jp, jpe, jpo, js, jz, jmp, lahf, lar, ldmxcsr, lds, les, lfs, lgs, lss, lea, leave, lfence, lgdt, lidt, lldt, lmsw, lock, lods, lodsb, lodsw, lodsd, loop, loope, loopz, loopne, loopnz, lsl, ltr, maskmovdqu, maskmovq, maxpd, maxps, maxsd, maxss, mfence, minpd, minps, minsd, minss, mov, movapd, movaps, movd, movdqa, movdqu, movdq2q, movhlps, movhpd, movhps, movlhps, movlpd, movlps, movmskpd, movmskps, movntdq, movnti, movntpd, movntps, movntq, movq, movq2dq, movs, movsb, movsw, movsd, movss, movsx, movupd, movups, movzx, mul, mulpd, mulps, mulsd, mulss, neg, nop, not, or, orpd, orps, out, outs, outsb, outsw, outsd, packsswb, packssdw, packuswb, paddb, paddw, paddd, paddq, paddsb, paddsw, paddusb, paddusw, pand, pandn, pause, pavgb, pavgw, pcmpeqb, pcmpeqw, pcmpeqd, pcmpgtb, pcmpgtw, pcmpgtd, pextrw, pinsrw, pmaddwd, pmaxsw, pmaxub, pminsw, pminub, pmovmskb, pmulhuv, pmulhw, pmullw, pmuludq, pop, popa, popad, popf, popfd, por, prefetcht0, prefetcht1, prefetcht2, prefetchnta, psadbw, pshufd, pshufhw, pshuflw, pshufw, psllw, pslld, psllq, psraw, psrad, psrldq, psrlw, psrld, psrlq, psubb, psubw, psubd, psubq, psubsb, psubsw, psubusb, psubusw, punpckhbw, punpckhwd, punpckhdq, punpckhqdq, punpcklbw, punpcklwd, punpckldq, punpcklqdq, push, pusha, pushad, pushf, pushfd, pxor, rcl, rcr, rol, ror, rcpps, rcpss, rdmsr, rdpmc, rdtsc, rep, repe, repz, repne, repnz, ret, rsm, rsqrtps, rsqrtss, sahf, sal, sar, shl, shr, sbb, scas, scasb, scasw, scasd, seta, setae, setb, setbe, setc, sete, setg, setge, setl, setle, setna, setnae, setnb, setnbe, setnc, setne, setng, setnge, setnl, setnle, setno, setnp, setns, setnz, seto, setp, setpe, setpo, sets, setz, sfence, sgdt, sidt, shld, shrd, shufpd, shufps, sldt, smsw, sqrtpd, sqrtps, sqrtsd, sqrtss, stc, std, sti, stmxcsr, stos, stosb, stosw, stosd, str, sub, subpd, subps, subsd, subss, sysenter, sysexit, test, ucomisd, ucomiss, ud2, unpckhpd, unpckhps, unpcklpd, unpcklps, verr, verw, wait, wbinvd, wrmsr, xadd, xchg, xlat, xlatb, xor, xorpd, xorps, pavgusb, pfadd, pfsub, pfsubr, pfacc, pfcmpge, pfcmpgt, pfcmpeq, pfmin, pfmax, pi2fw, pi2fd, pf2iw, pf2id, pfrcp, pfrsqrt, pfmul, pfrcpit1, pfrsqit1, pfrcpit2, pmulhrw, pswapw, femms, prefetch, prefetchw, pfnacc, pfpnacc, pswapd, pmulhuw
Re: '#pragma reserve' statement to reserve backend keywords
Side effect when using for example #cmdline "-asm ...": the warning messages ('Use of reserved ...') can be doubled (if there are no other errors).
Example with fbc 64-bit:Compiler output:
...\FBIde0.4.6r4-FreeBASIC1.09.0.win64\FBIDETEMP.bas(9) warning 47(1): Use of reserved global or backend symbol, ah
...\FBIde0.4.6r4-FreeBASIC1.09.0.win64\FBIDETEMP.bas(9) warning 47(1): Use of reserved global or backend symbol, ah
Example with fbc 64-bit:
Code: Select all
#cmdline "-asm att"
Sub ah()
End Sub
ah()
Print "OK"
Sleep
...\FBIde0.4.6r4-FreeBASIC1.09.0.win64\FBIDETEMP.bas(9) warning 47(1): Use of reserved global or backend symbol, ah
...\FBIde0.4.6r4-FreeBASIC1.09.0.win64\FBIDETEMP.bas(9) warning 47(1): Use of reserved global or backend symbol, ah
Re: '#pragma reserve' statement to reserve backend keywords
'#pragma reserve (asm, extern) symbol' is an alternative syntax to '#pragma reserve (extern) symbol' and there is a duplication error if both are used on the same symbol.
'#pragma reserve (extern, asm) symbol' is also allowed but does not induce duplication error with '#pragma reserve (extern) symbol' but on the other hand it duplicates with '#pragma reserve (asm) symbol' ???
'#pragma reserve (extern, asm) symbol' is also allowed but does not induce duplication error with '#pragma reserve (extern) symbol' but on the other hand it duplicates with '#pragma reserve (asm) symbol' ???
Re: '#pragma reserve' statement to reserve backend keywords
Thanks, I see my logic error. I'll fix this ASAP.fxm wrote:' '#pragma reserve (extern, asm) symbol' is also allowed but does not induce duplication error with '#pragma reserve (extern) symbol'