Class: Kumi::Core::Analyzer::Passes::Codegen::Ruby::Emitter

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/core/analyzer/passes/codegen/ruby/emitter.rb

Overview

Emitter is responsible for turning the final LIR into a Ruby source code string.

Defined Under Namespace

Classes: BindsInfo, KernelInfo

Instance Method Summary collapse

Constructor Details

#initialize(kernels_data, binds_data) ⇒ Emitter

Returns a new instance of Emitter.



14
15
16
17
18
19
20
21
22
# File 'lib/kumi/core/analyzer/passes/codegen/ruby/emitter.rb', line 14

def initialize(kernels_data, binds_data)
  @all_kernels_inlined = true
  @kernels = kernels_data.map { |k| KernelInfo.new(**k.slice("id", "fn_id", "impl", "attrs").transform_keys(&:to_sym)) }
                         .to_h { |k| [k.fn_id, k] }

  @binds = binds_data.map { |b| BindsInfo.new(**b.slice("op_result_reg", "fn_id").transform_keys(&:to_sym)) }
                     .to_h { |b| [b.op_result_reg, b] }
  @buffer = OutputBuffer.new
end

Instance Method Details

#emit(declarations, schema_digest:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kumi/core/analyzer/passes/codegen/ruby/emitter.rb', line 24

def emit(declarations, schema_digest:)
  @buffer.reset!
  @buffer.emit_header(schema_digest)
  @buffer.emit_class_methods(declarations.keys)

  declarations.each do |name, payload|
    emit_declaration(name, Array(payload[:operations]))
  end

  emit_private_helpers
  @buffer.emit_footer
  @buffer.to_s
end