Module: Kumi::Support::IRRender
- Defined in:
- lib/kumi/support/ir_render.rb
Class Method Summary collapse
-
.to_json(ir_module, pretty: true) ⇒ Object
Stable JSON for goldens (simple canonical serialization).
-
.to_text(ir_module, analysis_state: nil) ⇒ Object
Human pretty text (using IRDump).
Class Method Details
.to_json(ir_module, pretty: true) ⇒ Object
Stable JSON for goldens (simple canonical serialization)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kumi/support/ir_render.rb', line 11 def to_json(ir_module, pretty: true) raise "nil IR" unless ir_module data = { inputs: ir_module.inputs, decls: ir_module.decls.map do |decl| { name: decl.name, kind: decl.kind, shape: decl.shape, ops: decl.ops.map do |op| { tag: op.tag, attrs: op.attrs, args: op.args } end } end } if pretty JSON.pretty_generate(data) else JSON.generate(data) end end |
.to_text(ir_module, analysis_state: nil) ⇒ Object
Human pretty text (using IRDump)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kumi/support/ir_render.rb', line 40 def to_text(ir_module, analysis_state: nil) raise "nil IR" unless ir_module if defined?(Kumi::Support::IRDump) # Convert AnalysisState to hash if needed analysis_state.to_h else # Fallback: simple text representation lines = [] lines << "IR Module (#{ir_module.decls.size} declarations):" ir_module.decls.each_with_index do |decl, i| lines << " [#{i}] #{decl.kind.upcase} #{decl.name} (#{decl.ops.size} ops)" decl.ops.each_with_index do |op, j| lines << " #{j}: #{op.tag.upcase} #{op.attrs.inspect} #{op.args.inspect}" end end lines.join("\n") end end |