Page 2 of 2

Posted: Sat Mar 10, 2007 8:15 pm
by hagibaba
This is a good example of how when a procedure is not called it changes the size of the exe. The resulting file sizes are 12kb and 11.5kb, but the only difference in the code is that one is called and the other is not. Just thought I'd add this to clarify.

Code: Select all


Procedure.d Called()
 Protected a.d,b.d,c.d,d.d,e.d,f.d,g.d,h.d,i.d,j.d
 a=1 : b=2 : c=3 : d=4 : e=5 : f=6 : g=7 : h=8 : i=9 : j=10
 a+a : b+b : c+c : d+d : e+e : f+f : g+g : h+h : i+i : j+j
 ProcedureReturn a
EndProcedure

If OpenWindow(0, 100, 200, 195, 260, "PB Window")
 
 MessageRequester("Info", "test1="+StrD(Called()), 0)
 
 Repeat
  EventID = WaitWindowEvent()
  If EventID = #PB_Event_CloseWindow
   Quit = 1
  EndIf
 Until Quit = 1
 
EndIf
End

Code: Select all


Procedure.d NotCalled()
 Protected a.d,b.d,c.d,d.d,e.d,f.d,g.d,h.d,i.d,j.d
 a=1 : b=2 : c=3 : d=4 : e=5 : f=6 : g=7 : h=8 : i=9 : j=10
 a+a : b+b : c+c : d+d : e+e : f+f : g+g : h+h : i+i : j+j
 ProcedureReturn a
EndProcedure

If OpenWindow(0, 100, 200, 195, 260, "PB Window")

 MessageRequester("Info", "test2="+StrD(0), 0)
 
 Repeat
  EventID = WaitWindowEvent()
  If EventID = #PB_Event_CloseWindow
   Quit = 1
  EndIf
 Until Quit = 1
 
EndIf
End


Posted: Sun Mar 11, 2007 4:32 am
by SkyManager
My latest tests show that :
All functions/procedures are included in the final exe.

Posted: Sun Mar 11, 2007 8:32 am
by Fred
Functions are included only if they are referenced somewhere (even in a non referenced function). If there is no use at all, it will be skipped.

Posted: Sun Mar 11, 2007 8:49 am
by PB
But that is at odds with my DeleteFile example, where the Procedure is never
referenced, but the API command is still included as part of the executable.

Posted: Sun Mar 11, 2007 8:56 am
by Fred
Yes, only the code body of the function isn't included, not the commands used in it. It should be changed somewhen.

Posted: Sun Mar 11, 2007 11:09 am
by Derek
That's what I thought happened, I knew that as soon as you used any command for the forst time then it was added to the exe. I just thought that first time used commands in unreferenced procedures were not added either, so I wasn't completely wrong. :wink:

Posted: Sun Mar 11, 2007 5:14 pm
by SkyManager
However, most of the procedures are calling one another.

For example, in an included PB,

Code: Select all

Procedure  GetFormLayout()
EndProcedure  
Procedure  GetDisplayItem()
  GetFormLayout()
EndProcedure  
Procedure  DisplayToScreen()
  GetDisplayItem()
EndProcedure  
When DisplayToScreen() is not used, all the referenced procedures should not be referenced although they are referenced by others, isn't it?

Posted: Sun Mar 11, 2007 10:37 pm
by Kaeru Gaman
SkyManager wrote:When DisplayToScreen() is not used, all the referenced procedures should not be referenced although they are referenced by others, isn't it?
yay, what a sentence... 8)

I think it will be quite complex if not even impossible, to implement such in a one-pass-compiler, no?

Posted: Mon Mar 12, 2007 9:11 am
by PB
> I think it will be quite complex if not even impossible, to implement such
> in a one-pass-compiler, no?

It's not possible with a one-pass compiler.

Posted: Mon Mar 12, 2007 9:46 am
by Trond
It's possible, but it would be a lot of work.

Posted: Mon Mar 12, 2007 9:56 am
by PB
I don't see how it's possible in one pass, even with declares. Care to elaborate?

Posted: Mon Mar 12, 2007 11:38 am
by Trond
Fasm's macro feature must be used, so it's not fully one-pass, but the point is that when the progam is compiled, each thing (procedure, string, etc...) has a list of which scopes it is used. At the end, the compiler can look at the information to know what to do. For example:

Code: Select all

Procedure.l IsUsed(Proc)
  If UsedFromMain(Proc)
    ProcedureReturn 1
  Else
    For Each Procedure where Proc is used -> UsedFrom
      If IsUsed(UsedFrom)
        ProcedureReturn 1
      EndIf
    Next
  Endif
  ProcedureReturn 0
EndProcedure

For Each Procedure -> Proc
  If IsUsed(Proc)
    EmitMacroNumber(Proc)
  EndIf
Next

Posted: Mon Mar 12, 2007 2:13 pm
by Kaeru Gaman
> when the progam is compiled, each thing (procedure, string, etc...) has a list of which scopes it is used.

to create this list is one additional pass before the one you call "when it's compiled"

Posted: Mon Mar 12, 2007 4:23 pm
by Trond
Kaeru Gaman wrote:> when the progam is compiled, each thing (procedure, string, etc...) has a list of which scopes it is used.

to create this list is one additional pass before the one you call "when it's compiled"
No, this info can be created in the same pass as the compilation. Then the procedures are placed in macros, and the macro is used once at the bottom of the source if the procedure is used.

Posted: Mon Mar 12, 2007 6:05 pm
by Thalius
Dunno if am right here but cant you use ( depending on the Situation ) CompilerIF's to include only the functions you would liek to use?

eg.

Code: Select all

CompilerIf Defined(MYLIB_COMPILER_SERVERMODE,#PB_Constant)
  --> Server Only Functions ...
CompilerElse
  --> Client Functions ...
CompilerEndIf
ofc you had to do it also for teh Declares -- its not too nice but my tests have shown a big difference in sizes. Atm am working on a Game Networklib.

Cheers, Thalius