lib/adarwin/engine.rb in bones-compiler-1.3.1 vs lib/adarwin/engine.rb in bones-compiler-1.6.0
- old
+ new
@@ -81,20 +81,31 @@
parser.type_names << 'size_t'
# Parse the original source code into AST form (using CAST)
original_ast = parser.parse(preprocessor.parsed_code)
+ # Process every SCoP, one by one
+ @id = 0
+ @result[:species_code] = preprocessor.target_code
+ preprocessor.scop_code.each do |scop_code|
+ process_scop(scop_code)
+ end
+ end
+
+ def process_scop(scop_code)
# Create an AST of the SCoP (using CAST) and save a backup
- scop_ast = C::Block.parse('{'+preprocessor.scop_code+'}')
+ scop_ast = C::Block.parse('{'+scop_code+'}')
original_scop_ast = scop_ast.clone
# Process the scop to identify the loop nests of interest and to find the
# corresponding species. This is the method performing most of the work.
@nests = []
- @id = 0
populate_nests(scop_ast)
+ # return if no loop nests are found in the code
+ return unless @nests.length > 0
+
# Remove inner-loop (nested) species. This removes all species that are
# found within another species. For completeness, this might be desired in
# some cases.
# TODO: Make this an option
@nests.each do |nest|
@@ -139,19 +150,19 @@
# Print the result SCoP
puts modified_scop if !@options[:silent]
# Store the result
- @result[:species_code] = preprocessor.target_code.gsub(preprocessor.scop_code,modified_scop)
+ @result[:species_code].gsub!(scop_code,modified_scop)
end
# This method writes the output code to a file.
def write_output
# Populate the species file
# TODO: The filename is fixed, make this an optional argument
- File.open(File.join(@options[:application].split('.').first+'_species'+'.c'),'w') do |target|
+ File.open(File.join(@options[:application].rpartition('.').first+'_species'+'.c'),'w') do |target|
target.puts @result[:species_code]
end
end
# This method populates the Nest datastructure (recursively). It is the main
@@ -170,12 +181,12 @@
if @options[:only_alg_number].to_i == 99 || @options[:only_alg_number].to_i == (@id+1)
# Only continue if the nest is an actual loop nest
if nest.for_statement?
@nests.push(Nest.new(new_level,nest,@id,@basename,!@options[:silent]))
+ @id += 1
end
end
- @id += 1
end
# Proceed to the next depth level.
# TODO: Make it an option to only investigate the outer most level(s).
ast.stmts.each_with_index do |nest,index|