[fpc-pascal] Inline bytes
How is it possible to put some inline bytes in the code like the former inline( $1f , $ef , $1A ); instruction? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Rainer Stratmann wrote on Thu, 09 Aug 2012: How is it possible to put some inline bytes in the code like the former inline( $1f , $ef , $1A ); instruction? {$asmmode att} asm .byte $0x1f, $0xef, $0x1a end; {$asmmode intel} asm db $1a, $ef, $1a end; If this is supposed to be the only code/data inside an assembler routine, make sure to also add "assembler; nostackframe;" to that routine's modifiers to prevent the compiler from setting up a stack frame and/or insert stack alignment code. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Hi, On 08/ 9/12 03:09 PM, Rainer Stratmann wrote: How is it possible to put some inline bytes in the code like the former inline( $1f , $ef , $1A ); instruction? Not sure if it is the official way, but the following works: with {$asmmode att} asm .byte 0x1f, 0xef, 0x1a end; and with {$asmmode intel} asm db $1f, $ef, $1a end; Hth, Thomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Am Thursday 09 August 2012 15:14:29 schrieb Jonas Maebe: > Rainer Stratmann wrote on Thu, 09 Aug 2012: > > How is it possible to put some inline bytes in the code like the former > > inline( $1f , $ef , $1A ); > > instruction? > > {$asmmode att} > asm >.byte $0x1f, $0xef, $0x1a > end; > > {$asmmode intel} > asm >db $1a, $ef, $1a > end; Thanks, the next problem then is: I wanted to do that in an inline procedure but if the compiler detects an asm statement then inline is disabled(!). ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Label
Is it possible to get the adress of a label in a procedure? label mark1; procedure s; begin mark1: end; var p : pointer; begin p := @mark1; // does not work; end; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
On 09/08/12 14:25, Rainer Stratmann wrote: > Am Thursday 09 August 2012 15:14:29 schrieb Jonas Maebe: >> Rainer Stratmann wrote on Thu, 09 Aug 2012: >>> How is it possible to put some inline bytes in the code like the former >>> inline( $1f , $ef , $1A ); >>> instruction? >> >> {$asmmode att} >> asm >>.byte $0x1f, $0xef, $0x1a >> end; >> >> {$asmmode intel} >> asm >>db $1a, $ef, $1a >> end; > > Thanks, the next problem then is: I wanted to do that in an inline procedure > but if the compiler detects an asm statement then inline is disabled(!). Maybe a macro? Henry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Rainer Stratmann wrote on Thu, 09 Aug 2012: Am Thursday 09 August 2012 15:14:29 schrieb Jonas Maebe: {$asmmode att} asm .byte $0x1f, $0xef, $0x1a end; I made an error here, the "$" should be removed (see Thomas' mail) {$asmmode intel} asm db $1a, $ef, $1a end; Thanks, the next problem then is: I wanted to do that in an inline procedure but if the compiler detects an asm statement then inline is disabled(!). That's correct, it is not possible inline assembler statements in FPC. You can try a macro instead: {$macro on} {$define IReallyKnowWhatIAmDoing:=asm .byte 0x1f, 0xef, 0x1a end} begin IReallyKnowWhatIAmDoing; end. You will have to declare the macro in a common include file or in every main source file if you want to use it in more than one compilation module though. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Rainer Stratmann wrote on Thu, 09 Aug 2012: Is it possible to get the adress of a label in a procedure? Not outside that procedure, no. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Am Thursday 09 August 2012 15:33:52 schrieb Jonas Maebe: > > Thanks, the next problem then is: I wanted to do that in an inline > > procedure but if the compiler detects an asm statement then inline is > > disabled(!). > > That's correct, it is not possible inline assembler statements in FPC. > You can try a macro instead: > > {$macro on} > {$define IReallyKnowWhatIAmDoing:=asm .byte 0x1f, 0xef, 0x1a end} > > begin >IReallyKnowWhatIAmDoing; Sounds good! > end. Same thing: inlining disabled(!). > You will have to declare the macro in a common include file or in > every main source file if you want to use it in more than one > compilation module though. > > Jonas > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Am Thursday 09 August 2012 15:35:54 schrieb Jonas Maebe: > Rainer Stratmann wrote on Thu, 09 Aug 2012: > > Is it possible to get the adress of a label in a procedure? > > Not outside that procedure, no. Would it be possible to chage it, to get this information? May be it is only some kind of accident prevention for programmers who do not really know what they are doing. :-) > > Jonas > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Rainer Stratmann wrote on Thu, 09 Aug 2012: Am Thursday 09 August 2012 15:35:54 schrieb Jonas Maebe: Rainer Stratmann wrote on Thu, 09 Aug 2012: > Is it possible to get the adress of a label in a procedure? Not outside that procedure, no. Would it be possible to chage it, to get this information? No. It would require quite a bit of rewriting in the compiler for little or no gain, and cause problems with smart linking on some platforms. Delphi presumably doesn't support it for the same reason. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Rainer Stratmann wrote on Thu, 09 Aug 2012: Am Thursday 09 August 2012 15:33:52 schrieb Jonas Maebe: > Thanks, the next problem then is: I wanted to do that in an inline > procedure but if the compiler detects an asm statement then inline is > disabled(!). That's correct, it is not possible inline assembler statements in FPC. You can try a macro instead: {$macro on} {$define IReallyKnowWhatIAmDoing:=asm .byte 0x1f, 0xef, 0x1a end} begin IReallyKnowWhatIAmDoing; Sounds good! end. Same thing: inlining disabled(!). The idea is to use the macro instead of a function call, not to use the macro inside a function that you then try to inline. A macro is just text substitution, it will never have a different effect than typing its contents directly at the place where the macro is used. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Am 09.08.2012 15:35, schrieb Jonas Maebe: Rainer Stratmann wrote on Thu, 09 Aug 2012: Is it possible to get the adress of a label in a procedure? Not outside that procedure, no. Just because it sounds that way: is it possible inside the procedure? Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Sven Barth wrote on Thu, 09 Aug 2012: Am 09.08.2012 15:35, schrieb Jonas Maebe: Rainer Stratmann wrote on Thu, 09 Aug 2012: Is it possible to get the adress of a label in a procedure? Not outside that procedure, no. Just because it sounds that way: is it possible inside the procedure? Yes, if the label declaration is also inside the procedure. You can only take the address of a globally declared label iff a) the label is also defined in the global scope ("begin .. end.", initialization, finalization) b) the label's address is also taken in one of those blocks. It doesn't have to be the same one though, because the compiler keeps the code for all of those blocks in memory at the same time and hence a label defined in one of those is still valid while generating the code for another one. That's more a compiler implementation aspect than a conscious design decision though Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Am Thursday 09 August 2012 15:51:10 schrieb Jonas Maebe: > The idea is to use the macro instead of a function call, not to use > the macro inside a function that you then try to inline. A macro is > just text substitution, it will never have a different effect than > typing its contents directly at the place where the macro is used. To avoid disabling procedure/function inlining when the compiler finds an asm instruction it would be good to have at least the mentioned former inline( $AB, $CD , $EF , ... ); back. Is that possible? Macros have to defined for each unit again so this is not userfriendly if a programmer changes a macro. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Am Thursday 09 August 2012 16:52:40 schrieb Jonas Maebe: > Sven Barth wrote on Thu, 09 Aug 2012: > > Am 09.08.2012 15:35, schrieb Jonas Maebe: > >> Rainer Stratmann wrote on Thu, 09 Aug 2012: > >>> Is it possible to get the adress of a label in a procedure? > >> > >> Not outside that procedure, no. > > > > Just because it sounds that way: is it possible inside the procedure? > > Yes, if the label declaration is also inside the procedure. You can > only take the address of a globally declared label iff > a) the label is also defined in the global scope ("begin .. end.", > initialization, finalization) > b) the label's address is also taken in one of those blocks. It > doesn't have to be the same one though, because the compiler keeps the > code for all of those blocks in memory at the same time and hence a > label defined in one of those is still valid while generating the code > for another one. That's more a compiler implementation aspect than a > conscious design decision though If you have a label in a procedure and declare this procedure as inline procedure then it gives also problems (Fatal: compilation aborted!). ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Rainer Stratmann wrote on Thu, 09 Aug 2012: To avoid disabling procedure/function inlining when the compiler finds an asm instruction it would be good to have at least the mentioned former inline( $AB, $CD , $EF , ... ); back. Is that possible? There are no plans to do so, and even if it were added it would be quite possible that this would also disable inlining the containing routine for implementation reasons. Macros have to defined for each unit again so this is not userfriendly if a programmer changes a macro. A macro can be defined in a file that is included in all units, so then you only have to change it in one place. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Hi, On 08/ 9/12 05:08 PM, Rainer Stratmann wrote: Just because it sounds that way: is it possible inside the procedure? Yes, if the label declaration is also inside the procedure. You can only take the address of a globally declared label iff a) the label is also defined in the global scope ("begin .. end.", initialization, finalization) b) the label's address is also taken in one of those blocks. It doesn't have to be the same one though, because the compiler keeps the code for all of those blocks in memory at the same time and hence a label defined in one of those is still valid while generating the code for another one. That's more a compiler implementation aspect than a conscious design decision though If you have a label in a procedure and declare this procedure as inline procedure then it gives also problems (Fatal: compilation aborted!). just fyi, generally the "inline" keyword is only a suggestion to the compiler. There is no guarantee whatsoever that it will actually inline that particular method. There are, as you found out, several limitations for that. Actually, there are more, like size of the inlined method, possible use of exception handling, etc. (I'm not sure about the exact conditions btw, maybe there's some documentation in the manuals) Do not use it if you code something that relies on actual inlining - it seems to me that you require that in whatever you're trying to achieve. Only macros are guaranteed to be inlined - because they are simple text replacement instructions to the compiler. Hth, Thomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Rainer Stratmann wrote on Thu, 09 Aug 2012: If you have a label in a procedure and declare this procedure as inline procedure then it gives also problems (Fatal: compilation aborted!). That is the generic error message that is shown at the end of every failed compilation. I guess you mean this error message: Error: Taking the address of labels defined outside the current scope isn't allowed Taking the address of a label inside an inlined routine is indeed not supported. I would really recommend you (again) to use resourcestrings. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Am Thursday 09 August 2012 17:09:57 schrieb Jonas Maebe: > if it were added it would be > quite possible that this would also disable inlining the containing > routine for implementation reasons. I think the reason for disabling is that in the asm code can be identifyers and jumplabels which are difficult to handle then. In the inline( $AB , $CD , ... ) instruction is only pure data, so for me there is no reason to disable the inlining then. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inline bytes
Rainer Stratmann wrote on Thu, 09 Aug 2012: Am Thursday 09 August 2012 17:09:57 schrieb Jonas Maebe: if it were added it would be quite possible that this would also disable inlining the containing routine for implementation reasons. I think the reason for disabling is that in the asm code can be identifyers and jumplabels which are difficult to handle then. In the inline( $AB , $CD , ... ) instruction is only pure data, so for me there is no reason to disable the inlining then. inline() can contain identifiers and labels just like assembler blocks. But again: there are no plans to add support for inline(). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Am Thursday 09 August 2012 17:18:09 schrieb Jonas Maebe: > I would really recommend you (again) to use resourcestrings. You say that is not possible and that is not possible (or someone can say: you don't want to go deep in it). Beyond that you recommend me your style of programming. I see everywhere limitations. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Rainer Stratmann wrote on Thu, 09 Aug 2012: Am Thursday 09 August 2012 17:18:09 schrieb Jonas Maebe: I would really recommend you (again) to use resourcestrings. You say that is not possible and that is not possible (or someone can say: you don't want to go deep in it). You noticed yourself what is and what is not possible. And I am indeed not interested in adding macro assembler features to FPC. Beyond that you recommend me your style of programming. I recommend existing functionality for exactly the kind of feature you want to implement, because it already exits, is documented, has been tested and is being used by many people. It's not "my style of programming". I've never used resourcestrings in my life (because I've never worked on a multilingual program, not because I've used something else instead). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Label
Am 09.08.2012 17:49, schrieb Jonas Maebe: It's not "my style of programming". I've never used resourcestrings in my life (because I've never worked on a multilingual program, not because I've used something else instead). The compiler is a multilingual program and uses a different mechanism than resourcestrings ;) Though, @Rainer, that still won't help you. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal