Start over
This commit is contained in:
127
Rakefile
127
Rakefile
@@ -5,34 +5,137 @@
|
||||
|
||||
require 'open3'
|
||||
require 'rake/clean'
|
||||
require 'term/ansicolor'
|
||||
|
||||
CLEAN.include 'build/boot'
|
||||
CROSS_GCC = '../eugenios/build/rootfs/bin/riscv32-unknown-linux-gnu-gcc'
|
||||
SYSROOT = '../eugenios/build/sysroot'
|
||||
QEMU = 'qemu-riscv32'
|
||||
|
||||
CLEAN.include 'build/boot', 'build/valid'
|
||||
|
||||
directory 'build/boot'
|
||||
directory 'build/valid'
|
||||
|
||||
desc 'Final stage'
|
||||
task default: ['build/boot/stage2b', 'build/boot/stage2b.s', 'boot/stage2.elna'] do |t|
|
||||
exe, previous_output, source = t.prerequisites
|
||||
task default: ['build/valid/stage3', 'build/valid/stage3.s', 'boot/stage3.elna'] do |t|
|
||||
exe, expected, source = t.prerequisites
|
||||
|
||||
cat_arguments = ['cat', source]
|
||||
compiler_arguments = [QEMU, '-L', SYSROOT, exe]
|
||||
diff_arguments = ['diff', '-Nur', '--text', previous_output, '-']
|
||||
diff_arguments = ['diff', '-Nur', '--text', expected, '-']
|
||||
Open3.pipeline(cat_arguments, compiler_arguments, diff_arguments)
|
||||
end
|
||||
|
||||
file 'build/boot/test.s' => ['build/boot/stage1', 'boot/test.elna'] do |t|
|
||||
source, exe = t.prerequisites.partition { |prerequisite| prerequisite.end_with? '.elna' }
|
||||
desc 'Convert stage2 language into the stage3 language'
|
||||
task :convert do
|
||||
File.open('boot/stage3.elna', 'w') do |stage2|
|
||||
li_value = nil
|
||||
|
||||
File.open t.name, 'w' do |output|
|
||||
assemble_stage output, exe, source
|
||||
File.readlines('boot/stage2.elna').each do |line|
|
||||
if line.start_with?("\tj ")
|
||||
stage2 << "\tgoto " + line.chomp.delete_prefix("\tj ") + ";\n"
|
||||
li_value = nil
|
||||
elsif line.match?(/^\tli a0, [[:digit:]]/)
|
||||
li_value = line.delete_prefix("\tli a0, ").chomp
|
||||
elsif line == "\tli a0, '\\n'\n"
|
||||
li_value = "'\\n'"
|
||||
elsif !li_value.nil? && line.start_with?("\t_")
|
||||
stage2 << "\t" + line[1..-4] + li_value + ");\n"
|
||||
li_value = nil
|
||||
else
|
||||
stage2 << "\tli a0, #{li_value}\n" unless li_value.nil?
|
||||
stage2 << line
|
||||
li_value = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
file 'build/boot/test' => ['build/boot/test.s', 'boot/common-boot.s'] do |t|
|
||||
#
|
||||
# Stage 3.
|
||||
#
|
||||
|
||||
file 'build/valid/stage3' => 'build/valid/stage3.s' do |t|
|
||||
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
|
||||
end
|
||||
|
||||
task test: 'build/boot/test' do |t|
|
||||
sh QEMU, '-L', SYSROOT, t.prerequisites.first
|
||||
file 'build/valid/stage3.s' => ['build/boot/stage3', 'boot/stage3.elna'] do |t|
|
||||
exe, source = t.prerequisites
|
||||
|
||||
cat_arguments = ['cat', source]
|
||||
compiler_arguments = [QEMU, '-L', SYSROOT, exe]
|
||||
last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
|
||||
|
||||
IO.copy_stream last_stdout, t.name
|
||||
end
|
||||
|
||||
file 'build/boot/stage3' => 'build/boot/stage3.s' do |t|
|
||||
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
|
||||
end
|
||||
|
||||
file 'build/boot/stage3.s' => ['build/valid/stage2', 'boot/stage3.elna'] do |t|
|
||||
exe, source = t.prerequisites
|
||||
|
||||
cat_arguments = ['cat', source]
|
||||
compiler_arguments = [QEMU, '-L', SYSROOT, exe]
|
||||
last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
|
||||
|
||||
IO.copy_stream last_stdout, t.name
|
||||
end
|
||||
|
||||
#
|
||||
# Stage 2.
|
||||
#
|
||||
|
||||
file 'build/valid/stage2' => 'build/valid/stage2.s' do |t|
|
||||
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
|
||||
end
|
||||
|
||||
file 'build/valid/stage2.s' => ['build/boot/stage2', 'boot/stage2.elna'] do |t|
|
||||
exe, source = t.prerequisites
|
||||
|
||||
cat_arguments = ['cat', source]
|
||||
compiler_arguments = [QEMU, '-L', SYSROOT, exe]
|
||||
last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
|
||||
|
||||
IO.copy_stream last_stdout, t.name
|
||||
end
|
||||
|
||||
file 'build/boot/stage2' => 'build/boot/stage2.s' do |t|
|
||||
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
|
||||
end
|
||||
|
||||
file 'build/boot/stage2.s' => ['build/valid/stage1', 'boot/stage2.elna'] do |t|
|
||||
exe, source = t.prerequisites
|
||||
|
||||
cat_arguments = ['cat', source]
|
||||
compiler_arguments = [QEMU, '-L', SYSROOT, exe]
|
||||
last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
|
||||
|
||||
IO.copy_stream last_stdout, t.name
|
||||
end
|
||||
|
||||
#
|
||||
# Stage 1.
|
||||
#
|
||||
|
||||
file 'build/valid/stage1' => ['build/valid', 'build/valid/stage1.s'] do |t|
|
||||
source = t.prerequisites.select { |prerequisite| prerequisite.end_with? '.s' }
|
||||
|
||||
sh CROSS_GCC, '-nostdlib', '-o', t.name, *source
|
||||
end
|
||||
|
||||
file 'build/valid/stage1.s' => ['build/boot/stage1', 'boot/stage1.s', 'build/valid'] do |t|
|
||||
source, exe, = t.prerequisites.partition { |prerequisite| prerequisite.end_with? '.s' }
|
||||
|
||||
cat_arguments = ['cat', *source]
|
||||
compiler_arguments = [QEMU, '-L', SYSROOT, *exe]
|
||||
last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
|
||||
|
||||
IO.copy_stream last_stdout, t.name
|
||||
end
|
||||
|
||||
file 'build/boot/stage1' => ['build/boot', 'boot/stage1.s'] do |t|
|
||||
source = t.prerequisites.select { |prerequisite| prerequisite.end_with? '.s' }
|
||||
|
||||
sh CROSS_GCC, '-nostdlib', '-o', t.name, *source
|
||||
end
|
||||
|
Reference in New Issue
Block a user