Module: Voodoo::GeneratorApi1

Included in:
CommonCodeGenerator
Defined in:
lib/voodoo/generators/generator_api1.rb

Overview

This module implements the old code generation API, consisting of the following methods:

#add_code #add_code_label #add_data #add_data_label #add_function #add_function_label #align_code #align_data #align_function

Instance Method Summary collapse

Instance Method Details

#add_code(*actions) ⇒ Object

Add code.

Parameters:

actions

an Array of actions to be added

Example:

add_code [:call, :exit, 0]


23
24
25
# File 'lib/voodoo/generators/generator_api1.rb', line 23

def add_code *actions
  add :code, *actions
end

#add_code_label(name) ⇒ Object

Add a label at the current address in the code section.

Example:

add_code_label :mylabel


31
32
33
# File 'lib/voodoo/generators/generator_api1.rb', line 31

def add_code_label name
  in_section(:code) { label name }
end

#add_data(*defs) ⇒ Object

Add data.

Parameters:

defs

an Array of data definitions

Example:

add_data [:word, 42]


42
43
44
# File 'lib/voodoo/generators/generator_api1.rb', line 42

def add_data *defs
  add :data, *defs
end

#add_data_label(name) ⇒ Object

Add a label at the current address in the data section.

Example:

add_data_label :msg


50
51
52
# File 'lib/voodoo/generators/generator_api1.rb', line 50

def add_data_label name
  add :data, [:label, name]
end

#add_function_label(name) ⇒ Object

Add a label at the address where the next function will be generated.

Example:

add_function_label :add_one


58
59
60
# File 'lib/voodoo/generators/generator_api1.rb', line 58

def add_function_label name
  add :functions, [:label, name]
end

#align_code(alignment = nil) ⇒ Object

Align code on the next alignment-byte boundary. If alignment is not specified, the default code alignment is used.



65
66
67
68
69
70
71
# File 'lib/voodoo/generators/generator_api1.rb', line 65

def align_code alignment = nil
  if alignment
    add :code, [:align, alignment]
  else
    add :code, [:align]
  end
end

#align_data(alignment = nil) ⇒ Object

Align data on the next alignment-byte boundary. If alignment is not specified, the default data alignment is used.



76
77
78
79
80
81
82
# File 'lib/voodoo/generators/generator_api1.rb', line 76

def align_data alignment = nil
  if alignment
    add :data, [:align, alignment]
  else
    add :data, [:align]
  end
end

#align_function(alignment = nil) ⇒ Object

Align function on the next alignment-byte boundary. If alignment is not specified, the default function alignment is used.



87
88
89
90
91
92
93
# File 'lib/voodoo/generators/generator_api1.rb', line 87

def align_function alignment = nil
  if alignment
    add :functions, [:align, alignment]
  else
    add :functions, [:align]
  end
end