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

JuliaLang / julia / #37607

01 Sep 2023 04:29AM UTC coverage: 87.361% (+1.2%) from 86.167%
#37607

push

local

web-flow
Add a codegen option to disable use of jlplts (#51123)

Alternative to https://github.com/JuliaLang/julia/pull/51108 with the
same objectives.

74424 of 85191 relevant lines covered (87.36%)

12774219.48 hits per line

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

95.68
/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,563✔
24
    printstyled(io, x, bold=llstyle[s][1], color=llstyle[s][2])
1,563✔
25
    print(io, trailing_spaces)
1,042✔
26
end
27

28
# displaying type warnings
29

30
function warntype_type_printer(io::IO; @nospecialize(type), used::Bool, show_type::Bool=true, _...)
580✔
31
    (show_type && used) || return nothing
383✔
32
    str = "::$type"
197✔
33
    if !highlighting[:warntype]
197✔
34
        print(io, str)
4✔
35
    elseif type isa Union && is_expected_union(type)
193✔
36
        Base.emphasize(io, str, Base.warn_color()) # more mild user notification
6✔
37
    elseif type isa Type && (!Base.isdispatchelem(type) || type == Core.Box)
325✔
38
        Base.emphasize(io, str)
7✔
39
    else
40
        Base.printstyled(io, str, color=:cyan) # show the "good" type
180✔
41
    end
42
    return nothing
197✔
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)
14✔
48
    Base.unionlen(u) < 4 || return false
14✔
49
    for x in Base.uniontypes(u)
14✔
50
        if !Base.isdispatchelem(x) || x == Core.Box
57✔
51
            return false
3✔
52
        end
53
    end
38✔
54
    return true
11✔
55
end
56

57
"""
58
    code_warntype([io::IO], f, types; debuginfo=:default)
59

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

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

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

73
See [`@code_warntype`](@ref man-code-warntype) for more information.
74
"""
75
function code_warntype(io::IO, @nospecialize(f), @nospecialize(t=Base.default_tt(f));
54✔
76
                       debuginfo::Symbol=:default, optimize::Bool=false, kwargs...)
77
    debuginfo = Base.IRShow.debuginfo(debuginfo)
26✔
78
    lineprinter = Base.IRShow.__debuginfo[debuginfo]
26✔
79
    for (src, rettype) in code_typed(f, t; optimize, kwargs...)
26✔
80
        if !(src isa Core.CodeInfo)
26✔
81
            println(io, src)
×
82
            println(io, "  failed to infer")
×
83
            continue
×
84
        end
85
        lambda_io::IOContext = io
26✔
86
        p = src.parent
26✔
87
        nargs::Int = 0
26✔
88
        if p isa Core.MethodInstance
26✔
89
            println(io, p)
26✔
90
            print(io, "  from ")
26✔
91
            println(io, p.def)
26✔
92
            p.def isa Method && (nargs = p.def.nargs)
52✔
93
            if !isempty(p.sparam_vals)
26✔
94
                println(io, "Static Parameters")
4✔
95
                sig = p.def.sig
4✔
96
                warn_color = Base.warn_color() # more mild user notification
4✔
97
                for i = 1:length(p.sparam_vals)
8✔
98
                    sig = sig::UnionAll
8✔
99
                    name = sig.var.name
8✔
100
                    val = p.sparam_vals[i]
8✔
101
                    print_highlighted(io::IO, v::String, color::Symbol) =
17✔
102
                        if highlighting[:warntype]
103
                            Base.printstyled(io, v; color)
9✔
104
                        else
105
                            Base.print(io, v)
×
106
                        end
107
                    if val isa TypeVar
8✔
108
                        if val.lb === Union{}
3✔
109
                            print(io, "  ", name, " <: ")
1✔
110
                            print_highlighted(io, "$(val.ub)", warn_color)
1✔
111
                        elseif val.ub === Any
2✔
112
                            print(io, "  ", sig.var.name, " >: ")
1✔
113
                            print_highlighted(io, "$(val.lb)", warn_color)
1✔
114
                        else
115
                            print(io, "  ")
1✔
116
                            print_highlighted(io, "$(val.lb)", warn_color)
1✔
117
                            print(io, " <: ", sig.var.name, " <: ")
1✔
118
                            print_highlighted(io, "$(val.ub)", warn_color)
4✔
119
                        end
120
                    elseif val isa typeof(Vararg)
5✔
121
                        print(io, "  ", name, "::")
1✔
122
                        print_highlighted(io, "Int", warn_color)
1✔
123
                    else
124
                        print(io, "  ", sig.var.name, " = ")
4✔
125
                        print_highlighted(io, "$(val)", :cyan) # show the "good" type
4✔
126
                    end
127
                    println(io)
8✔
128
                    sig = sig.body
8✔
129
                end
12✔
130
            end
131
        end
132
        if src.slotnames !== nothing
26✔
133
            slotnames = Base.sourceinfo_slotnames(src)
26✔
134
            lambda_io = IOContext(lambda_io, :SOURCE_SLOTNAMES => slotnames)
26✔
135
            slottypes = src.slottypes
26✔
136
            nargs > 0 && println(io, "Arguments")
26✔
137
            for i = 1:length(slotnames)
52✔
138
                if i == nargs + 1
75✔
139
                    println(io, "Locals")
6✔
140
                end
141
                print(io, "  ", slotnames[i])
75✔
142
                if isa(slottypes, Vector{Any})
75✔
143
                    warntype_type_printer(io; type=slottypes[i], used=true)
75✔
144
                end
145
                println(io)
75✔
146
            end
124✔
147
        end
148
        print(io, "Body")
26✔
149
        warntype_type_printer(io; type=rettype, used=true)
26✔
150
        println(io)
26✔
151
        irshow_config = Base.IRShow.IRShowConfig(lineprinter(src), warntype_type_printer)
26✔
152
        Base.IRShow.show_ir(lambda_io, src, irshow_config)
26✔
153
        println(io)
26✔
154
    end
52✔
155
    nothing
26✔
156
end
157
code_warntype(args...; kwargs...) = (@nospecialize; code_warntype(stdout, args...; kwargs...))
×
158

159
using Base: CodegenParams
160

161
const GENERIC_SIG_WARNING = "; WARNING: This code may not match what actually runs.\n"
162
const OC_MISMATCH_WARNING =
163
"""
164
; WARNING: The pre-inferred opaque closure is not callable with the given arguments
165
;          and will error on dispatch with this signature.
166
"""
167

168
# Printing code representations in IR and assembly
169

170
function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrapper::Bool,
125✔
171
                        raw::Bool, dump_module::Bool, syntax::Symbol,
172
                        optimize::Bool, debuginfo::Symbol, binary::Bool,
173
                        params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), safepoint_on_entry=raw, gcstack_arg=raw))
174
    ccall(:jl_is_in_pure_context, Bool, ()) && error("code reflection cannot be used from generated functions")
125✔
175
    if isa(f, Core.Builtin)
120✔
176
        throw(ArgumentError("argument is not a generic function"))
2✔
177
    end
178
    warning = ""
118✔
179
    # get the MethodInstance for the method match
180
    if !isa(f, Core.OpaqueClosure)
118✔
181
        world = Base.get_world_counter()
114✔
182
        match = Base._which(signature_type(f, t); world)
114✔
183
        mi = Core.Compiler.specialize_method(match)
111✔
184
        # TODO: use jl_is_cacheable_sig instead of isdispatchtuple
185
        isdispatchtuple(mi.specTypes) || (warning = GENERIC_SIG_WARNING)
111✔
186
    else
187
        world = UInt64(f.world)
4✔
188
        tt = Base.to_tuple_type(t)
4✔
189
        if Core.Compiler.is_source_inferred(f.source.source)
4✔
190
            # OC was constructed from inferred source. There's only one
191
            # specialization and we can't infer anything more precise either.
192
            world = f.source.primary_world
4✔
193
            mi = f.source.specializations::Core.MethodInstance
4✔
194
            Core.Compiler.hasintersect(typeof(f).parameters[1], tt) || (warning = OC_MISMATCH_WARNING)
4✔
195
        else
196
            mi = Core.Compiler.specialize_method(f.source, Tuple{typeof(f.captures), tt.parameters...}, Core.svec())
×
197
            actual = isdispatchtuple(mi.specTypes)
×
198
            isdispatchtuple(mi.specTypes) || (warning = GENERIC_SIG_WARNING)
×
199
        end
200
    end
201
    # get the code for it
202
    if debuginfo === :default
115✔
203
        debuginfo = :source
74✔
204
    elseif debuginfo !== :source && debuginfo !== :none
41✔
205
        throw(ArgumentError("'debuginfo' must be either :source or :none"))
×
206
    end
207
    if native
115✔
208
        if syntax !== :att && syntax !== :intel
28✔
209
            throw(ArgumentError("'syntax' must be either :intel or :att"))
×
210
        end
211
        if dump_module
28✔
212
            # we want module metadata, so use LLVM to generate assembly output
213
            str = _dump_function_native_assembly(mi, world, wrapper, syntax, debuginfo, binary, raw, params)
25✔
214
        else
215
            # if we don't want the module metadata, just disassemble what our JIT has
216
            str = _dump_function_native_disassembly(mi, world, wrapper, syntax, debuginfo, binary)
31✔
217
        end
218
    else
219
        str = _dump_function_llvm(mi, world, wrapper, !raw, dump_module, optimize, debuginfo, params)
87✔
220
    end
221
    str = warning * str
115✔
222
    return str
115✔
223
end
224

225
function _dump_function_native_disassembly(mi::Core.MethodInstance, world::UInt,
3✔
226
                                           wrapper::Bool, syntax::Symbol,
227
                                           debuginfo::Symbol, binary::Bool)
228
    str = @ccall jl_dump_method_asm(mi::Any, world::UInt, false::Bool, wrapper::Bool,
3✔
229
                                    syntax::Ptr{UInt8}, debuginfo::Ptr{UInt8},
230
                                    binary::Bool)::Ref{String}
231
    return str
3✔
232
end
233

234
struct LLVMFDump
235
    tsm::Ptr{Cvoid} # opaque
236
    f::Ptr{Cvoid} # opaque
237
end
238

239
function _dump_function_native_assembly(mi::Core.MethodInstance, world::UInt,
25✔
240
                                        wrapper::Bool, syntax::Symbol, debuginfo::Symbol,
241
                                        binary::Bool, raw::Bool, params::CodegenParams)
242
    llvmf_dump = Ref{LLVMFDump}()
25✔
243
    @ccall jl_get_llvmf_defn(llvmf_dump::Ptr{LLVMFDump},mi::Any, world::UInt, wrapper::Bool,
25✔
244
                             true::Bool, params::CodegenParams)::Cvoid
245
    llvmf_dump[].f == C_NULL && error("could not compile the specified method")
25✔
246
    str = @ccall jl_dump_function_asm(llvmf_dump::Ptr{LLVMFDump}, false::Bool,
25✔
247
                                      syntax::Ptr{UInt8}, debuginfo::Ptr{UInt8},
248
                                      binary::Bool, raw::Bool)::Ref{String}
249
    return str
25✔
250
end
251

252
function _dump_function_llvm(
87✔
253
        mi::Core.MethodInstance, world::UInt, wrapper::Bool,
254
        strip_ir_metadata::Bool, dump_module::Bool,
255
        optimize::Bool, debuginfo::Symbol,
256
        params::CodegenParams)
257
    llvmf_dump = Ref{LLVMFDump}()
87✔
258
    @ccall jl_get_llvmf_defn(llvmf_dump::Ptr{LLVMFDump}, mi::Any, world::UInt,
87✔
259
                             wrapper::Bool, optimize::Bool, params::CodegenParams)::Cvoid
260
    llvmf_dump[].f == C_NULL && error("could not compile the specified method")
87✔
261
    str = @ccall jl_dump_function_ir(llvmf_dump::Ptr{LLVMFDump}, strip_ir_metadata::Bool,
87✔
262
                                     dump_module::Bool, debuginfo::Ptr{UInt8})::Ref{String}
263
    return str
87✔
264
end
265

266
"""
267
    code_llvm([io=stdout,], f, types; raw=false, dump_module=false, optimize=true, debuginfo=:default)
268

269
Prints the LLVM bitcodes generated for running the method matching the given generic
270
function and type signature to `io`.
271

272
If the `optimize` keyword is unset, the code will be shown before LLVM optimizations.
273
All metadata and dbg.* calls are removed from the printed bitcode. For the full IR, set the `raw` keyword to true.
274
To dump the entire module that encapsulates the function (with declarations), set the `dump_module` keyword to true.
275
Keyword argument `debuginfo` may be one of source (default) or none, to specify the verbosity of code comments.
276
"""
277
function code_llvm(io::IO, @nospecialize(f), @nospecialize(types=Base.default_tt(f));
108✔
278
                   raw::Bool=false, dump_module::Bool=false, optimize::Bool=true, debuginfo::Symbol=:default,
279
                   params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), safepoint_on_entry=raw, gcstack_arg=raw))
280
    d = _dump_function(f, types, false, false, raw, dump_module, :intel, optimize, debuginfo, false, params)
53✔
281
    if highlighting[:llvm] && get(io, :color, false)::Bool
49✔
282
        print_llvm(io, d)
1✔
283
    else
284
        print(io, d)
48✔
285
    end
286
end
287
code_llvm(args...; kwargs...) = (@nospecialize; code_llvm(stdout, args...; kwargs...))
12✔
288

289
"""
290
    code_native([io=stdout,], f, types; syntax=:intel, debuginfo=:default, binary=false, dump_module=true)
291

292
Prints the native assembly instructions generated for running the method matching the given
293
generic function and type signature to `io`.
294

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

301
See also: [`@code_native`](@ref), [`code_llvm`](@ref), [`code_typed`](@ref) and [`code_lowered`](@ref)
302
"""
303
function code_native(io::IO, @nospecialize(f), @nospecialize(types=Base.default_tt(f));
68✔
304
                     dump_module::Bool=true, syntax::Symbol=:intel, raw::Bool=false,
305
                     debuginfo::Symbol=:default, binary::Bool=false,
306
                     params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), safepoint_on_entry=raw, gcstack_arg=raw))
307
    d = _dump_function(f, types, true, false, raw, dump_module, syntax, true, debuginfo, binary, params)
33✔
308
    if highlighting[:native] && get(io, :color, false)::Bool
28✔
309
        print_native(io, d)
1✔
310
    else
311
        print(io, d)
27✔
312
    end
313
end
314
code_native(args...; kwargs...) = (@nospecialize; code_native(stdout, args...; kwargs...))
14✔
315

316
## colorized IR and assembly printing
317

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

320
function print_llvm(io::IO, code::String)
34✔
321
    buf = IOBuffer(code)
34✔
322
    for line in eachline(buf)
68✔
323
        m = match(r"^(\s*)((?:[^;]|;\")*)(.*)$", line)
43✔
324
        m === nothing && continue
43✔
325
        indent, tokens, comment = m.captures
43✔
326
        print(io, indent)
86✔
327
        print_llvm_tokens(io, tokens)
86✔
328
        printstyled_ll(io, comment, :comment)
86✔
329
        println(io)
43✔
330
    end
43✔
331
end
332

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

337
function print_llvm_tokens(io, tokens)
43✔
338
    m = match(r"^((?:[^\s:]+:)?)(\s*)(.*)", tokens)
43✔
339
    if m !== nothing
43✔
340
        label, spaces, tokens = m.captures
43✔
341
        printstyled_ll(io, label, :label, spaces)
86✔
342
    end
343
    m = match(r"^(%[^\s=]+)(\s*)=(\s*)(.*)", tokens)
43✔
344
    if m !== nothing
43✔
345
        result, spaces, spaces2, tokens = m.captures
21✔
346
        printstyled_ll(io, result, :variable, spaces)
42✔
347
        printstyled_ll(io, '=', :default, spaces2)
42✔
348
    end
349
    m = match(r"^([a-z]\w*)(\s*)(.*)", tokens)
43✔
350
    if m !== nothing
43✔
351
        inst, spaces, tokens = m.captures
34✔
352
        iskeyword = occursin(r"^(?:define|declare|type)$", inst) || occursin("=", tokens)
64✔
353
        printstyled_ll(io, inst, iskeyword ? :keyword : :instruction, spaces)
68✔
354
    end
355

356
    print_llvm_operands(io, tokens)
43✔
357
end
358

359
function print_llvm_operands(io, tokens)
67✔
360
    while !isempty(tokens)
240✔
361
        tokens = print_llvm_operand(io, tokens)
212✔
362
    end
106✔
363
    return tokens
67✔
364
end
365

366
function print_llvm_operand(io, tokens)
106✔
367
    islabel = false
106✔
368
    while !isempty(tokens)
640✔
369
        m = match(r"^,(\s*)(.*)", tokens)
269✔
370
        if m !== nothing
269✔
371
            spaces, tokens = m.captures
31✔
372
            printstyled_ll(io, ',', :default, spaces)
62✔
373
            break
31✔
374
        end
375
        m = match(r"^(\*+|=)(\s*)(.*)", tokens)
238✔
376
        if m !== nothing
238✔
377
            sym, spaces, tokens = m.captures
20✔
378
            printstyled_ll(io, sym, :default, spaces)
40✔
379
            continue
20✔
380
        end
381
        m = match(r"^(\"[^\"]*\")(\s*)(.*)", tokens)
218✔
382
        if m !== nothing
218✔
383
            str, spaces, tokens = m.captures
3✔
384
            printstyled_ll(io, str, :variable, spaces)
6✔
385
            continue
3✔
386
        end
387
        m = match(r"^([({\[<])(\s*)(.*)", tokens)
215✔
388
        if m !== nothing
215✔
389
            bracket, spaces, tokens = m.captures
24✔
390
            printstyled_ll(io, bracket, :bracket, spaces)
48✔
391
            tokens = print_llvm_operands(io, tokens) # enter
48✔
392
            continue
24✔
393
        end
394
        m = match(r"^([)}\]>])(\s*)(.*)", tokens)
191✔
395
        if m !== nothing
191✔
396
            bracket, spaces, tokens = m.captures
24✔
397
            printstyled_ll(io, bracket, :bracket, spaces)
48✔
398
            break # leave
24✔
399
        end
400

401
        m = match(r"^([^\s,*=(){}\[\]<>]+)(\s*)(.*)", tokens)
167✔
402
        m === nothing && break
167✔
403
        token, spaces, tokens = m.captures
167✔
404
        if occursin(llvm_types, token)
167✔
405
            printstyled_ll(io, token, :type)
55✔
406
            islabel = token == "label"
106✔
407
        elseif occursin(llvm_cond, token) # condition code is instruction-level
112✔
408
            printstyled_ll(io, token, :instruction)
1✔
409
        elseif occursin(num_regex, token)
111✔
410
            printstyled_ll(io, token, :number)
29✔
411
        elseif occursin(r"^@.+$", token)
82✔
412
            printstyled_ll(io, token, :funcname)
5✔
413
        elseif occursin(r"^%.+$", token)
77✔
414
            islabel |= occursin(r"^%[^\d].*$", token) & occursin(r"^\]", tokens)
38✔
415
            printstyled_ll(io, token, islabel ? :label : :variable)
38✔
416
            islabel = false
38✔
417
        elseif occursin(r"^[a-z]\w+$", token)
39✔
418
            printstyled_ll(io, token, :keyword)
34✔
419
        else
420
            printstyled_ll(io, token, :default)
5✔
421
        end
422
        print(io, spaces)
167✔
423
    end
214✔
424
    return tokens
106✔
425
end
426

427
function print_native(io::IO, code::String, arch::Symbol=sys_arch_category())
59✔
428
    archv = Val(arch)
59✔
429
    buf = IOBuffer(code)
58✔
430
    for line in eachline(buf)
116✔
431
        m = match(r"^(\s*)((?:[^;#/]|#\S|;\"|/[^/])*)(.*)$", line)
96✔
432
        m === nothing && continue
96✔
433
        indent, tokens, comment = m.captures
96✔
434
        print(io, indent)
192✔
435
        print_native_tokens(io, tokens, archv)
96✔
436
        printstyled_ll(io, comment, :comment)
192✔
437
        println(io)
96✔
438
    end
96✔
439
end
440

441
function sys_arch_category()
1✔
442
    if Sys.ARCH === :x86_64 || Sys.ARCH === :i686
1✔
443
        :x86
1✔
444
    elseif Sys.ARCH === :aarch64 || startswith(string(Sys.ARCH), "arm")
×
445
        :arm
×
446
    else
447
        :unsupported
×
448
    end
449
end
450

451
print_native_tokens(io, line, ::Val) = print(io, line)
1✔
452

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

458
function print_native_tokens(io, tokens, arch::Union{Val{:x86}, Val{:arm}})
95✔
459
    x86 = arch isa Val{:x86}
95✔
460
    m = match(r"^((?:[^\s:]+:|\"[^\"]+\":)?)(\s*)(.*)", tokens)
95✔
461
    if m !== nothing
95✔
462
        label, spaces, tokens = m.captures
95✔
463
        printstyled_ll(io, label, :label, spaces)
190✔
464
    end
465
    haslabel = false
95✔
466
    m = match(r"^([a-z][\w.]*)(\s*)(.*)", tokens)
95✔
467
    if m !== nothing
95✔
468
        instruction, spaces, tokens = m.captures
57✔
469
        printstyled_ll(io, instruction, :instruction, spaces)
114✔
470
        haslabel = occursin(r"^(?:bl?|bl?\.\w{2,5}|[ct]bn?z)?$", instruction)
57✔
471
    end
472

473
    isfuncname = false
95✔
474
    while !isempty(tokens)
896✔
475
        m = match(r"^([,:*])(\s*)(.*)", tokens)
353✔
476
        if m !== nothing
353✔
477
            sym, spaces, tokens = m.captures
86✔
478
            printstyled_ll(io, sym, :default, spaces)
172✔
479
            isfuncname = false
86✔
480
            continue
86✔
481
        end
482
        m = match(r"^([(){}\[\]])(\s*)(.*)", tokens)
267✔
483
        if m !== nothing
267✔
484
            bracket, spaces, tokens = m.captures
56✔
485
            printstyled_ll(io, bracket, :bracket, spaces)
112✔
486
            continue
56✔
487
        end
488
        m = match(r"^#([0-9a-fx.-]+)(\s*)(.*)", tokens)
211✔
489
        if !x86 && m !== nothing && occursin(num_regex, m.captures[1])
211✔
490
            num, spaces, tokens = m.captures
6✔
491
            printstyled_ll(io, "#" * num, :number, spaces)
12✔
492
            continue
6✔
493
        end
494

495
        m = match(r"^([^\s,:*(){}\[\]][^\s,:*/(){}\[\]]*)(\s*)(.*)", tokens)
205✔
496
        m === nothing && break
205✔
497
        token, spaces, tokens = m.captures
205✔
498
        if occursin(num_regex, token)
205✔
499
            printstyled_ll(io, token, :number)
20✔
500
        elseif x86 && occursin(x86_ptr, token) || occursin(avx512flags, token)
310✔
501
            printstyled_ll(io, token, :keyword)
22✔
502
            isfuncname = token == "offset"
22✔
503
        elseif !x86 && (occursin(arm_keywords, token) || occursin(arm_cond, token))
202✔
504
            printstyled_ll(io, token, :keyword)
7✔
505
        elseif occursin(r"^L.+$", token)
156✔
506
            printstyled_ll(io, token, :label)
5✔
507
        elseif occursin(r"^\$.+$", token)
151✔
508
            printstyled_ll(io, token, :funcname)
2✔
509
        elseif occursin(r"^%?(?:[a-z][\w.]+|\"[^\"]+\")$", token)
149✔
510
            islabel = haslabel & !occursin(',', tokens)
188✔
511
            printstyled_ll(io, token, islabel ? :label : isfuncname ? :funcname : :variable)
228✔
512
            isfuncname = false
114✔
513
        else
514
            printstyled_ll(io, token, :default)
35✔
515
        end
516
        print(io, spaces)
205✔
517
    end
448✔
518
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

© 2025 Coveralls, Inc