IDE tool for viewing the ASM for your PB source.

Share your advanced PureBasic knowledge/code with the community.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: IDE tool for viewing the ASM for your PB source.

Post by luis »

[fast forward]
Demivec wrote: I tested your code and did not observe this; the second message was never displayed after the assembled code was loaded in notepad.
OK, thanks. It happens to me using 4.51 x86 under win7 64 bit, and only using the exe.

I found this a little disturbing, but if it's happening only to me I'll try to investigate the reason later by myself.

I'll try it in a fresh installation (using virtual machines) on both Win7 32 and Win7 64 and see what happen.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: IDE tool for viewing the ASM for your PB source.

Post by luis »

Tested with a fresh installation of PB 4.51 x86 under Windows XP, Windows 7 x86, Windows 7 x64.

Just compiled the source listed in my post, defined as a tool, specified "%TEMPFILE" as parameter (with the quotes).

In all of the cases, the message "How come I'm visualized even when the test is successful ?" is shown.

I don't see how can be happening, the code generated is this, looks ok to me.
After running the notepad, the incriminated message is skipped (but only in the code below, not when running the prog).

Maybe I have to look at the actual exe.

Code: Select all


[omissis]

  AND    eax,eax
  JE    _EndIf4
; RunProgram("notepad.exe", dir$,"")
  PUSH   dword _S5
  PUSH   dword [v_dir$]
  PUSH   dword _S6
  CALL  _PB_RunProgram2@12
; Else
  JMP   _EndIf3
_EndIf4:
; MessageRequester("Error!", "There was an error creating the assembly code file.")
  PUSH   dword _S7
  PUSH   dword _S8
  CALL  _PB_MessageRequester@8
; EndIf
_EndIf3:
; Else
  JMP   _EndIf1
_EndIf2:
; MessageRequester("What?", "How come I'm visualized even when the test is successful ?")
  PUSH   dword _S9
  PUSH   dword _S10
  CALL  _PB_MessageRequester@8
; EndIf
_EndIf1:
_PB_EOP_NoValue:
  PUSH   dword 0
_PB_EOP:
  CALL  _PB_EndFunctions
  PUSH   dword [PB_MemoryBase]
  CALL  _HeapDestroy@4
  CALL  _ExitProcess@4
_PB_EndFunctions:
  RET
; 
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: IDE tool for viewing the ASM for your PB source.

Post by luis »

LOL I found the reason :lol:

A set of things went together to make my life miserable.

First thing: pbcompiler.exe executes the generated exe file. It's something unusual I *never* come across with *any* other compiler I used, and I completely forgot this. I normally expect a compiler/linker to generate the exe and then quit. This was the main ingredient.

But that's more, for testing the "tool" just added to the tools menu initially I used the source of the tool itself.

The result? The "exe" version of the tool was running, generating the Purebasic.asm then loaded in the editor, but at the same time the pbcompiler was executing the generated exe too, and so that copy not having a valid file as parameter was showing the right/wrong messagebox !

So on the screen I was seeing the notepad opened by the "tool" version of the source and the impossible messagebox opened by the other copy of the tool just compiled and executed.

No suprise the asm was looking right.

Sometimes this marvelous things just happen, especially to me.
"Have you tried turning it off and on again ?"
A little PureBasic review
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: IDE tool for viewing the ASM for your PB source.

Post by freak »

luis wrote:First thing: pbcompiler.exe executes the generated exe file. It's something unusual I *never* come across with *any* other compiler I used, and I completely forgot this. I normally expect a compiler/linker to generate the exe and then quit. This was the main ingredient.
It only does this if there is no /EXE switch present that specifies the output executable.
quidquid Latine dictum sit altum videtur
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: IDE tool for viewing the ASM for your PB source.

Post by luis »

Demivec wrote:You didn't indicate anything else happened so I assumed it was because the filename and path were incorrectly constructed. I had corrected this code for myself and referred you to my previous post.
BTW, the number of "\", being "\" or even "\\\\" doesn't seem to be a problem. It works anyway.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: IDE tool for viewing the ASM for your PB source.

Post by luis »

freak wrote: It only does this if there is no /EXE switch present that specifies the output executable.
Yes, thanks, I noticed, nice to know :)

It was my fault, I really forgot. Already stumbled on this "auto-run" thing some years ago ... but it's so unusual I keep forgetting.

Maybe this time will stick in my mind.

Code: Select all

EnableExplicit

#COMPILER_OPTIONS$ = "/XP /USER"

#EDITOR$ = "c:\Program Files (x86)\Notepad++\notepad++.exe" 


Procedure Main()
 Protected pb_file$ = ProgramParameter(0)
 Protected pb_file_dir$ = GetPathPart(pb_file$)
 Protected asm_file$ = pb_file_dir$ + "PureBasic.asm"
 Protected compiler_exe$ = GetEnvironmentVariable("PB_TOOL_Compiler")
 Protected temp$ = GetEnvironmentVariable("TEMP")
 Protected editor_exe$ = #EDITOR$
 Protected options$ = #COMPILER_OPTIONS$ 
 Protected compiler 
 
 DeleteFile(asm_file$)

 If (Len(pb_file$) > 0 And FileSize(pb_file$) > 0)    
    ; the asm file is created in the working dir
    compiler = RunProgram(compiler_exe$, Chr(34) + pb_file$ + Chr(34)+" /COMMENTED /EXE " + temp$ + "\out.exe " + options$, pb_file_dir$, #PB_Program_Hide | #PB_Program_Wait)
    
    If compiler         
        If FileSize(asm_file$) >= 0
            RunProgram(editor_exe$, asm_file$,"")
        Else
            MessageRequester("ASM source not found !", Chr(34) + asm_file$ + Chr(34) + " not found.")
        EndIf        
    EndIf
 Else
    MessageRequester("PB source not found !", Chr(34) + pb_file$ + Chr(34) + " not found.")         
 EndIf
 
EndProcedure

Main()

"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: IDE tool for viewing the ASM for your PB source.

Post by Tenaja »

I seem to be having an issue with this (srod's initial code) when trying to compile with Included files. The simple test files run perfectly normally, but when I try to run it with the CommentedASM tool, it will not generate the asm unless I comment out the Include (and proc call).

Has anybody dealt with this?

Thanks...

Main.pb:

Code: Select all

IncludeFile "Include File INC.pb"
 Debug "In MAIN"
IncProc()
Include File INC.pb:

Code: Select all

Debug "In Included file"

Procedure IncProc()
	Debug "IncProc"
EndProcedure
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: IDE tool for viewing the ASM for your PB source.

Post by Keya »

Here is my version, i started with luis' code as template but modified it quite a bit, it now also supports Mac and Linux as well as Windows as I am trying to learn how Purebasic executables are different on each OS :)

Code: Select all

EnableExplicit

Procedure AppMain()
  Protected pb_openfile$, pb_compiler$, pb_options$, srcfile$, savedir$, pb_asmfile$, pb_compiledbin$, pb_flags$, pb_asmfiletxt$, hcompiler.i
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    pb_openfile$ = "notepad"
    pb_compiledbin$ = "~tmpcompile.exe"
    pb_flags$ = "/COMMENTED /EXE"
  CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
    pb_openfile$ = "xdg-open"
    pb_compiledbin$ = "~tmpcompile.elf"
    pb_flags$ = "--commented --executable"
  CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
    pb_openfile$ = "open"
    pb_compiledbin$ = "~tmpcompile.mach" ;.app
    pb_flags$ = "--commented --executable"
  CompilerEndIf       
  
  srcfile$=ProgramParameter(0)   
  If (Len(srcfile$) > 0 And FileSize(srcfile$) > 0)   
    pb_compiler$ = #PB_Compiler_Home + "/compilers/pbcompiler"
    pb_options$ = " " + pb_flags$ + " " + Chr(34) + GetHomeDirectory() + pb_compiledbin$ + Chr(34)  
    savedir$ = GetTemporaryDirectory()
    pb_asmfile$ = savedir$+"purebasic.asm"
    pb_asmfiletxt$ = pb_asmfile$ + ".txt"
    DeleteFile(pb_asmfile$): DeleteFile(pb_asmfiletxt$)
    hcompiler.i = RunProgram(pb_compiler$, Chr(34) + srcfile$ + Chr(34) + pb_options$, savedir$, #PB_Program_Hide | #PB_Program_Wait)   
    If hcompiler         
      Delay(500)
      If FileSize(pb_asmfile$) >= 0
        RenameFile(pb_asmfile$, pb_asmfiletxt$)
        MessageRequester("OK","Saved to " + pb_asmfiletxt$ + #CRLF$ + "Filesize " + Str(FileSize(pb_asmfiletxt$)) + " bytes")               
        RunProgram(pb_openfile$, Chr(34) + pb_asmfiletxt$ + Chr(34),savedir$)
      Else
        MessageRequester("ASM source not found", "Not found: " + pb_asmfile$)
      EndIf       
    EndIf
  Else
    MessageRequester("PB source not found", "Not found: " + srcfile$)         
  EndIf
EndProcedure

AppMain()
Setup: in Configure Tools, simply point it to the compiled binary, and set the parameters to (with quote chars): "%FILE"
When setting it up for Mac make sure you point it at the actual compiled mach-o binary in the \Contents\ subdir of the .app, not the .app itself
I rename the output from purebasic.asm to purebasic.asm.txt so that it can load in default text editor
Post Reply