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.
- data/bin/voodooc +71 -16
- data/lib/voodoo/compiler.rb +41 -13
- data/lib/voodoo/config.rb +5 -0
- data/lib/voodoo/generators/amd64_nasm_generator.rb +4 -0
- data/lib/voodoo/generators/arm_elf_generator.rb +33 -0
- data/lib/voodoo/generators/arm_gas_generator.rb +927 -0
- data/lib/voodoo/generators/common_code_generator.rb +19 -6
- data/lib/voodoo/generators/gas_elf_generator.rb +2 -2
- data/lib/voodoo/generators/i386_nasm_generator.rb +6 -1
- data/lib/voodoo/generators/mips_gas_generator.rb +14 -4
- data/lib/voodoo/generators/nasm_elf_generator.rb +1 -1
- data/lib/voodoo/generators/nasm_generator.rb +6 -10
- data/lib/voodoo/parser.rb +307 -128
- data/lib/voodoo/validator.rb +391 -0
- metadata +13 -11
- data/lib/voodoo/generators/generator_api1.rb +0 -95
@@ -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
|
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
|
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
|
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
|
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
|
@@ -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
|
-
|
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
|