Skip to content

Commit 106868a

Browse files
committed
Split write_logfile into separate function
1 parent 52878f3 commit 106868a

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

contrib/juliac/juliac-buildscript.jl

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,39 @@ function recursively_add_types!(types::Base.IdSet{DataType}, @nospecialize(T::Da
5050
return types
5151
end
5252

53+
function write_logfile(io::IO)
54+
iotmp = IOBuffer()
55+
types = Base.IdSet{DataType}()
56+
Base.visit(Core.GlobalMethods) do method
57+
if isdefined(method, :ccallable)
58+
rt, sig = method.ccallable
59+
name = length(method.ccallable) > 2 ? Symbol(method.ccallable[3]) : method.name
60+
print(IOContext(iotmp, :print_method_signature_only => true), method)
61+
methodstr = String(take!(iotmp))
62+
if name !== method.name
63+
methodstr = replace(methodstr, String(method.name) => String(name))
64+
end
65+
println(io, methodstr, "::", rt)
66+
for T in sig.parameters[2:end]
67+
recursively_add_types!(types, T)
68+
end
69+
end
70+
end
71+
println(io) # blank line separates methods from types
72+
for T in types
73+
println(io, T)
74+
dtfd = Base.DataTypeFieldDesc(T)
75+
local fd
76+
for i = 1:Base.datatype_nfields(T)
77+
fd = dtfd[i]
78+
fn = fieldname(T, i)
79+
ft = fieldtype(T, i)
80+
println(io, " ", fn, "::", ft, "[", fd.offset, "]")
81+
end
82+
println(io, fd.offset + fd.size, " bytes")
83+
end
84+
end
85+
5386
# Load user code
5487

5588
import Base.Experimental.entrypoint
@@ -100,37 +133,8 @@ let mod = Base.include(Main, ARGS[1])
100133
# Export info about entrypoints and structs needed to create header files
101134
if length(ARGS) >= 4
102135
logfile = ARGS[4]
103-
iotmp = IOBuffer()
104136
open(logfile, "w") do io
105-
types = Base.IdSet{DataType}()
106-
Base.visit(Core.GlobalMethods) do method
107-
if isdefined(method, :ccallable)
108-
rt, sig = method.ccallable
109-
name = length(method.ccallable) > 2 ? Symbol(method.ccallable[3]) : method.name
110-
print(IOContext(iotmp, :print_method_signature_only => true), method)
111-
methodstr = String(take!(iotmp))
112-
if name !== method.name
113-
methodstr = replace(methodstr, String(method.name) => String(name))
114-
end
115-
println(io, methodstr, "::", rt)
116-
for T in sig.parameters[2:end]
117-
recursively_add_types!(types, T)
118-
end
119-
end
120-
end
121-
println(io) # blank line separates methods from types
122-
for T in types
123-
println(io, T)
124-
dtfd = Base.DataTypeFieldDesc(T)
125-
local fd
126-
for i = 1:Base.datatype_nfields(T)
127-
fd = dtfd[i]
128-
fn = fieldname(T, i)
129-
ft = fieldtype(T, i)
130-
println(io, " ", fn, "::", ft, "[", fd.offset, "]")
131-
end
132-
println(io, fd.offset + fd.size, " bytes")
133-
end
137+
write_logfile(io)
134138
end
135139
end
136140
end

0 commit comments

Comments
 (0)