voodoo 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,3 @@
1
- require 'voodoo/generators/generator_api1'
2
-
3
1
  module Voodoo
4
2
  # Common base class for code generators.
5
3
  #
@@ -8,10 +6,11 @@ module Voodoo
8
6
  # - #new
9
7
  # - #add
10
8
  # - #add_function
9
+ # - #features
11
10
  # - #gensym
11
+ # - #has_feature?
12
12
  # - #output_file_name
13
13
  # - #output_file_suffix
14
- # - #wordsize
15
14
  # - #write
16
15
  #
17
16
  # This class contains base implementations of some of these methods,
@@ -21,9 +20,6 @@ module Voodoo
21
20
  # is provided on the main page of the documentation of the Voodoo module.
22
21
  #
23
22
  class CommonCodeGenerator
24
- # Provide compatibility with old API
25
- include GeneratorApi1
26
-
27
23
  # Initializes the code generator.
28
24
  # _params_ shall be a hash containing parameters to the code generator,
29
25
  # and shall at least contain the keys <tt>:architecture</tt> and
@@ -43,6 +39,9 @@ module Voodoo
43
39
  @top_level = Environment.initial_environment
44
40
  @environment = @top_level
45
41
  @output_file_suffix = '.o'
42
+ @features = {
43
+ :voodoo => "1.0" # Voodoo language version
44
+ }
46
45
  end
47
46
 
48
47
  # Adds code to the given section.
@@ -158,6 +157,14 @@ module Voodoo
158
157
  end
159
158
  end
160
159
 
160
+ # Returns a hash describing the features supported by this code generator.
161
+ # The keys in this hash are the names of the supported features.
162
+ # The associated values are strings providing additional information about
163
+ # the feature, such as a version number.
164
+ def features
165
+ @features
166
+ end
167
+
161
168
  # Add a function to the current section
162
169
  def function formals, *code
163
170
  begin_function *formals
@@ -175,6 +182,12 @@ module Voodoo
175
182
  @sections[real_section_name(@section)] << code
176
183
  end
177
184
 
185
+ # Returns true if a feature is supported by this generator,
186
+ # false otherwise.
187
+ def has_feature? name
188
+ @features.has_key? name
189
+ end
190
+
178
191
  # Get the real name of a section.
179
192
  # Given a section name which may be an alias, this method returns the
180
193
  # real name of the section.
@@ -5,7 +5,7 @@ module Voodoo
5
5
  # Class that generates ELF object files by invoking the GNU assembler on
6
6
  # the output of a code generator that generates GNU assembly.
7
7
  class GasELFGenerator
8
- def initialize asmgenerator, extra_args
8
+ def initialize asmgenerator, extra_args = ""
9
9
  @asmgenerator = asmgenerator
10
10
  @extra_args = extra_args
11
11
  @output_file_suffix = '.o'
@@ -33,7 +33,7 @@ module Voodoo
33
33
  Tempfile.open(base + '.s') do |asmfile|
34
34
  Tempfile.open(base + '.o') do |elffile|
35
35
  elffile.close
36
- # Write assembly code to nsamfile
36
+ # Write assembly code to asmfile
37
37
  @asmgenerator.write asmfile
38
38
  asmfile.close
39
39
  # Find out the name of the GNU assembler
@@ -1,4 +1,5 @@
1
1
  require 'voodoo/generators/common_code_generator'
2
+ require 'voodoo/generators/nasm_generator'
2
3
 
3
4
  module Voodoo
4
5
  # = i386 NASM Code Generator
@@ -61,6 +62,10 @@ module Voodoo
61
62
  # Stack pointer
62
63
  @SP = 'esp'
63
64
  super params
65
+ @features.merge! \
66
+ :'bits-per-word' => '32',
67
+ :'byte-order' => 'little-endian',
68
+ :'bytes-per-word' => '4'
64
69
  end
65
70
 
66
71
  # Call a function
@@ -104,7 +109,7 @@ module Voodoo
104
109
  emit "push dword #{value_ref}\n"
105
110
  end
106
111
 
107
- # Call a function, re-using the current call fram if possible
112
+ # Call a function, re-using the current call frame if possible
108
113
  def tail_call fun, *args
109
114
  emit "; tail-call #{fun} #{args.join ' '}\n"
110
115
  if args.length > @environment.args
@@ -3,7 +3,7 @@ require 'voodoo/generators/common_code_generator'
3
3
  module Voodoo
4
4
  # = MIPS GNU Assembler Code Generator
5
5
  #
6
- # The MIPS code generator generates i386 assembly code for use with
6
+ # The MIPS code generator generates assembly code for use with
7
7
  # the GNU assembler.
8
8
  #
9
9
  # == Calling Convention
@@ -43,7 +43,7 @@ module Voodoo
43
43
  # empty0 <-- $sp points here
44
44
  #
45
45
  # The function prologue of functions generated by this code generator
46
- # creates activiation frames that look as follows:
46
+ # creates activation frames that look as follows:
47
47
  #
48
48
  # :
49
49
  # old frame
@@ -117,6 +117,18 @@ module Voodoo
117
117
  @if_labels = []
118
118
  super params
119
119
  @output_file_suffix = '.s'
120
+ @features.merge! \
121
+ :'bits-per-word' => '32',
122
+ :'bytes-per-word' => '4'
123
+ case @architecture
124
+ when :mips
125
+ @features[:'byte-order'] = 'big-endian'
126
+ when :mipsel
127
+ @features[:'byte-order'] = 'little-endian'
128
+ else
129
+ raise ArgumentError.new("#{self.class} does not support " +
130
+ "architecture #{@architecture}")
131
+ end
120
132
  end
121
133
 
122
134
  def align alignment = nil
@@ -840,8 +852,6 @@ module Voodoo
840
852
  ret :call, func, *args
841
853
  end
842
854
 
843
- # TODO
844
-
845
855
  # Back up any stack arguments we will need after we overwrite them
846
856
  temporaries = @TEMPORARIES.dup
847
857
  nlocals = @environment.locals
@@ -35,7 +35,7 @@ module Voodoo
35
35
  Tempfile.open(base + '.o') do |elffile|
36
36
  begin
37
37
  elffile.close
38
- # Write NASM code to nsamfile
38
+ # Write NASM code to nasmfile
39
39
  @nasmgenerator.write nasmfile
40
40
  nasmfile.close
41
41
  # Find out the name of the nasm executable
@@ -29,15 +29,6 @@ module Voodoo
29
29
  @output_file_suffix = '.asm'
30
30
  end
31
31
 
32
- #
33
- # == Information About the Generator
34
- #
35
-
36
- # Returns the number of bits per word for this code generator.
37
- def wordsize
38
- @WORDSIZE * 8
39
- end
40
-
41
32
  #
42
33
  # == Labels
43
34
  #
@@ -415,7 +406,12 @@ module Voodoo
415
406
  # Set the byte at _base_ + _offset_ to _value_
416
407
  def set_byte base, offset, value
417
408
  emit "; set-byte #{base} #{offset} #{value}\n"
418
- value_ref = load_value value, @RETURN_REG
409
+ if immediate_operand?(value)
410
+ value_ref = value
411
+ else
412
+ load_value_into_register value, @RETURN_REG
413
+ value_ref = "al"
414
+ end
419
415
  addr_ref = load_address base, offset, 1
420
416
  emit "mov byte #{addr_ref}, #{value_ref}\n"
421
417
  end