mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-10 01:55:13 +00:00
nm output buffering
- file is loaded on first access and then kept in buffer
This commit is contained in:
parent
d31f668c0c
commit
764996499c
|
@ -12595,11 +12595,10 @@ IF os$ = "WIN" THEN
|
|||
IF NOT _FILEEXISTS(nm_output_file$) THEN
|
||||
SHELL _HIDE "cmd /c internal\c\c_compiler\bin\nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " --demangle -g >" + AddQuotes$(nm_output_file$)
|
||||
END IF
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x) + "("
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname+LEFTBRACKET
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12616,15 +12615,13 @@ IF os$ = "WIN" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
IF n > 1 THEN a$ = "Unable to resolve multiple instances of sub/function '" + ResolveStaticFunction_Name(x) + "' in '" + ResolveStaticFunction_File(x) + "'": GOTO errmes
|
||||
|
||||
IF n = 0 THEN 'attempt to locate simple function name without brackets
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x)
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12645,18 +12642,16 @@ IF os$ = "WIN" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
END IF
|
||||
|
||||
IF n = 0 THEN 'a C++ dynamic object library?
|
||||
IF NOT _FILEEXISTS(nm_output_file$) THEN
|
||||
SHELL _HIDE "cmd /c internal\c\c_compiler\bin\nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file$)
|
||||
END IF
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x) + "("
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname+LEFTBRACKET
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12673,16 +12668,14 @@ IF os$ = "WIN" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
IF n > 1 THEN a$ = "Unable to resolve multiple instances of sub/function '" + ResolveStaticFunction_Name(x) + "' in '" + ResolveStaticFunction_File(x) + "'": GOTO errmes
|
||||
END IF
|
||||
|
||||
IF n = 0 THEN 'a C dynamic object library?
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x)
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12703,7 +12696,6 @@ IF os$ = "WIN" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
IF n = 0 THEN a$ = "Could not find sub/function '" + ResolveStaticFunction_Name(x) + "' in '" + ResolveStaticFunction_File(x) + "'": GOTO errmes
|
||||
END IF
|
||||
|
||||
|
@ -12755,11 +12747,10 @@ IF os$ = "LNX" THEN
|
|||
END IF
|
||||
|
||||
IF MacOSX = 0 THEN 'C++ name demangling not supported in MacOSX
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x) + "("
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname+LEFTBRACKET
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12776,17 +12767,15 @@ IF os$ = "LNX" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
IF n > 1 THEN a$ = "Unable to resolve multiple instances of sub/function '" + ResolveStaticFunction_Name(x) + "' in '" + ResolveStaticFunction_File(x) + "'": GOTO errmes
|
||||
END IF 'macosx=0
|
||||
|
||||
IF n = 0 THEN 'attempt to locate simple function name without brackets
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x): s2$ = s$
|
||||
IF MacOSX THEN s$ = " _" + ResolveStaticFunction_Name(x) 'search for C mangled name
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12807,7 +12796,6 @@ IF os$ = "LNX" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
END IF
|
||||
|
||||
IF n = 0 THEN 'a C++ dynamic object library?
|
||||
|
@ -12815,11 +12803,10 @@ IF os$ = "LNX" THEN
|
|||
IF NOT _FILEEXISTS(nm_output_file$) THEN
|
||||
SHELL _HIDE "nm " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file$) + " 2>" + AddQuotes$(tmpdir$ + "nm_error.txt")
|
||||
END IF
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x) + "("
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname+LEFTBRACKET
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12836,16 +12823,14 @@ IF os$ = "LNX" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
IF n > 1 THEN a$ = "Unable to resolve multiple instances of sub/function '" + ResolveStaticFunction_Name(x) + "' in '" + ResolveStaticFunction_File(x) + "'": GOTO errmes
|
||||
END IF
|
||||
|
||||
IF n = 0 THEN 'a C dynamic object library?
|
||||
fh = FREEFILE
|
||||
s$ = " " + ResolveStaticFunction_Name(x)
|
||||
OPEN nm_output_file$ FOR BINARY AS #fh
|
||||
DO UNTIL EOF(fh)
|
||||
LINE INPUT #fh, a$
|
||||
fh = OpenBuffer%("I", nm_output_file$)
|
||||
DO UNTIL EndOfBuf%(fh)
|
||||
a$ = ReadBufLine$(fh)
|
||||
IF LEN(a$) THEN
|
||||
'search for SPACE+functionname
|
||||
x1 = INSTR(a$, s$)
|
||||
|
@ -12866,7 +12851,6 @@ IF os$ = "LNX" THEN
|
|||
END IF 'x1
|
||||
END IF '<>""
|
||||
LOOP
|
||||
CLOSE #fh
|
||||
macosx_libfind_failed:
|
||||
IF n = 0 THEN a$ = "Could not find sub/function '" + ResolveStaticFunction_Name(x) + "' in '" + ResolveStaticFunction_File(x) + "'": GOTO errmes
|
||||
END IF
|
||||
|
|
|
@ -25,8 +25,8 @@ SELECT CASE UCASE$(LEFT$(sbMode$, 1))
|
|||
CASE "B" 'binary
|
||||
IF buf% > UBOUND(SBufN) THEN GOSUB newBuf
|
||||
nul& = SeekBuf&(buf%, 0, SBM_BufStart)
|
||||
CASE "I" 'input
|
||||
IF buf% > UBOUND(SBufN) THEN ERROR 53 'buffer not found
|
||||
CASE "I" 'input (try to load from file, if yet unkown)
|
||||
IF buf% > UBOUND(SBufN) THEN GOSUB loadBuf
|
||||
nul& = SeekBuf&(buf%, 0, SBM_BufStart)
|
||||
CASE "O" 'output
|
||||
IF buf% <= UBOUND(SBufN) THEN DisposeBuf buf%: SBufN(buf%) = ""
|
||||
|
@ -42,6 +42,12 @@ buf% = CreateBuf%
|
|||
IF buf% > UBOUND(SBufN) THEN REDIM _PRESERVE SBufN(0 TO buf% + 99) AS STRING 'extend by 100 buffers
|
||||
SBufN(buf%) = sbName$
|
||||
RETURN
|
||||
'----------
|
||||
loadBuf:
|
||||
buf% = FileToBuf%(sbName$)
|
||||
IF buf% > UBOUND(SBufN) THEN REDIM _PRESERVE SBufN(0 TO buf% + 99) AS STRING 'extend by 100 buffers
|
||||
SBufN(buf%) = sbName$
|
||||
RETURN
|
||||
END FUNCTION
|
||||
|
||||
'--- This subroutine will clear the given buffer or ALL buffers, if the
|
||||
|
|
|
@ -39,6 +39,34 @@ simplebuffer_array$(buf& + 0) = ""
|
|||
simplebuffer_array$(buf& + 1) = ""
|
||||
END SUB
|
||||
|
||||
'---------------------------------------------------------------------
|
||||
FUNCTION FileToBuf% (fileSpec$)
|
||||
'--- option _explicit requirements ---
|
||||
DIM han%, buf&, ff%, fl&&, ext&
|
||||
'--- create a new buffer ---
|
||||
han% = CreateBuf%
|
||||
buf& = han% * 106
|
||||
'--- on success, open file ---
|
||||
IF han% >= 0 THEN
|
||||
ff% = FREEFILE
|
||||
OPEN fileSpec$ FOR BINARY LOCK WRITE AS ff%
|
||||
fl&& = LOF(ff%): ext& = fl&& MOD 16384
|
||||
'--- load file into buffer & adjust length ---
|
||||
simplebuffer_array$(buf& + 0) = SPACE$(fl&&)
|
||||
GET ff%, , simplebuffer_array$(buf& + 0)
|
||||
IF ext& > 0 THEN
|
||||
simplebuffer_array$(buf& + 0) = simplebuffer_array$(buf& + 0) + SPACE$(16384 - ext&)
|
||||
END IF
|
||||
'--- set cursor, buffer length & change state ---
|
||||
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(1)
|
||||
MID$(simplebuffer_array$(buf& + 1), 5, 4) = MKL$(fl&&)
|
||||
MID$(simplebuffer_array$(buf& + 1), 13, 4) = MKL$(0)
|
||||
CLOSE ff%
|
||||
END IF
|
||||
'--- return new handle ---
|
||||
FileToBuf% = han%
|
||||
END FUNCTION
|
||||
|
||||
'---------------------------------------------------------------------
|
||||
SUB BufToFile (handle%, fileSpec$)
|
||||
'--- option _explicit requirements ---
|
||||
|
@ -54,6 +82,22 @@ CLOSE ff%
|
|||
MID$(simplebuffer_array$(buf& + 1), 13, 4) = MKL$(0)
|
||||
END SUB
|
||||
|
||||
'---------------------------------------------------------------------
|
||||
FUNCTION ReadBufLine$ (handle%)
|
||||
'--- option _explicit requirements ---
|
||||
DIM buf&, cur&, cbl&&, brc$, brl%, eol&
|
||||
'--- prepare values ---
|
||||
buf& = handle% * 106
|
||||
cur& = GetBufPos&(handle%): cbl&& = GetBufLen&(handle%)
|
||||
brc$ = BufEolSeq$(handle%): brl% = LEN(brc$)
|
||||
'--- find next line break ---
|
||||
eol& = INSTR(cur&, simplebuffer_array$(buf& + 0), brc$)
|
||||
IF eol& = 0 OR eol& > cbl&& THEN eol& = cbl&& + 1: brl% = 0
|
||||
'--- read from buffer ---
|
||||
ReadBufLine$ = MID$(simplebuffer_array$(buf& + 0), cur&, eol& - cur&)
|
||||
MID$(simplebuffer_array$(buf& + 1), 1, 4) = MKL$(eol& + brl%)
|
||||
END FUNCTION
|
||||
|
||||
'---------------------------------------------------------------------
|
||||
SUB WriteBufLine (handle%, text$)
|
||||
'--- option _explicit requirements ---
|
||||
|
@ -157,6 +201,12 @@ buf& = handle% * 106
|
|||
GetBufLen& = CVL(MID$(simplebuffer_array$(buf& + 1), 5, 4))
|
||||
END FUNCTION
|
||||
|
||||
'---------------------------------------------------------------------
|
||||
FUNCTION EndOfBuf% (handle%)
|
||||
'--- return EndOfBuffer condition ---
|
||||
EndOfBuf% = (GetBufPos&(handle%) > GetBufLen&(handle%))
|
||||
END FUNCTION
|
||||
|
||||
'---------------------------------------------------------------------
|
||||
FUNCTION IsBufChanged% (handle%)
|
||||
'--- option _explicit requirements ---
|
||||
|
|
Loading…
Reference in a new issue