Skip to content

Commit e90786b

Browse files
committed
Nicer printing
- remove mangling in favor of native Julia printing - include argnames in methods - support and test name argument to ccallable
1 parent 1099753 commit e90786b

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

contrib/juliac/juliac-buildscript.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ function recursively_add_types!(types::Base.IdSet{DataType}, @nospecialize(T::Da
5151
end
5252
end
5353

54-
function mangle_name(@nospecialize(T::DataType))
55-
is_c_friendly(T) && return string(T)
56-
pname = isempty(T.parameters) ? String(nameof(T)) :
57-
join(pushfirst!(map(mangle_name, T.parameters), String(nameof(T)), "_"))
58-
return "_" * pname * "_"
59-
end
60-
6154
# Load user code
6255

6356
import Base.Experimental.entrypoint
@@ -108,29 +101,34 @@ let mod = Base.include(Main, ARGS[1])
108101
# Export info about entrypoints and structs needed to create header files
109102
if length(ARGS) >= 4
110103
logfile = ARGS[4]
104+
iotmp = IOBuffer()
111105
open(logfile, "w") do io
112106
types = Base.IdSet{DataType}()
113107
Base.visit(Core.GlobalMethods) do method
114108
if isdefined(method, :ccallable)
115109
rt, sig = method.ccallable
116110
name = length(method.ccallable) > 2 ? Symbol(method.ccallable[3]) : method.name
117-
Base.show_tuple_as_call(io, name, sig)
118-
println(io, "::", rt)
111+
print(IOContext(iotmp, :print_method_signature_only => true), method)
112+
methodstr = String(take!(iotmp))
113+
if name !== method.name
114+
methodstr = replace(methodstr, String(method.name) => String(name))
115+
end
116+
println(io, methodstr, "::", rt)
119117
for T in sig.parameters[2:end]
120118
recursively_add_types!(types, T)
121119
end
122120
end
123121
end
124-
println(io)
122+
println(io) # blank line separates methods from types
125123
for T in types
126-
println(io, mangle_name(T))
124+
println(io, T)
127125
dtfd = Base.DataTypeFieldDesc(T)
128126
local fd
129127
for i = 1:Base.datatype_nfields(T)
130128
fd = dtfd[i]
131129
fn = fieldname(T, i)
132130
ft = fieldtype(T, i)
133-
println(io, " ", fn, "::", mangle_name(ft), "[", fd.offset, "]")
131+
println(io, " ", fn, "::", ft, "[", fd.offset, "]")
134132
end
135133
println(io, fd.offset + fd.size, " bytes")
136134
end

test/trimming/simplelib.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ struct CVectorPair{T}
1111
to::CVector{T}
1212
end
1313

14-
Base.@ccallable function copyto_and_sum(fromto::CVectorPair{Float32})::Float32
14+
Base.@ccallable "copyto_and_sum" function badname(fromto::CVectorPair{Float32})::Float32
1515
from, to = unsafe_wrap(Array, fromto.from.data, fromto.from.length), unsafe_wrap(Array, fromto.to.data, fromto.to.length)
1616
copyto!(to, from)
1717
return sum(to)
1818
end
1919

20+
# FIXME? varargs
21+
# Base.@ccallable function printints(x::Cint...)::Nothing
22+
# for i in 1:length(x)
23+
# print(x[i], " ")
24+
# end
25+
# println()
26+
# end
27+
2028
end

test/trimming/trimming.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,27 @@ let exe_suffix = splitext(Base.julia_exename())[2]
1717
@test filesize(basic_jll_exe) < filesize(unsafe_string(Base.JLOptions().image_file))/10
1818

1919
str = read(joinpath(bindir, "bindinginfo_simplelib.log"), String)
20-
@test occursin("copyto_and_sum(::CVectorPair{Float32})::Float32", str)
20+
@test occursin("copyto_and_sum(fromto::CVectorPair{Float32})::Float32", str)
2121
@test occursin(
2222
"""
23-
_CVector_Float32_
23+
CVector{Float32}
2424
length::Int32[0]
2525
data::Ptr{Float32}[8]
2626
16 bytes""", str
2727
)
2828
@test occursin(
2929
"""
30-
_CVectorPair_Float32_
31-
from::_CVector_Float32_[0]
32-
to::_CVector_Float32_[16]
30+
CVectorPair{Float32}
31+
from::CVector{Float32}[0]
32+
to::CVector{Float32}[16]
3333
32 bytes""", str
3434
)
35+
# ensure that there is a blank line between methods and types
36+
lines = split(str, '\n'; keepempty=true)
37+
nblanks = 0
38+
for line in lines
39+
nblanks += isempty(line)
40+
occursin("length", line) && break
41+
end
42+
@test nblanks == 1
3543
end

0 commit comments

Comments
 (0)