From 39269cc68a32f6e1a7524b00da36a1fe4cc7fb8b Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 21 Aug 2026 00:05:03 +0200 Subject: Implement Single and Double floats --- rakelib/gcc.rake | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'rakelib') diff --git a/rakelib/gcc.rake b/rakelib/gcc.rake index 7b6bf44..3d6cf85 100644 --- a/rakelib/gcc.rake +++ b/rakelib/gcc.rake @@ -91,10 +91,48 @@ def download_and_pipe(url, target, command) end end +# Makes a link from the source tree in the GCC tree. def link_frontend(source, destination) File.symlink Pathname.new(source).relative_path_from(destination), (destination + File.basename(source)) end +# Replaces an elna-native directive in the line with its dg-* equivalent, +# escaping the directive argument for dejagnu's Tcl evaluation. +def convert_directive(line, directive, dg_name) + line.sub(/\(\*\s*#{Regexp.escape directive}\s+(.*?)\s*\*\)/) do + escaped = Regexp.last_match(1).gsub(/[\\\[\]$"]/) { |character| "\\#{character}" } + "(* { #{dg_name} \"#{escaped}\" } *)" + end +end + +def convert_test(source, target, category, extra_lines = []) + File.open(target, 'wb') do |output| + File.foreach(source) do |line| + line = convert_directive(line, '@Error', 'dg-error') + line = convert_directive(line, '@Flags', 'dg-additional-options') + + output.puts line + end + + # Runnable tests compile, link and execute. + output.puts '(* { dg-do run } *)' if category == 'runnable' + + extra_lines.each { |line| output.puts line } + + # Suppress excess output so stray diagnostics do not fail the test. + output.puts '(* { dg-prune-output .* } *)' + + case category + when 'compilable' + # Assert that an output file was produced. + output.puts '(* { dg-final { output-exists } } *)' + when 'fail_compilation' + # Assert that no output file was produced. + output.puts '(* { dg-final { output-exists-not } } *)' + end + end +end + namespace :gcc do # Dependencies. GCC_VERSION = "16.1.0" @@ -139,7 +177,7 @@ namespace :gcc do FileList['boot', 'include', 'COPYING3', 'README.md', 'gcc/gcc', 'gcc/*.in', 'gcc/lang*'].each do |file| link_frontend file, source_destination end - FileList['testsuite/*', 'gcc/dg.exp', 'README.md'].each do |file| + FileList['gcc/dg.exp', 'README.md'].each do |file| link_frontend file, test_destination end destination = GCC_TREE + 'gcc/testsuite/lib' @@ -180,8 +218,52 @@ namespace :gcc do sh 'make', 'install', chdir: HOST_GCC end + desc 'Convert the testsuite into dejagnu format' + task :convert do + destination = GCC_TREE + 'gcc/testsuite/elna.dg' + destination.mkpath + source = Pathname.new 'testsuite' + + # Regenerate the category directories from scratch: this removes + # converted tests whose sources are gone and adds new ones. + %w[compilable fail_compilation runnable].each do |category| + category_destination = destination + category + category_source = source + category + + rm_rf category_destination + mkdir_p category_destination + + category_source.each_child do |test_path| + test_target = category_destination + test_path.basename + + # Multi-module tests: directories containing a sut.elna (system under + # test) and any helper files, compiled and linked together. + if test_path.directory? + main = test_path + 'sut.elna' + raise %(multi-module test directory \"#{test_path}\" must contain sut.elna) unless main + + test_target.mkdir + modules = test_path.children - [main] + + modules.each do |extra| + cp_r extra, test_target + end + extra_sources = test_target.glob("**/*.elna") + .map { |extra| %("#{extra.relative_path_from test_target}") } + + convert_test main, (test_target + 'sut.elna'), category, [ + "(* { dg-additional-options \"-I#{test_target.expand_path}\" } *)", + "(* { dg-additional-sources #{extra_sources * ' '} } *)" + ] + else + convert_test test_path, test_target, category + end + end + end + end + desc 'Run tests' - task :check do + task check: 'gcc:convert' do log_file = Pathname.new(HOST_GCC) + 'gcc/testsuite/elna/elna.log' sh 'make', 'check-elna', chdir: File.join(HOST_GCC, 'gcc') -- cgit v1.2.3