PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Du brauchst Grafiken, gute Programme oder Leute die dir helfen? Frag hier.
Wolfram
Beiträge: 28
Registriert: 23.08.2013 14:38
Computerausstattung: OSX 10.13 | PB 5.46

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von Wolfram »

Ähm… :? Wenn "open" wirklich erforderlich ist, um ein Tool zu starten, dann frage ich mich, warum das PB nicht selber korrekt handhabt.
Was passiert, wenn in Commandline nur der Dateipfad zum Tool und die Parameter in Arguments angegeben werden? Wird das Tool dann nicht aufgerufen?
showAssabler.app ist ein Paket (ein Ordner mit einer Extension) dort kann man keine args übergeben.
Entweder den Befehl auf "/deinPfad/showAssabler.app/Contens/MacOS/showAssabler" ändern oder das Tool als Commandline kompilieren, dann geht es ohne open.

Nur damit der Code sauberer aussieht oder gibt es noch andere Gründe dafür?
So wie Du es geschrieben hast wird der Fensterinhalt verzögert neu berechnet. Mit BindEvend() ist es flüssig.
Ich weiß nicht ob das nur unter OSX so ist, glaube ich aber nicht.
OSX 10.13 | PB 5.46
Benutzeravatar
Sicro
Beiträge: 923
Registriert: 11.08.2005 19:08
Kontaktdaten:

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von Sicro »

Danke Wolfram für die Aufklärung. :allright:
Den Code werde ich entsprechend anpassen.
Bild
Warum OpenSource eine Lizenz haben sollte :: DarkColor-Schema für PureBasic
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Jede Hilfe ist willkommen!
Manjaro Xfce x64 (Hauptsystem) :: Windows 7 x64 (VirtualBox) :: Neueste PureBasic-Version
Benutzeravatar
mk-soft
Beiträge: 3361
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von mk-soft »

Bei macOS geht es auch wenn man den gesamten Path zum Programm angibt...

Beispiel
/Users/Michael/Daten/Purebasic/displayASM.app/Contents/MacOS/displayASM
Apps... schon geklärt :wink:

P.S. Da ich oft ThreadSafe arbeite, habe ich die Compiler-Option "--thread" hinzugefügt.

Code: Alles auswählen

; Run the PB compiler to create the ASM code file
program = RunProgram(compilerFilePath$,
                     #DQUOTE$ + codeFilePath$ + #DQUOTE$ + " --commented --thread --executable " + #DQUOTE$ + exeFilePath$ + #DQUOTE$,
                     workingDirectoryPath$,
                     #PB_Program_Open | #PB_Program_Read)
P.P.S Habe mir noch den Compiler Output dazu gepackt, falls der Compiler mit Fehler beendet wird

Code: Alles auswählen

; If an error has occurred, output detailed information
If isCompilerError Or asmCode$ = ""
  MessageRequester(#ErrorWindowTitle, "Tool could not create the asm output!" + #CRLF$ +
                                      #CRLF$ + #CRLF$ +
                                      "Compiler File Path:"        + #CRLF$ + compilerFilePath$     + #CRLF$ + #CRLF$ +
                                      "Compiler Working Dir Path:" + #CRLF$ + workingDirectoryPath$ + #CRLF$ + #CRLF$ +
                                      "Code File Path:"            + #CRLF$ + codeFilePath$         + #CRLF$ + #CRLF$ +
                                      "ASM Code File Path:"        + #CRLF$ + asmCodeFilePath$      + #CRLF$ + #CRLF$ +
                                      "EXE File Path:"             + #CRLF$ + exeFilePath$          + #CRLF$ + #CRLF$ +
                                      "Compiler Output:"            + #CRLF$ + compilerOutput$,
                   #PB_MessageRequester_Error)
  End
EndIf
Danke fürs Tool :allright:
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul / OPC-Helper DLL
PB v3.30 / v5.7x - OS Mac Mini OSX 10.xx / Window 10 Pro. (X64) /Window 7 Pro. (X64) / Window XP Pro. (X86) / Ubuntu 14.04
Downloads auf My Webspace
Benutzeravatar
Sicro
Beiträge: 923
Registriert: 11.08.2005 19:08
Kontaktdaten:

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von Sicro »

Danke @Wolfram und @mk-soft für die Hinweise und Verbesserungsvorschläge :allright:

Changelog:
  • Use module 'OpenStandardProgram'
  • Use 'BindEvent()' for '#PB_Event_SizeWindow' events
  • Use 'PB_Tool_Compiler' instead of '%HOME'
  • Use compiler options of the current code
  • Add MacOS 'Application' menu support
  • Add more information to the error output
  • Add more information to the ASM output
  • Remove ASM file after reading
  • Add a note for MacOS to the setting descriptions of the PB-IDE-Tools
Bild
Warum OpenSource eine Lizenz haben sollte :: DarkColor-Schema für PureBasic
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Jede Hilfe ist willkommen!
Manjaro Xfce x64 (Hauptsystem) :: Windows 7 x64 (VirtualBox) :: Neueste PureBasic-Version
Benutzeravatar
mk-soft
Beiträge: 3361
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von mk-soft »

Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul / OPC-Helper DLL
PB v3.30 / v5.7x - OS Mac Mini OSX 10.xx / Window 10 Pro. (X64) /Window 7 Pro. (X64) / Window XP Pro. (X86) / Ubuntu 14.04
Downloads auf My Webspace
Benutzeravatar
mk-soft
Beiträge: 3361
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von mk-soft »

Hallo Sicro,

Für C-backend angepasst.

Update 28.11.2021
- Angepasst für C-Code
- Überprüfung und Korrektur Environment Variable "PB_TOOL_Compiler"
- PB Editor Standard Konstanten hinzugefügt
- Ausgabe in Standard Editor und Zwischenablage den C-Code ohne eigenen Header
- Include Dateien Abhängigkeiten aufgelöst

Update 20.12.2021
- Bei Arm32/64 ist Compiler name "pbcompiler". Auch wenn es ein immer C-Backend ist

displayCcode.pb

Code: Alles auswählen

;-Description   : Displays the commented C code from the PB compiler
; OS            : Windows, Linux, Mac
; English-Forum :
; French-Forum  :
; German-Forum  : https://www.purebasic.fr/german/viewtopic.php?f=10&t=30935
; 
; Author        : Sicro
; Author second : mk-soft (Modified for C-Code)
; Update        : C-Code    , 28.11.2021
; Update        : Arm32/64  , 20.12.2021

; -----------------------------------------------------------------------------

; MIT License
;
; Copyright (c) 2018-2020 Sicro
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.

; Tool Settings:
; - Arguments: "%FILE" "%TEMPFILE"
; - Event:     Menu Or Shortcut
; For MacOS, the field "Commandline" must contain the full path to the executable
; file, e.g.: .../Program.app/Contents/MacOS/Program

EnableExplicit

; =============
;-Include Codes
; =============

Procedure.i OpenWithStandardProgram(FilePath$)
  
  Protected Result
  
  ; Avoid problems with paths containing spaces
  FilePath$ = #DQUOTE$ + FilePath$ + #DQUOTE$
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ; https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shellexecutew
      Result = Bool(ShellExecute_(0, "open", FilePath$, #Null, #Null, #SW_SHOW) > 32)
    CompilerCase #PB_OS_Linux
      ; https://portland.freedesktop.org/doc/xdg-open.html
      Result = Bool(RunProgram("xdg-open", FilePath$, GetCurrentDirectory()))
    CompilerCase #PB_OS_MacOS
      Result = Bool(RunProgram("open", FilePath$, GetCurrentDirectory()))
  CompilerEndSelect
  
  ProcedureReturn Result
  
EndProcedure

;XIncludeFile "../File/GetFileContentAsString.pbi"

; ================
;-Define Constants
; ================

#Program_Name     = "Display C-Code"
#ErrorWindowTitle = #Program_Name + " - ERROR"

#Window_Main = 0

Enumeration Gadget
  #Editor_Output
  #Button_OpenStandardEditor
  #Button_CopyToClipboard
EndEnumeration

; ======================
;-Define Local Variables
; ======================

Define compilerHomePath$, compilerFilePath$, workingDirectoryPath$, codeFilePath$, codeTempFilePath$,
       asmCodeFilePath$, exeFilePath$, outputFilePathForStandardProgram$, compilerParameters$,
       compilerUserParameters$
Define asmCode$, output$, compilerOutput$
Define program, file, event, isCompilerError, countOfParameters, i, isLibrary

; ==============================
;-Set Values For Local Variables
; ==============================

outputFilePathForStandardProgram$ = GetTemporaryDirectory() + RemoveString(#Program_Name, " ") + "-Output.txt"

compilerFilePath$ = GetEnvironmentVariable("PB_TOOL_Compiler")
If compilerFilePath$ = ""
  MessageRequester("Info", "Run only as PB-IDE Tool", #PB_MessageRequester_Info)
  End
EndIf

CompilerSelect #PB_Compiler_Processor
  CompilerCase #PB_Processor_Arm32
    
  CompilerCase #PB_Processor_Arm64
    
  CompilerDefault
    If Not FindString(compilerFilePath$, "pbcompilerc")
      compilerFilePath$   = ReplaceString(compilerFilePath$, "pbcompiler", "pbcompilerc")
    EndIf
    
CompilerEndSelect

compilerHomePath$ = GetPathPart(compilerFilePath$)
codeFilePath$     = ProgramParameter(0) ; "%FILE"
codeTempFilePath$ = ProgramParameter(1) ; "%TEMPFILE"

If codeFilePath$ = ""
  ; The code has not yet been saved
  ; Use the path of the auto-generated temp code file
  codeFilePath$ = codeTempFilePath$
EndIf

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  asmCodeFilePath$ = compilerHomePath$ + "purebasic.c"
CompilerElse
  asmCodeFilePath$ = GetPathPart(codeFilePath$) + "purebasic.c"
CompilerEndIf

; The EXE file is only created so that the PB compiler does not execute the code, but only creates the ASM code
exeFilePath$ = GetTemporaryDirectory() + "purebasic"

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  workingDirectoryPath$ = GetPathPart(compilerFilePath$)
CompilerElse
  workingDirectoryPath$ = GetPathPart(codeFilePath$)
CompilerEndIf

compilerParameters$ = "--commented -o PB_Editor_BuildCount=0 -o PB_Editor_CompileCount=0"

If Val(GetEnvironmentVariable("PB_TOOL_Thread"))
  compilerParameters$ + " --thread"
EndIf

If Val(GetEnvironmentVariable("PB_TOOL_Unicode"))
  compilerParameters$ + " --unicode"
EndIf

If GetEnvironmentVariable("PB_TOOL_SubSystem")
  compilerParameters$ + " --subsystem " + GetEnvironmentVariable("PB_TOOL_SubSystem")
EndIf

Procedure$ ProcessParameter(parameter$, exeFilePath$, *isLibrary.Integer)
  Select LCase(parameter$)
    Case "-dl", "--dylib", "-so", "--sharedobject"
      parameter$ = parameter$ + " " + #DQUOTE$ + exeFilePath$ + #DQUOTE$
      *isLibrary\i = #True
    Case "/dll"
      parameter$ = "--executable " + #DQUOTE$ + exeFilePath$ + #DQUOTE$ + parameter$
      *isLibrary\i = #True
  EndSelect
  ProcedureReturn parameter$
EndProcedure

; Get user parameters
countOfParameters = CountProgramParameters()
For i = 2 To countOfParameters - 1
  compilerUserParameters$ + " " + ProcessParameter(ProgramParameter(i), exeFilePath$, @isLibrary)
Next
If Not isLibrary
  compilerParameters$ + " --executable " + #DQUOTE$ + exeFilePath$ + #DQUOTE$
EndIf
compilerParameters$ + compilerUserParameters$

; =======================
;-Delete Old Output Files
; =======================

; Make sure that there are no previous output files, to prevent old output files from being read, if an error occurs.
DeleteFile(asmCodeFilePath$)
DeleteFile(exeFilePath$)

; ====================
;-Create ASM Code File
; ====================

; Run the PB compiler to create the ASM code file
program = RunProgram(compilerFilePath$,
                     #DQUOTE$ + codeFilePath$ + #DQUOTE$ + " " + compilerParameters$,
                     workingDirectoryPath$,
                     #PB_Program_Open | #PB_Program_Read)

; Read the PB compiler output
If program
  While ProgramRunning(program)
    While AvailableProgramOutput(program)
      compilerOutput$ + ReadProgramString(program) + #CRLF$
    Wend
  Wend
  isCompilerError = Bool(ProgramExitCode(program))
  CloseProgram(program)
Else
  isCompilerError = #True
EndIf

; Read the ASM code file
file = ReadFile(#PB_Any, asmCodeFilePath$)
If file
  asmCode$ + ReadString(file, #PB_File_IgnoreEOL)
  CloseFile(file)
EndIf

; If an error has occurred, output detailed information
If isCompilerError Or asmCode$ = ""
  MessageRequester(#ErrorWindowTitle, "Tool could not create the asm output!" +
                                      #CRLF$ + #CRLF$ +
                                      "Note that the PB compiler only generates ASM output if the PB code is syntaxically correct!" +
                                      #CRLF$ + #CRLF$ +
                                      "-------------------------------------" +
                                      #CRLF$ + #CRLF$ +
                                      "Compiler File Path:"        + #CRLF$ + compilerFilePath$     + #CRLF$ + #CRLF$ +
                                      "Compiler Parameters:"       + #CRLF$ + compilerParameters$   + #CRLF$ + #CRLF$ +
                                      "Compiler Working Dir Path:" + #CRLF$ + workingDirectoryPath$ + #CRLF$ + #CRLF$ +
                                      "ASM Code File Path:"        + #CRLF$ + asmCodeFilePath$      +
                                      #CRLF$ + #CRLF$ +
                                      "-------------------------------------" +
                                      #CRLF$ + #CRLF$ +
                                      "Compiler Output:"           + #CRLF$ + compilerOutput$,
                   #PB_MessageRequester_Error)
  End
EndIf

; Remove the ASM file only if no error occurred to avoid removing error traces
DeleteFile(exeFilePath$)

output$ = "##############################################" + #CRLF$ +
          "Compiler File Path: "  + compilerFilePath$      + #CRLF$ +
          "Compiler Parameters: " + compilerParameters$    + #CRLF$ +
          "ASM Code File Path:"   + asmCodeFilePath$       + #CRLF$ +
          #CRLF$ +
          "##############################################" + #CRLF$ +
          compilerOutput$ + #CRLF$ +
          "##############################################" + #CRLF$ +
          #CRLF$ +
          asmCode$

; =============================
;-Create ASM Code Output Window
; =============================

Procedure UpdateWindow()
  ResizeGadget(#Editor_Output, #PB_Ignore, #PB_Ignore, WindowWidth(#Window_Main), WindowHeight(#Window_Main) - 40)
  ResizeGadget(#Button_OpenStandardEditor, 5, GadgetHeight(#Editor_Output) + 5, WindowWidth(#Window_Main) / 2 - 8, #PB_Ignore)
  ResizeGadget(#Button_CopyToClipboard, GadgetWidth(#Button_OpenStandardEditor) + 10, GadgetHeight(#Editor_Output) + 5,
               WindowWidth(#Window_Main) / 2 - 8, #PB_Ignore)
EndProcedure
 
; Display the ASM code in an EditorGadget
If Not OpenWindow(#Window_Main, #PB_Ignore, #PB_Ignore, 500, 500, #Program_Name, #PB_Window_SystemMenu | #PB_Window_SizeGadget |
                                                                                 #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
  MessageRequester(#ErrorWindowTitle, "The program window could not be created!", #PB_MessageRequester_Error)
  End
EndIf

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  If Not IsMenu(#Window_Main)
    CreateMenu(0, WindowID(#Window_Main))
  EndIf
  
  ;MenuItem(#PB_Menu_About, "")
  ;MenuItem(#PB_Menu_Preferences, "")
  MenuItem(#PB_Menu_Quit, "")
CompilerEndIf

EditorGadget(#Editor_Output, 0, 0, WindowWidth(#Window_Main), WindowHeight(#Window_Main) - 40)
ButtonGadget(#Button_OpenStandardEditor, 5, GadgetHeight(#Editor_Output) + 5, WindowWidth(#Window_Main) / 2 - 8, 30, "Open Standard Editor")
ButtonGadget(#Button_CopyToClipboard, GadgetWidth(#Button_OpenStandardEditor) + 10, GadgetHeight(#Editor_Output) + 5,
             WindowWidth(#Window_Main) / 2 - 8, 30, "Copy To Clipboard")
SetGadgetText(#Editor_Output, output$)

BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Window_Main)

Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_OpenStandardEditor
          If Not OpenWithStandardProgram(asmCodeFilePath$)
            file = CreateFile(#PB_Any, outputFilePathForStandardProgram$)
            If file
              WriteStringN(file, asmCode$)
              CloseFile(file)
            EndIf
            If Not OpenWithStandardProgram(outputFilePathForStandardProgram$)
              MessageRequester(#ErrorWindowTitle, "The output could not be opened in the standard editor!", #PB_MessageRequester_Error)
            EndIf
          EndIf
        Case #Button_CopyToClipboard
          SetClipboardText(asmCode$)
      EndSelect
    Case #PB_Event_Menu
      CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
        ; MacOS 'Application' menu
        Select EventMenu()
          Case #PB_Menu_About
          Case #PB_Menu_Preferences
          Case #PB_Menu_Quit
            Break
        EndSelect
      CompilerEndIf
  EndSelect
Until event = #PB_Event_CloseWindow
Zuletzt geändert von mk-soft am 20.12.2021 22:06, insgesamt 2-mal geändert.
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul / OPC-Helper DLL
PB v3.30 / v5.7x - OS Mac Mini OSX 10.xx / Window 10 Pro. (X64) /Window 7 Pro. (X64) / Window XP Pro. (X86) / Ubuntu 14.04
Downloads auf My Webspace
Benutzeravatar
mk-soft
Beiträge: 3361
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von mk-soft »

Update 28.11.2021
- Angepasst für ASM-Code
- Überprüfung und Korrektur Environment Variable "PB_TOOL_Compiler"
- PB Editor Standard Konstanten hinzugefügt
- Ausgabe in Standard Editor und Zwischenablage den asmCode ohne eigenen Header
- Include Dateien Abhängigkeiten aufgelöst

displayASMcode.pb

Code: Alles auswählen

;-Description   : Displays the commented ASM code from the PB compiler
; OS            : Windows, Linux, Mac
; English-Forum :
; French-Forum  :
; German-Forum  : https://www.purebasic.fr/german/viewtopic.php?f=10&t=30935
; 
; Author        : Sicro
; Author second : mk-soft
; Update        : 28.11.2021

; -----------------------------------------------------------------------------

; MIT License
;
; Copyright (c) 2018-2020 Sicro
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.

; Tool Settings:
; - Arguments: "%FILE" "%TEMPFILE"
; - Event:     Menu Or Shortcut
; For MacOS, the field "Commandline" must contain the full path to the executable
; file, e.g.: .../Program.app/Contents/MacOS/Program

EnableExplicit

; =============
;-Include Codes
; =============

Procedure.i OpenWithStandardProgram(FilePath$)
  
  Protected Result
  
  ; Avoid problems with paths containing spaces
  FilePath$ = #DQUOTE$ + FilePath$ + #DQUOTE$
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ; https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shellexecutew
      Result = Bool(ShellExecute_(0, "open", FilePath$, #Null, #Null, #SW_SHOW) > 32)
    CompilerCase #PB_OS_Linux
      ; https://portland.freedesktop.org/doc/xdg-open.html
      Result = Bool(RunProgram("xdg-open", FilePath$, GetCurrentDirectory()))
    CompilerCase #PB_OS_MacOS
      Result = Bool(RunProgram("open", FilePath$, GetCurrentDirectory()))
  CompilerEndSelect
  
  ProcedureReturn Result
  
EndProcedure

;XIncludeFile "../File/GetFileContentAsString.pbi"

; ================
;-Define Constants
; ================

#Program_Name     = "Display ASM Code"
#ErrorWindowTitle = #Program_Name + " - ERROR"

#Window_Main = 0

Enumeration Gadget
  #Editor_Output
  #Button_OpenStandardEditor
  #Button_CopyToClipboard
EndEnumeration

; ======================
;-Define Local Variables
; ======================

Define compilerHomePath$, compilerFilePath$, workingDirectoryPath$, codeFilePath$, codeTempFilePath$,
       asmCodeFilePath$, exeFilePath$, outputFilePathForStandardProgram$, compilerParameters$,
       compilerUserParameters$
Define asmCode$, output$, compilerOutput$
Define program, file, event, isCompilerError, countOfParameters, i, isLibrary

; ==============================
;-Set Values For Local Variables
; ==============================

outputFilePathForStandardProgram$ = GetTemporaryDirectory() + RemoveString(#Program_Name, " ") + "-Output.txt"

compilerFilePath$ = GetEnvironmentVariable("PB_TOOL_Compiler")
If compilerFilePath$ = ""
  MessageRequester("Info", "Run only as PB-IDE Tool", #PB_MessageRequester_Info)
  End
EndIf

If FindString(compilerFilePath$, "pbcompilerc")
    compilerFilePath$   = ReplaceString(compilerFilePath$, "pbcompilerc", "pbcompiler")
EndIf
compilerHomePath$ = GetPathPart(compilerFilePath$)
codeFilePath$     = ProgramParameter(0) ; "%FILE"
codeTempFilePath$ = ProgramParameter(1) ; "%TEMPFILE"

If codeFilePath$ = ""
  ; The code has not yet been saved
  ; Use the path of the auto-generated temp code file
  codeFilePath$ = codeTempFilePath$
EndIf

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  asmCodeFilePath$ = compilerHomePath$ + "purebasic.asm"
CompilerElse
  asmCodeFilePath$ = GetPathPart(codeFilePath$) + "purebasic.asm"
CompilerEndIf

; The EXE file is only created so that the PB compiler does not execute the code, but only creates the ASM code
exeFilePath$ = GetTemporaryDirectory() + "purebasic"

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  workingDirectoryPath$ = GetPathPart(compilerFilePath$)
CompilerElse
  workingDirectoryPath$ = GetPathPart(codeFilePath$)
CompilerEndIf

compilerParameters$ = "--commented -o PB_Editor_BuildCount=0 -o PB_Editor_CompileCount=0"

If Val(GetEnvironmentVariable("PB_TOOL_Thread"))
  compilerParameters$ + " --thread"
EndIf

If Val(GetEnvironmentVariable("PB_TOOL_Unicode"))
  compilerParameters$ + " --unicode"
EndIf

If GetEnvironmentVariable("PB_TOOL_SubSystem")
  compilerParameters$ + " --subsystem " + GetEnvironmentVariable("PB_TOOL_SubSystem")
EndIf

Procedure$ ProcessParameter(parameter$, exeFilePath$, *isLibrary.Integer)
  Select LCase(parameter$)
    Case "-dl", "--dylib", "-so", "--sharedobject"
      parameter$ = parameter$ + " " + #DQUOTE$ + exeFilePath$ + #DQUOTE$
      *isLibrary\i = #True
    Case "/dll"
      parameter$ = "--executable " + #DQUOTE$ + exeFilePath$ + #DQUOTE$ + parameter$
      *isLibrary\i = #True
  EndSelect
  ProcedureReturn parameter$
EndProcedure

; Get user parameters
countOfParameters = CountProgramParameters()
For i = 2 To countOfParameters - 1
  compilerUserParameters$ + " " + ProcessParameter(ProgramParameter(i), exeFilePath$, @isLibrary)
Next
If Not isLibrary
  compilerParameters$ + " --executable " + #DQUOTE$ + exeFilePath$ + #DQUOTE$
EndIf
compilerParameters$ + compilerUserParameters$

; =======================
;-Delete Old Output Files
; =======================

; Make sure that there are no previous output files, to prevent old output files from being read, if an error occurs.
DeleteFile(asmCodeFilePath$)
DeleteFile(exeFilePath$)

; ====================
;-Create ASM Code File
; ====================

; Run the PB compiler to create the ASM code file
program = RunProgram(compilerFilePath$,
                     #DQUOTE$ + codeFilePath$ + #DQUOTE$ + " " + compilerParameters$,
                     workingDirectoryPath$,
                     #PB_Program_Open | #PB_Program_Read)

; Read the PB compiler output
If program
  While ProgramRunning(program)
    While AvailableProgramOutput(program)
      compilerOutput$ + ReadProgramString(program) + #CRLF$
    Wend
  Wend
  isCompilerError = Bool(ProgramExitCode(program))
  CloseProgram(program)
Else
  isCompilerError = #True
EndIf

; Read the ASM code file
file = ReadFile(#PB_Any, asmCodeFilePath$)
If file
  asmCode$ + ReadString(file, #PB_File_IgnoreEOL)
  CloseFile(file)
EndIf

; If an error has occurred, output detailed information
If isCompilerError Or asmCode$ = ""
  MessageRequester(#ErrorWindowTitle, "Tool could not create the asm output!" +
                                      #CRLF$ + #CRLF$ +
                                      "Note that the PB compiler only generates ASM output if the PB code is syntaxically correct!" +
                                      #CRLF$ + #CRLF$ +
                                      "-------------------------------------" +
                                      #CRLF$ + #CRLF$ +
                                      "Compiler File Path:"        + #CRLF$ + compilerFilePath$     + #CRLF$ + #CRLF$ +
                                      "Compiler Parameters:"       + #CRLF$ + compilerParameters$   + #CRLF$ + #CRLF$ +
                                      "Compiler Working Dir Path:" + #CRLF$ + workingDirectoryPath$ + #CRLF$ + #CRLF$ +
                                      "ASM Code File Path:"        + #CRLF$ + asmCodeFilePath$      +
                                      #CRLF$ + #CRLF$ +
                                      "-------------------------------------" +
                                      #CRLF$ + #CRLF$ +
                                      "Compiler Output:"           + #CRLF$ + compilerOutput$,
                   #PB_MessageRequester_Error)
  End
EndIf

; Remove the ASM file only if no error occurred to avoid removing error traces
DeleteFile(exeFilePath$)

output$ = "##############################################" + #CRLF$ +
          "Compiler File Path: "  + compilerFilePath$      + #CRLF$ +
          "Compiler Parameters: " + compilerParameters$    + #CRLF$ +
          "ASM Code File Path:"   + asmCodeFilePath$       + #CRLF$ +
          #CRLF$ +
          "##############################################" + #CRLF$ +
          compilerOutput$ + #CRLF$ +
          "##############################################" + #CRLF$ +
          #CRLF$ +
          asmCode$

; =============================
;-Create ASM Code Output Window
; =============================

Procedure UpdateWindow()
  ResizeGadget(#Editor_Output, #PB_Ignore, #PB_Ignore, WindowWidth(#Window_Main), WindowHeight(#Window_Main) - 40)
  ResizeGadget(#Button_OpenStandardEditor, 5, GadgetHeight(#Editor_Output) + 5, WindowWidth(#Window_Main) / 2 - 8, #PB_Ignore)
  ResizeGadget(#Button_CopyToClipboard, GadgetWidth(#Button_OpenStandardEditor) + 10, GadgetHeight(#Editor_Output) + 5,
               WindowWidth(#Window_Main) / 2 - 8, #PB_Ignore)
EndProcedure
 
; Display the ASM code in an EditorGadget
If Not OpenWindow(#Window_Main, #PB_Ignore, #PB_Ignore, 500, 500, #Program_Name, #PB_Window_SystemMenu | #PB_Window_SizeGadget |
                                                                                 #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
  MessageRequester(#ErrorWindowTitle, "The program window could not be created!", #PB_MessageRequester_Error)
  End
EndIf

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  If Not IsMenu(#Window_Main)
    CreateMenu(0, WindowID(#Window_Main))
  EndIf
  
  ;MenuItem(#PB_Menu_About, "")
  ;MenuItem(#PB_Menu_Preferences, "")
  MenuItem(#PB_Menu_Quit, "")
CompilerEndIf

EditorGadget(#Editor_Output, 0, 0, WindowWidth(#Window_Main), WindowHeight(#Window_Main) - 40)
ButtonGadget(#Button_OpenStandardEditor, 5, GadgetHeight(#Editor_Output) + 5, WindowWidth(#Window_Main) / 2 - 8, 30, "Open Standard Editor")
ButtonGadget(#Button_CopyToClipboard, GadgetWidth(#Button_OpenStandardEditor) + 10, GadgetHeight(#Editor_Output) + 5,
             WindowWidth(#Window_Main) / 2 - 8, 30, "Copy To Clipboard")
SetGadgetText(#Editor_Output, output$)

BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Window_Main)

Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_OpenStandardEditor
          file = CreateFile(#PB_Any, outputFilePathForStandardProgram$)
          If file
            WriteStringN(file, asmCode$)
            CloseFile(file)
          EndIf
          If Not OpenWithStandardProgram(outputFilePathForStandardProgram$)
            MessageRequester(#ErrorWindowTitle, "The output could not be opened in the standard editor!", #PB_MessageRequester_Error)
          EndIf
        Case #Button_CopyToClipboard
          SetClipboardText(asmCode$)
      EndSelect
    Case #PB_Event_Menu
      CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
        ; MacOS 'Application' menu
        Select EventMenu()
          Case #PB_Menu_About
          Case #PB_Menu_Preferences
          Case #PB_Menu_Quit
            Break
        EndSelect
      CompilerEndIf
  EndSelect
Until event = #PB_Event_CloseWindow
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul / OPC-Helper DLL
PB v3.30 / v5.7x - OS Mac Mini OSX 10.xx / Window 10 Pro. (X64) /Window 7 Pro. (X64) / Window XP Pro. (X86) / Ubuntu 14.04
Downloads auf My Webspace
Benutzeravatar
Sicro
Beiträge: 923
Registriert: 11.08.2005 19:08
Kontaktdaten:

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von Sicro »

@mk-soft
Danke für deine Anpassungen. :-)
Wie ich auf GitHub geschrieben habe, sollten wir alles in einem einzigen Tool vereinen, nachdem der PB_TOOL_Compiler-Bug behoben ist.

Wenn es so weit ist, melde ich mich nochmal bei dir.
Bild
Warum OpenSource eine Lizenz haben sollte :: DarkColor-Schema für PureBasic
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Jede Hilfe ist willkommen!
Manjaro Xfce x64 (Hauptsystem) :: Windows 7 x64 (VirtualBox) :: Neueste PureBasic-Version
Benutzeravatar
mk-soft
Beiträge: 3361
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: PB-IDE-Tool: Display ASM Code (Win,Lin,Mac)

Beitrag von mk-soft »

Update DisplayCcode 20.12.2021
- Bei Arm32/64 ist der Compiler Name immer "pbcompiler". Auch wenn es ein C-Backend ist

Läuft auch auf einem Paspberry PI ;)
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul / OPC-Helper DLL
PB v3.30 / v5.7x - OS Mac Mini OSX 10.xx / Window 10 Pro. (X64) /Window 7 Pro. (X64) / Window XP Pro. (X86) / Ubuntu 14.04
Downloads auf My Webspace
Antworten