Page 2 of 2
Re: Test code in includes
Posted: Wed Jan 18, 2012 11:42 am
by Perkin
Just gave jaPBe a small try, using the test files as given in earlier post.
Using the cutter plugin ..
Compiling to executable the MyTestProc2() is still added to final executable even though it isn't being called.
-----
As said in previous post, I think I'll just have to comment out the test code when not testing or have it in its own file.
Again thanks to all.
Re: Test code in includes
Posted: Wed Jan 18, 2012 11:56 am
by luis
Bisonte wrote:If you want "not included" unused procedures...
jaPBe has a "Cutter" Plugin, that shredder the code to one big file with only the used procedures...
(for the final compile its very useful...)
Does it really work ?
I wanted to make something of that kind myself but I given up.
http://www.purebasic.fr/english/viewtop ... 54#p369254
Just think of using one or more macros to build up a procedure body, or a procedure to be excluded by some conditional compilation. Does "cutter" works as expected here ? I doubt it.
Re: Test code in includes
Posted: Wed Jan 18, 2012 12:08 pm
by luis
Perkin wrote:
The resultant main project code runs as it should, but viewing the exe in a hex viewer, it looks like the MyTestProc2 is still included, even though it isn't called directly - only from the now not included test code.
The body of the procedure (the code) is not included, only its text (string) in the data section.
This is because the pb compiler generate all the code/data for all the procedures inside macros, and then SOME of them are never expanded.
http://www.purebasic.fr/english/viewtop ... 45#p318245
Code: Select all
;
; #INCLUDED=1
;
; Procedure MyTestProc()
macro MP0{
_Procedure0:
PS0=4
; MessageRequester("Hey","I am here!")
PUSH dword _S1
PUSH dword _S2
CALL _PB_MessageRequester@8
; EndProcedure
XOR eax,eax
_EndProcedure1:
RET
}
;
; Procedure MyTestProc2()
macro MP2{
_Procedure2:
PS2=4
; MessageRequester("Hey","I am here as well!")
PUSH dword _S3
PUSH dword _S2
CALL _PB_MessageRequester@8
; EndProcedure
XOR eax,eax
_EndProcedure3:
RET
}
;
; CompilerIf Defined(INCLUDED,#PB_Constant)=0
;
;
; MyTestProc()
CALL _Procedure0
_PB_EOP_NoValue:
PUSH dword 0
_PB_EOP:
CALL _PB_EndFunctions
PUSH dword [PB_MemoryBase]
CALL _HeapDestroy@4
CALL _ExitProcess@4
_PB_EndFunctions:
RET
;
MP0
;
section '.data' data readable writeable
;
_PB_DataSection:
_PB_OpenGLSubsystem: db 0
pb_public PB_DEBUGGER_LineNumber
dd -1
pb_public PB_DEBUGGER_IncludedFiles
dd 0
pb_public PB_DEBUGGER_FileName
db 0
_PB_ExecutableType: dd 0
public _SYS_StaticStringStart
_SYS_StaticStringStart:
_S1: db "I am here!",0
_S3: db "I am here as well!",0
_S2: db "Hey",0
pb_public PB_NullString
db 0
public _SYS_StaticStringEnd
_SYS_StaticStringEnd:
align 4
align 4
s_s:
dd 0
dd -1
align 4
;
section '.bss' readable writeable
_PB_BSSSection:
align 4
;
I_BSSStart:
_PB_MemoryBase:
PB_MemoryBase: rd 1
_PB_Instance:
PB_Instance: rd 1
;
align 4
PB_DataPointer rd 1
align 4
align 4
align 4
align 4
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection:
I really want a option to make the PB parser generate a single, expanded, preprocessed source for me.
Re: Test code in includes
Posted: Wed Jan 18, 2012 1:42 pm
by Bisonte
luis wrote:Bisonte wrote:If you want "not included" unused procedures...
jaPBe has a "Cutter" Plugin, that shredder the code to one big file with only the used procedures...
(for the final compile its very useful...)
Does it really work ?
I wanted to make something of that kind myself but I given up.
http://www.purebasic.fr/english/viewtop ... 54#p369254
Just think of using one or more macros to build up a procedure body, or a procedure to be excluded by some conditional compilation. Does "cutter" works as expected here ? I doubt it.
I think so... I tried it with the jaPBe source itself and it works there... only one big file and a lot of procedures are not
longer in the source.
Re: Test code in includes
Posted: Thu Jan 19, 2012 12:56 pm
by Perkin
luis wrote:Perkin wrote:
The resultant main project code runs as it should, but viewing the exe in a hex viewer, it looks like the MyTestProc2 is still included, even though it isn't called directly - only from the now not included test code.
The body of the procedure (the code) is not included, only its text (string) in the data section.
This is because the pb compiler generate all the code/data for all the procedures inside macros, and then SOME of them are never expanded.
So it's only the string data that's added?
I think that might be alright, I'll have to check through some of them to see.
Thanks.
Re: Test code in includes
Posted: Sat Jan 21, 2012 7:42 pm
by luis
Bisonte wrote:luis wrote:
Does it really work ?
I wanted to make something of that kind myself but I given up.
http://www.purebasic.fr/english/viewtop ... 54#p369254
Just think of using one or more macros to build up a procedure body, or a procedure to be excluded by some conditional compilation. Does "cutter" works as expected here ? I doubt it.
I think so... I tried it with the jaPBe source itself and it works there... only one big file and a lot of procedures are not
longer in the source.
A simple example, you can make it more convoluted and find many other "hard" cases
Code: Select all
; unused1()
Macro genproc_start()
Procedure unused1()
Debug "unused1()"
EndMacro
Macro genproc_end()
ProcedureReturn
EndProcedure
EndMacro
genproc_start()
genproc_end()
; unused2()
Procedure unused2()
unused1()
EndProcedure
; used1()
Procedure used1()
Debug "used1()"
ProcedureReturn
EndProcedure
Procedure Main()
used1()
EndProcedure
Main()
Perfectly valid, but fails with cutter and lead to the unneeded inclusion of unused1() with PB. As I said, I don't think there is a solution in existence working reliably.
Not until...
http://www.purebasic.fr/english/viewtop ... =3&t=40658
Re: Test code in includes
Posted: Mon Jan 23, 2012 5:58 pm
by Perkin
That looks like it would be good.
Re: Test code in includes
Posted: Tue Jan 24, 2012 9:46 pm
by blueznl
Two notes:
1. Trimming... look around, several tools were at one time posted. I hate the missing includes myself, so I added a 'trimming' version to CodeCaddy as well.
2. Includes... yeah, I would love to have a constant that would indicate if the include was executed by itself, or if it was included by another program. It would make it so much easier to maintain includes and quickly test them for bugs. I'd love it.
Re: Test code in includes
Posted: Wed Feb 15, 2012 8:31 am
by Sirius-2337
I would love to have a constant that would indicate if the include was executed by itself, or if it was included by another program.
You can do this by adding a Custom Constant in Compiler Options.
For example add "#IsExecutedByItself = 1". Then you can check whether the Constant is defined or not.
It won't be defined if the code is included by another code.