Page 2 of 2
Re: IDE tool for viewing the ASM for your PB source.
Posted: Sun Mar 20, 2011 2:57 pm
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.
Re: IDE tool for viewing the ASM for your PB source.
Posted: Sun Mar 20, 2011 4:50 pm
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
;
Re: IDE tool for viewing the ASM for your PB source.
Posted: Sun Mar 20, 2011 6:27 pm
by luis
LOL I found the reason
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.
Re: IDE tool for viewing the ASM for your PB source.
Posted: Sun Mar 20, 2011 6:47 pm
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.
Re: IDE tool for viewing the ASM for your PB source.
Posted: Sun Mar 20, 2011 6:49 pm
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.
Re: IDE tool for viewing the ASM for your PB source.
Posted: Sun Mar 20, 2011 6:51 pm
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()
Re: IDE tool for viewing the ASM for your PB source.
Posted: Sun Dec 30, 2012 12:25 am
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
Re: IDE tool for viewing the ASM for your PB source.
Posted: Fri Sep 11, 2015 9:54 pm
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