• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37760

26 Apr 2024 05:25AM UTC coverage: 87.437% (+0.003%) from 87.434%
#37760

push

local

web-flow
define `clamp(x, ::Type{BigInt})` (#54228)

While `clamp(x, T)` is defined for all `T<:Integer`, it fails for
`T<:BigInt`.
The reason is, that `typemax(BigInt)` is not defined but called.
This PR will allow generic code with `clamp(x, Integer)` to behave
without error also if applied to `BigInt`.

1 of 1 new or added line in 1 file covered. (100.0%)

159 existing lines in 6 files now uncovered.

76392 of 87368 relevant lines covered (87.44%)

15847360.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.05
/stdlib/InteractiveUtils/src/codeview.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
# highlighting settings
4
const highlighting = Dict{Symbol, Bool}(
5
    :warntype => true,
6
    :llvm => true,
7
    :native => true,
8
)
9

10
const llstyle = Dict{Symbol, Tuple{Bool, Union{Symbol, Int}}}(
11
    :default     => (false, :normal), # e.g. comma, equal sign, unknown token
12
    :comment     => (false, :light_black),
13
    :label       => (false, :light_red),
14
    :instruction => ( true, :light_cyan),
15
    :type        => (false, :cyan),
16
    :number      => (false, :yellow),
17
    :bracket     => (false, :yellow),
18
    :variable    => (false, :normal), # e.g. variable, register
19
    :keyword     => (false, :light_magenta),
20
    :funcname    => (false, :light_yellow),
21
)
22

23
function printstyled_ll(io::IO, x, s::Symbol, trailing_spaces="")
1,038✔
24
    printstyled(io, x, bold=llstyle[s][1], color=llstyle[s][2])
2,597✔
25
    print(io, trailing_spaces)
1,038✔
26
end
27

28
# displaying type warnings
29

30
function warntype_type_printer(io::IO; @nospecialize(type), used::Bool, show_type::Bool=true, _...)
607✔
31
    (show_type && used) || return nothing
445✔
32
    str = "::$type"
261✔
33
    if !highlighting[:warntype]
261✔
34
        print(io, str)
6✔
35
    elseif type isa Union && is_expected_union(type)
255✔
36
        Base.emphasize(io, str, Base.warn_color()) # more mild user notification
14✔
37
    elseif type isa Type && (!Base.isdispatchelem(type) || type == Core.Box)
394✔
38
        Base.emphasize(io, str)
7✔
39
    else
40
        Base.printstyled(io, str, color=:cyan) # show the "good" type
234✔
41
    end
42
    return nothing
261✔
43
end
44

45
# True if one can be pretty certain that the compiler handles this union well,
46
# i.e. must be small with concrete types.
47
function is_expected_union(u::Union)
22✔
48
    Base.unionlen(u) < 4 || return false
22✔
49
    for x in Base.uniontypes(u)
22✔
50
        if !Base.isdispatchelem(x) || x == Core.Box
89✔
51
            return false
3✔
52
        end
53
    end
43✔
54
    return true
19✔
55
end
56

57
function print_warntype_codeinfo(io::IO, src::Core.CodeInfo, @nospecialize(rettype), nargs::Int; lineprinter)
52✔
58
    if src.slotnames !== nothing
26✔
59
        slotnames = Base.sourceinfo_slotnames(src)
26✔
60
        io = IOContext(io, :SOURCE_SLOTNAMES => slotnames)
26✔
61
        slottypes = src.slottypes
26✔
62
        nargs > 0 && println(io, "Arguments")
26✔
63
        for i = 1:length(slotnames)
26✔
64
            if i == nargs + 1
75✔
65
                println(io, "Locals")
6✔
66
            end
67
            print(io, "  ", slotnames[i])
75✔
68
            if isa(slottypes, Vector{Any})
75✔
69
                warntype_type_printer(io; type=slottypes[i], used=true)
75✔
70
            end
71
            println(io)
147✔
72
        end
124✔
73
    end
74
    print(io, "Body")
26✔
75
    warntype_type_printer(io; type=rettype, used=true)
26✔
76
    println(io)
50✔
77
    irshow_config = Base.IRShow.IRShowConfig(lineprinter(src), warntype_type_printer)
26✔
78
    Base.IRShow.show_ir(io, src, irshow_config)
26✔
79
    println(io)
26✔
80
end
81

82
function print_warntype_mi(io::IO, mi::Core.MethodInstance)
26✔
83
    println(io, mi)
26✔
84
    print(io, "  from ")
26✔
85
    println(io, mi.def)
26✔
86
    if !isempty(mi.sparam_vals)
26✔
87
        println(io, "Static Parameters")
4✔
88
        sig = mi.def.sig
4✔
89
        warn_color = Base.warn_color() # more mild user notification
4✔
90
        for i = 1:length(mi.sparam_vals)
4✔
91
            sig = sig::UnionAll
8✔
92
            name = sig.var.name
8✔
93
            val = mi.sparam_vals[i]
8✔
94
            print_highlighted(io::IO, v::String, color::Symbol) =
17✔
95
                if highlighting[:warntype]
96
                    Base.printstyled(io, v; color)
9✔
97
                else
98
                    Base.print(io, v)
×
99
                end
100
            if val isa TypeVar
8✔
101
                if val.lb === Union{}
3✔
102
                    print(io, "  ", name, " <: ")
1✔
103
                    print_highlighted(io, "$(val.ub)", warn_color)
1✔
104
                elseif val.ub === Any
2✔
105
                    print(io, "  ", sig.var.name, " >: ")
1✔
106
                    print_highlighted(io, "$(val.lb)", warn_color)
1✔
107
                else
108
                    print(io, "  ")
1✔
109
                    print_highlighted(io, "$(val.lb)", warn_color)
1✔
110
                    print(io, " <: ", sig.var.name, " <: ")
1✔
111
                    print_highlighted(io, "$(val.ub)", warn_color)
1✔
112
                end
113
            elseif val isa typeof(Vararg)
5✔
114
                print(io, "  ", name, "::")
1✔
115
                print_highlighted(io, "Int", warn_color)
1✔
116
            else
117
                print(io, "  ", sig.var.name, " = ")
4✔
118
                print_highlighted(io, "$(val)", :cyan) # show the "good" type
4✔
119
            end
120
            println(io)
8✔
121
            sig = sig.body
8✔
122
        end
8✔
123
    end
124
end
125

126
"""
127
    code_warntype([io::IO], f, types; debuginfo=:default)
128

129
Prints lowered and type-inferred ASTs for the methods matching the given generic function
130
and type signature to `io` which defaults to `stdout`. The ASTs are annotated in such a way
131
as to cause "non-leaf" types which may be problematic for performance to be emphasized
132
(if color is available, displayed in red). This serves as a warning of potential type instability.
133

134
Not all non-leaf types are particularly problematic for performance, and the performance
135
characteristics of a particular type is an implementation detail of the compiler.
136
`code_warntype` will err on the side of coloring types red if they might be a performance
137
concern, so some types may be colored red even if they do not impact performance.
138
Small unions of concrete types are usually not a concern, so these are highlighted in yellow.
139

140
Keyword argument `debuginfo` may be one of `:source` or `:none` (default), to specify the verbosity of code comments.
141

142
See the [`@code_warntype`](@ref man-code-warntype) section in the Performance Tips page of the manual for more information.
143

144
See also: [`@code_warntype`](@ref), [`code_typed`](@ref), [`code_lowered`](@ref), [`code_llvm`](@ref), [`code_native`](@ref).
145
"""
146
function code_warntype(io::IO, @nospecialize(f), @nospecialize(tt=Base.default_tt(f));
54✔
147
                       world=Base.get_world_counter(),
148
                       interp::Core.Compiler.AbstractInterpreter=Core.Compiler.NativeInterpreter(world),
149
                       debuginfo::Symbol=:default, optimize::Bool=false, kwargs...)
150
    (ccall(:jl_is_in_pure_context, Bool, ()) || world == typemax(UInt)) &&
26✔
151
        error("code reflection cannot be used from generated functions")
152
    debuginfo = Base.IRShow.debuginfo(debuginfo)
26✔
153
    lineprinter = Base.IRShow.__debuginfo[debuginfo]
26✔
154
    nargs::Int = 0
26✔
155
    if isa(f, Core.OpaqueClosure)
26✔
156
        isa(f.source, Method) && (nargs = f.nargs)
×
157
        print_warntype_codeinfo(io, Base.code_typed_opaque_closure(f, tt)[1]..., nargs; lineprinter)
×
158
        return nothing
×
159
    end
160
    tt = Base.signature_type(f, tt)
26✔
161
    matches = Core.Compiler.findall(tt, Core.Compiler.method_table(interp))
26✔
162
    matches === nothing && Base.raise_match_failure(:code_warntype, tt)
26✔
163
    for match in matches.matches
26✔
164
        match = match::Core.MethodMatch
26✔
165
        (src, rettype) = Core.Compiler.typeinf_code(interp, match, optimize)
26✔
166
        mi = Core.Compiler.specialize_method(match)
26✔
167
        mi.def isa Method && (nargs = (mi.def::Method).nargs)
26✔
168
        print_warntype_mi(io, mi)
26✔
169
        print_warntype_codeinfo(io, src, rettype, nargs; lineprinter)
26✔
170
    end
26✔
171
    nothing
26✔
172
end
UNCOV
173
code_warntype(args...; kwargs...) = (@nospecialize; code_warntype(stdout, args...; kwargs...))
×
174

175
using Base: CodegenParams
176

177
const GENERIC_SIG_WARNING = "; WARNING: This code may not match what actually runs.\n"
178
const OC_MISMATCH_WARNING =
179
"""
180
; WARNING: The pre-inferred opaque closure is not callable with the given arguments
181
;          and will error on dispatch with this signature.
182
"""
183

184
# Printing code representations in IR and assembly
185

186
function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrapper::Bool,
131✔
187
                        raw::Bool, dump_module::Bool, syntax::Symbol,
188
                        optimize::Bool, debuginfo::Symbol, binary::Bool,
189
                        params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), debug_info_level=Cint(2), safepoint_on_entry=raw, gcstack_arg=raw))
190
    ccall(:jl_is_in_pure_context, Bool, ()) && error("code reflection cannot be used from generated functions")
131✔
191
    if isa(f, Core.Builtin)
126✔
192
        throw(ArgumentError("argument is not a generic function"))
2✔
193
    end
194
    warning = ""
124✔
195
    # get the MethodInstance for the method match
196
    if !isa(f, Core.OpaqueClosure)
124✔
197
        world = Base.get_world_counter()
120✔
198
        match = Base._which(signature_type(f, t); world)
120✔
199
        mi = Core.Compiler.specialize_method(match)
117✔
200
        # TODO: use jl_is_cacheable_sig instead of isdispatchtuple
201
        isdispatchtuple(mi.specTypes) || (warning = GENERIC_SIG_WARNING)
117✔
202
    else
203
        world = UInt64(f.world)
4✔
204
        tt = Base.to_tuple_type(t)
4✔
205
        if !isdefined(f.source, :source)
4✔
206
            # OC was constructed from inferred source. There's only one
207
            # specialization and we can't infer anything more precise either.
208
            world = f.source.primary_world
4✔
209
            mi = f.source.specializations::Core.MethodInstance
4✔
210
            Core.Compiler.hasintersect(typeof(f).parameters[1], tt) || (warning = OC_MISMATCH_WARNING)
4✔
211
        else
212
            mi = Core.Compiler.specialize_method(f.source, Tuple{typeof(f.captures), tt.parameters...}, Core.svec())
×
UNCOV
213
            actual = isdispatchtuple(mi.specTypes)
×
UNCOV
214
            isdispatchtuple(mi.specTypes) || (warning = GENERIC_SIG_WARNING)
×
215
        end
216
    end
217
    # get the code for it
218
    if debuginfo === :default
121✔
219
        debuginfo = :source
76✔
220
    elseif debuginfo !== :source && debuginfo !== :none
45✔
UNCOV
221
        throw(ArgumentError("'debuginfo' must be either :source or :none"))
×
222
    end
223
    if native
121✔
224
        if syntax !== :att && syntax !== :intel
29✔
UNCOV
225
            throw(ArgumentError("'syntax' must be either :intel or :att"))
×
226
        end
227
        if dump_module
29✔
228
            # we want module metadata, so use LLVM to generate assembly output
229
            str = _dump_function_native_assembly(mi, world, wrapper, syntax, debuginfo, binary, raw, params)
25✔
230
        else
231
            # if we don't want the module metadata, just disassemble what our JIT has
232
            str = _dump_function_native_disassembly(mi, world, wrapper, syntax, debuginfo, binary)
4✔
233
        end
234
    else
235
        str = _dump_function_llvm(mi, world, wrapper, !raw, dump_module, optimize, debuginfo, params)
92✔
236
    end
237
    str = warning * str
121✔
238
    return str
121✔
239
end
240

241
function _dump_function_native_disassembly(mi::Core.MethodInstance, world::UInt,
242
                                           wrapper::Bool, syntax::Symbol,
243
                                           debuginfo::Symbol, binary::Bool)
244
    str = @ccall jl_dump_method_asm(mi::Any, world::UInt, false::Bool, wrapper::Bool,
4✔
245
                                    syntax::Ptr{UInt8}, debuginfo::Ptr{UInt8},
246
                                    binary::Bool)::Ref{String}
247
    return str
4✔
248
end
249

250
struct LLVMFDump
251
    tsm::Ptr{Cvoid} # opaque
252
    f::Ptr{Cvoid} # opaque
253
end
254

255
function _dump_function_native_assembly(mi::Core.MethodInstance, world::UInt,
25✔
256
                                        wrapper::Bool, syntax::Symbol, debuginfo::Symbol,
257
                                        binary::Bool, raw::Bool, params::CodegenParams)
258
    llvmf_dump = Ref{LLVMFDump}()
25✔
259
    @ccall jl_get_llvmf_defn(llvmf_dump::Ptr{LLVMFDump},mi::Any, world::UInt, wrapper::Bool,
25✔
260
                             true::Bool, params::CodegenParams)::Cvoid
261
    llvmf_dump[].f == C_NULL && error("could not compile the specified method")
25✔
262
    str = @ccall jl_dump_function_asm(llvmf_dump::Ptr{LLVMFDump}, false::Bool,
25✔
263
                                      syntax::Ptr{UInt8}, debuginfo::Ptr{UInt8},
264
                                      binary::Bool, raw::Bool)::Ref{String}
265
    return str
25✔
266
end
267

268
function _dump_function_llvm(
92✔
269
        mi::Core.MethodInstance, world::UInt, wrapper::Bool,
270
        strip_ir_metadata::Bool, dump_module::Bool,
271
        optimize::Bool, debuginfo::Symbol,
272
        params::CodegenParams)
273
    llvmf_dump = Ref{LLVMFDump}()
92✔
274
    @ccall jl_get_llvmf_defn(llvmf_dump::Ptr{LLVMFDump}, mi::Any, world::UInt,
92✔
275
                             wrapper::Bool, optimize::Bool, params::CodegenParams)::Cvoid
276
    llvmf_dump[].f == C_NULL && error("could not compile the specified method")
92✔
277
    str = @ccall jl_dump_function_ir(llvmf_dump::Ptr{LLVMFDump}, strip_ir_metadata::Bool,
92✔
278
                                     dump_module::Bool, debuginfo::Ptr{UInt8})::Ref{String}
279
    return str
92✔
280
end
281

282
"""
283
    code_llvm([io=stdout,], f, types; raw=false, dump_module=false, optimize=true, debuginfo=:default)
284

285
Prints the LLVM bitcodes generated for running the method matching the given generic
286
function and type signature to `io`.
287

288
If the `optimize` keyword is unset, the code will be shown before LLVM optimizations.
289
All metadata and dbg.* calls are removed from the printed bitcode. For the full IR, set the `raw` keyword to true.
290
To dump the entire module that encapsulates the function (with declarations), set the `dump_module` keyword to true.
291
Keyword argument `debuginfo` may be one of source (default) or none, to specify the verbosity of code comments.
292

293
See also: [`@code_llvm`](@ref), [`code_warntype`](@ref), [`code_typed`](@ref), [`code_lowered`](@ref), [`code_native`](@ref).
294
"""
295
function code_llvm(io::IO, @nospecialize(f), @nospecialize(types=Base.default_tt(f));
58✔
296
                   raw::Bool=false, dump_module::Bool=false, optimize::Bool=true, debuginfo::Symbol=:default,
297
                   params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), debug_info_level=Cint(2), safepoint_on_entry=raw, gcstack_arg=raw))
298
    d = _dump_function(f, types, false, false, raw, dump_module, :intel, optimize, debuginfo, false, params)
54✔
299
    if highlighting[:llvm] && get(io, :color, false)::Bool
50✔
300
        print_llvm(io, d)
1✔
301
    else
302
        print(io, d)
49✔
303
    end
304
end
305
code_llvm(args...; kwargs...) = (@nospecialize; code_llvm(stdout, args...; kwargs...))
12✔
306

307
"""
308
    code_native([io=stdout,], f, types; syntax=:intel, debuginfo=:default, binary=false, dump_module=true)
309

310
Prints the native assembly instructions generated for running the method matching the given
311
generic function and type signature to `io`.
312

313
* Set assembly syntax by setting `syntax` to `:intel` (default) for intel syntax or `:att` for AT&T syntax.
314
* Specify verbosity of code comments by setting `debuginfo` to `:source` (default) or `:none`.
315
* If `binary` is `true`, also print the binary machine code for each instruction precedented by an abbreviated address.
316
* If `dump_module` is `false`, do not print metadata such as rodata or directives.
317
* If `raw` is `false`, uninteresting instructions (like the safepoint function prologue) are elided.
318

319
See also: [`@code_native`](@ref), [`code_warntype`](@ref), [`code_typed`](@ref), [`code_lowered`](@ref), [`code_llvm`](@ref).
320
"""
321
function code_native(io::IO, @nospecialize(f), @nospecialize(types=Base.default_tt(f));
38✔
322
                     dump_module::Bool=true, syntax::Symbol=:intel, raw::Bool=false,
323
                     debuginfo::Symbol=:default, binary::Bool=false,
324
                     params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), debug_info_level=Cint(2), safepoint_on_entry=raw, gcstack_arg=raw))
325
    d = _dump_function(f, types, true, false, raw, dump_module, syntax, true, debuginfo, binary, params)
34✔
326
    if highlighting[:native] && get(io, :color, false)::Bool
29✔
327
        print_native(io, d)
1✔
328
    else
329
        print(io, d)
28✔
330
    end
331
end
332
code_native(args...; kwargs...) = (@nospecialize; code_native(stdout, args...; kwargs...))
14✔
333

334
## colorized IR and assembly printing
335

336
const num_regex = r"^(?:\$?-?\d+|0x[0-9A-Fa-f]+|-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)$"
337

338
function print_llvm(io::IO, code::String)
34✔
339
    buf = IOBuffer(code)
68✔
340
    for line in eachline(buf)
68✔
341
        m = match(r"^(\s*)((?:[^;]|;\")*)(.*)$", line)
43✔
342
        m === nothing && continue
43✔
343
        indent, tokens, comment = m.captures
43✔
344
        print(io, indent)
86✔
345
        print_llvm_tokens(io, tokens)
86✔
346
        printstyled_ll(io, comment, :comment)
86✔
347
        println(io)
43✔
348
    end
43✔
349
end
350

351
const llvm_types =
352
    r"^(?:void|half|float|double|x86_\w+|ppc_\w+|label|metadata|type|opaque|token|i\d+)$"
353
const llvm_cond = r"^(?:[ou]?eq|[ou]?ne|[uso][gl][te]|ord|uno)$" # true|false
354

355
function print_llvm_tokens(io, tokens)
43✔
356
    m = match(r"^((?:[^\s:]+:)?)(\s*)(.*)", tokens)
43✔
357
    if m !== nothing
43✔
358
        label, spaces, tokens = m.captures
43✔
359
        printstyled_ll(io, label, :label, spaces)
86✔
360
    end
361
    m = match(r"^(%[^\s=]+)(\s*)=(\s*)(.*)", tokens)
43✔
362
    if m !== nothing
43✔
363
        result, spaces, spaces2, tokens = m.captures
21✔
364
        printstyled_ll(io, result, :variable, spaces)
42✔
365
        printstyled_ll(io, '=', :default, spaces2)
42✔
366
    end
367
    m = match(r"^([a-z]\w*)(\s*)(.*)", tokens)
43✔
368
    if m !== nothing
43✔
369
        inst, spaces, tokens = m.captures
34✔
370
        iskeyword = occursin(r"^(?:define|declare|type)$", inst) || occursin("=", tokens)
64✔
371
        printstyled_ll(io, inst, iskeyword ? :keyword : :instruction, spaces)
68✔
372
    end
373

374
    print_llvm_operands(io, tokens)
43✔
375
end
376

UNCOV
377
function print_llvm_operands(io, tokens)
×
378
    while !isempty(tokens)
240✔
379
        tokens = print_llvm_operand(io, tokens)
106✔
380
    end
106✔
381
    return tokens
67✔
382
end
383

384
function print_llvm_operand(io, tokens)
106✔
385
    islabel = false
106✔
386
    while !isempty(tokens)
632✔
387
        m = match(r"^,(\s*)(.*)", tokens)
265✔
388
        if m !== nothing
265✔
389
            spaces, tokens = m.captures
31✔
390
            printstyled_ll(io, ',', :default, spaces)
62✔
391
            break
31✔
392
        end
393
        m = match(r"^(\*+|=)(\s*)(.*)", tokens)
234✔
394
        if m !== nothing
234✔
395
            sym, spaces, tokens = m.captures
16✔
396
            printstyled_ll(io, sym, :default, spaces)
32✔
397
            continue
16✔
398
        end
399
        m = match(r"^(\"[^\"]*\")(\s*)(.*)", tokens)
218✔
400
        if m !== nothing
218✔
401
            str, spaces, tokens = m.captures
3✔
402
            printstyled_ll(io, str, :variable, spaces)
6✔
403
            continue
3✔
404
        end
405
        m = match(r"^([({\[<])(\s*)(.*)", tokens)
215✔
406
        if m !== nothing
215✔
407
            bracket, spaces, tokens = m.captures
24✔
408
            printstyled_ll(io, bracket, :bracket, spaces)
48✔
409
            tokens = print_llvm_operands(io, tokens) # enter
48✔
410
            continue
24✔
411
        end
412
        m = match(r"^([)}\]>])(\s*)(.*)", tokens)
191✔
413
        if m !== nothing
191✔
414
            bracket, spaces, tokens = m.captures
24✔
415
            printstyled_ll(io, bracket, :bracket, spaces)
48✔
416
            break # leave
24✔
417
        end
418

419
        m = match(r"^([^\s,*=(){}\[\]<>]+)(\s*)(.*)", tokens)
167✔
420
        m === nothing && break
167✔
421
        token, spaces, tokens = m.captures
167✔
422
        if occursin(llvm_types, token)
167✔
423
            printstyled_ll(io, token, :type)
51✔
424
            islabel = token == "label"
51✔
425
        elseif occursin(llvm_cond, token) # condition code is instruction-level
116✔
426
            printstyled_ll(io, token, :instruction)
1✔
427
        elseif occursin(num_regex, token)
115✔
428
            printstyled_ll(io, token, :number)
29✔
429
        elseif occursin(r"^@.+$", token)
86✔
430
            printstyled_ll(io, token, :funcname)
5✔
431
        elseif occursin(r"^%.+$", token)
81✔
432
            islabel |= occursin(r"^%[^\d].*$", token) & occursin(r"^\]", tokens)
38✔
433
            printstyled_ll(io, token, islabel ? :label : :variable)
38✔
434
            islabel = false
38✔
435
        elseif occursin(r"^[a-z]\w+$", token)
43✔
436
            printstyled_ll(io, token, :keyword)
38✔
437
        else
438
            printstyled_ll(io, token, :default)
5✔
439
        end
440
        print(io, spaces)
167✔
441
    end
210✔
442
    return tokens
106✔
443
end
444

445
function print_native(io::IO, code::String, arch::Symbol=sys_arch_category())
58✔
446
    archv = Val(arch)
59✔
447
    buf = IOBuffer(code)
116✔
448
    for line in eachline(buf)
116✔
449
        m = match(r"^(\s*)((?:[^;#/]|#\S|;\"|/[^/])*)(.*)$", line)
94✔
450
        m === nothing && continue
94✔
451
        indent, tokens, comment = m.captures
94✔
452
        print(io, indent)
188✔
453
        print_native_tokens(io, tokens, archv)
94✔
454
        printstyled_ll(io, comment, :comment)
188✔
455
        println(io)
94✔
456
    end
94✔
457
end
458

459
function sys_arch_category()
460
    if Sys.ARCH === :x86_64 || Sys.ARCH === :i686
1✔
461
        :x86
UNCOV
462
    elseif Sys.ARCH === :aarch64 || startswith(string(Sys.ARCH), "arm")
×
463
        :arm
464
    else
465
        :unsupported
466
    end
467
end
468

469
print_native_tokens(io, line, ::Val) = print(io, line)
1✔
470

471
const x86_ptr = r"^(?:(?:[xyz]mm|[dq])?word|byte|ptr|offset)$"
472
const avx512flags = r"^(?:z|r[nduz]-sae|sae|1to1?\d)$"
473
const arm_cond = r"^(?:eq|ne|cs|ho|cc|lo|mi|pl|vs|vc|hi|ls|[lg][te]|al|nv)$"
474
const arm_keywords = r"^(?:lsl|lsr|asr|ror|rrx|!|/[zm])$"
475

476
function print_native_tokens(io, tokens, arch::Union{Val{:x86}, Val{:arm}})
93✔
477
    x86 = arch isa Val{:x86}
93✔
478
    m = match(r"^((?:[^\s:]+:|\"[^\"]+\":)?)(\s*)(.*)", tokens)
93✔
479
    if m !== nothing
93✔
480
        label, spaces, tokens = m.captures
93✔
481
        printstyled_ll(io, label, :label, spaces)
186✔
482
    end
483
    haslabel = false
93✔
484
    m = match(r"^([a-z][\w.]*)(\s*)(.*)", tokens)
93✔
485
    if m !== nothing
93✔
486
        instruction, spaces, tokens = m.captures
57✔
487
        printstyled_ll(io, instruction, :instruction, spaces)
114✔
488
        haslabel = occursin(r"^(?:bl?|bl?\.\w{2,5}|[ct]bn?z)?$", instruction)
57✔
489
    end
490

491
    isfuncname = false
93✔
492
    while !isempty(tokens)
900✔
493
        m = match(r"^([,:*])(\s*)(.*)", tokens)
357✔
494
        if m !== nothing
357✔
495
            sym, spaces, tokens = m.captures
88✔
496
            printstyled_ll(io, sym, :default, spaces)
176✔
497
            isfuncname = false
88✔
498
            continue
88✔
499
        end
500
        m = match(r"^([(){}\[\]])(\s*)(.*)", tokens)
269✔
501
        if m !== nothing
269✔
502
            bracket, spaces, tokens = m.captures
56✔
503
            printstyled_ll(io, bracket, :bracket, spaces)
112✔
504
            continue
56✔
505
        end
506
        m = match(r"^#([0-9a-fx.-]+)(\s*)(.*)", tokens)
213✔
507
        if !x86 && m !== nothing && occursin(num_regex, m.captures[1])
213✔
508
            num, spaces, tokens = m.captures
6✔
509
            printstyled_ll(io, "#" * num, :number, spaces)
12✔
510
            continue
6✔
511
        end
512

513
        m = match(r"^([^\s,:*(){}\[\]][^\s,:*/(){}\[\]]*)(\s*)(.*)", tokens)
207✔
514
        m === nothing && break
207✔
515
        token, spaces, tokens = m.captures
207✔
516
        if occursin(num_regex, token)
207✔
517
            printstyled_ll(io, token, :number)
22✔
518
        elseif x86 && occursin(x86_ptr, token) || occursin(avx512flags, token)
310✔
519
            printstyled_ll(io, token, :keyword)
22✔
520
            isfuncname = token == "offset"
22✔
521
        elseif !x86 && (occursin(arm_keywords, token) || occursin(arm_cond, token))
202✔
522
            printstyled_ll(io, token, :keyword)
7✔
523
        elseif occursin(r"^L.+$", token)
156✔
524
            printstyled_ll(io, token, :label)
5✔
525
        elseif occursin(r"^\$.+$", token)
151✔
526
            printstyled_ll(io, token, :funcname)
2✔
527
        elseif occursin(r"^%?(?:[a-z][\w.]+|\"[^\"]+\")$", token)
149✔
528
            islabel = haslabel & !occursin(',', tokens)
188✔
529
            printstyled_ll(io, token, islabel ? :label : isfuncname ? :funcname : :variable)
228✔
530
            isfuncname = false
114✔
531
        else
532
            printstyled_ll(io, token, :default)
35✔
533
        end
534
        print(io, spaces)
207✔
535
    end
357✔
536
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc