Implement a RISC-V backend
This commit is contained in:
43
Rakefile
43
Rakefile
@ -4,12 +4,13 @@ require 'open3'
|
||||
|
||||
DFLAGS = ['--warn-no-deprecated', '-L/usr/lib64/gcc-12']
|
||||
BINARY = 'build/bin/elna'
|
||||
TESTS = FileList['tests/*.elna'].flat_map do |test|
|
||||
TESTS = FileList['tests/*.eln'].flat_map do |test|
|
||||
build = Pathname.new 'build'
|
||||
asm_test = build + 'asm' + Pathname.new(test).basename('')
|
||||
test_basename = Pathname.new(test).basename('')
|
||||
|
||||
[build + test, asm_test].map { |path| path.sub_ext('').to_path }
|
||||
[build + 'riscv' + test_basename].map { |path| path.sub_ext('').to_path }
|
||||
end
|
||||
|
||||
SOURCES = FileList['source/**/*.d']
|
||||
|
||||
directory 'build'
|
||||
@ -17,27 +18,23 @@ directory 'build'
|
||||
CLEAN.include 'build'
|
||||
CLEAN.include '.dub'
|
||||
|
||||
rule(/build\/tests\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.o') }) do |t|
|
||||
sh 'ld.gold', '-L/usr/lib64',
|
||||
'--dynamic-linker', '/lib64/ld-linux-x86-64.so.2',
|
||||
rule(/build\/riscv\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.o') }) do |t|
|
||||
sh '/opt/riscv/bin/riscv32-unknown-elf-ld',
|
||||
'-o', t.name,
|
||||
'/usr/lib64/crt1.o', '/usr/lib64/crti.o', '-lc', t.source, '/usr/lib64/crtn.o'
|
||||
'-L/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0',
|
||||
'-L/opt/riscv/riscv32-unknown-elf/lib',
|
||||
'/opt/riscv/riscv32-unknown-elf/lib/crt0.o',
|
||||
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtbegin.o',
|
||||
t.source,
|
||||
'--start-group', '-lc', '-lgloss', '--end-group',
|
||||
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtend.o'
|
||||
end
|
||||
|
||||
rule(/build\/asm\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.s') }) do |t|
|
||||
sh 'gcc', '-x', 'assembler', '-o', t.name, t.source
|
||||
end
|
||||
|
||||
rule(/build\/tests\/.+\.o$/ => ->(file) { test_for_object(file) }) do |t|
|
||||
rule(/build\/riscv\/.+\.o$/ => ->(file) { test_for_object(file, '.eln') }) do |t|
|
||||
Pathname.new(t.name).dirname.mkpath
|
||||
sh BINARY, '-o', t.name, t.source
|
||||
end
|
||||
|
||||
rule(/build\/asm\/.+\.s$/ => ->(file) { test_for_object(file) }) do |t|
|
||||
Pathname.new(t.name).dirname.mkpath
|
||||
sh BINARY, '-s', '-o', t.name, t.source
|
||||
end
|
||||
|
||||
file BINARY => SOURCES do |t|
|
||||
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc-12')
|
||||
end
|
||||
@ -56,7 +53,13 @@ task test: BINARY do
|
||||
.to_i
|
||||
|
||||
puts "Running #{test}"
|
||||
system test
|
||||
if test.include? '/riscv/'
|
||||
system('/opt/riscv/bin/spike',
|
||||
'/opt/riscv/riscv32-unknown-elf/bin/pk', test,
|
||||
{ out: '/dev/null' })
|
||||
else
|
||||
raise 'Unsupported test platform'
|
||||
end
|
||||
actual = $?.exitstatus
|
||||
|
||||
fail "#{test}: Expected #{expected}, got #{actual}" unless expected == actual
|
||||
@ -68,10 +71,10 @@ task unittest: SOURCES do |t|
|
||||
sh('dub', 'test', '--compiler=gdc-12')
|
||||
end
|
||||
|
||||
def test_for_object(out_file)
|
||||
def test_for_object(out_file, extension)
|
||||
test_source = Pathname
|
||||
.new(out_file)
|
||||
.sub_ext('.elna')
|
||||
.sub_ext(extension)
|
||||
.sub(/^build\/[[:alpha:]]+\//, 'tests/')
|
||||
.to_path
|
||||
[test_source, BINARY]
|
||||
|
Reference in New Issue
Block a user