mirror of
https://github.com/samsonjs/compiler.git
synced 2026-03-25 08:45:52 +00:00
build test files in bin/ subdir, cleaned up Makefile and .gitignore.
This commit is contained in:
parent
9b5c3b795e
commit
be4bd30315
4 changed files with 35 additions and 54 deletions
19
.gitignore
vendored
19
.gitignore
vendored
|
|
@ -3,21 +3,4 @@
|
|||
trash
|
||||
test/*.o
|
||||
test/*.asm
|
||||
|
||||
# TODO just ignore test/bin/* or similar
|
||||
test/test_big
|
||||
test/test_lt
|
||||
test/test_gt
|
||||
test/test_ge
|
||||
test/test_le
|
||||
test/test_eq
|
||||
test/test_neq
|
||||
test/test_while
|
||||
test/test_if
|
||||
test/test_until
|
||||
test/test_repeat
|
||||
test/test_do
|
||||
test/test_for
|
||||
test/test_break
|
||||
test/test_print
|
||||
test/test_huge
|
||||
test/bin/*
|
||||
|
|
|
|||
15
build.rb
15
build.rb
|
|
@ -6,7 +6,7 @@ require 'asm/binary'
|
|||
require 'asm/machosymtab'
|
||||
require 'asm/machofile'
|
||||
|
||||
# usage: build.rb <filename> [elf | macho ] [asm | bin]
|
||||
# usage: build.rb <filename> [output filename] [elf | macho ] [asm | bin]
|
||||
|
||||
DefaultBinFormats = Hash.new('bin')
|
||||
def binformat(p,f) DefaultBinFormats[p]=f end
|
||||
|
|
@ -14,12 +14,13 @@ binformat 'darwin', 'macho'
|
|||
binformat 'linux', 'elf'
|
||||
|
||||
def main
|
||||
filename = ARGV[0].to_s
|
||||
filename = ARGV.shift.to_s
|
||||
raise "can't read #{filename}" unless File.readable?(filename)
|
||||
outdir = ARGV.shift || '.'
|
||||
platform = `uname -s`.chomp.downcase
|
||||
binformat = ARGV[1] ? ARGV[1].downcase : DefaultBinFormats[platform]
|
||||
puts "Building #{filename} for #{platform}, binformat is #{binformat} ..."
|
||||
outfile = build(filename, platform, binformat)
|
||||
outfile = build(filename, outdir, platform, binformat)
|
||||
puts outfile
|
||||
exit
|
||||
end
|
||||
|
|
@ -72,7 +73,7 @@ def assemble(filename, binformat='elf')
|
|||
end
|
||||
|
||||
# link with ld, return resulting filename.
|
||||
def link(filename, platform='linux')
|
||||
def link(filename, outdir, platform='linux')
|
||||
f = base(filename)
|
||||
cmd, args = *case platform
|
||||
when 'darwin': ['gcc', '-arch i386']
|
||||
|
|
@ -85,8 +86,8 @@ def link(filename, platform='linux')
|
|||
return f
|
||||
end
|
||||
|
||||
def build(filename, platform='linux', binformat='elf')
|
||||
objfile = base(filename) + '.o'
|
||||
def build(filename, outdir, platform='linux', binformat='elf')
|
||||
objfile = File.join(outdir, base(filename) + '.o')
|
||||
symtab, objwriter_class =
|
||||
case binformat
|
||||
when 'elf': [Assembler::ELFSymtab.new, Assembler::ELFFile]
|
||||
|
|
@ -95,7 +96,7 @@ def build(filename, platform='linux', binformat='elf')
|
|||
raise "unsupported binary format: #{binformat}"
|
||||
end
|
||||
compile(filename, objfile, Assembler::Binary.new(platform, symtab, objwriter_class))
|
||||
exefile = link(objfile, platform)
|
||||
exefile = link(objfile, outdir, platform)
|
||||
return exefile
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -15,67 +15,63 @@ all: lt gt ge le eq neq or and if while until repeat for do break print big huge
|
|||
@true
|
||||
|
||||
lt: test.rb test_lt.code
|
||||
@./test.rb lt $(BINFORMAT)
|
||||
@./test.rb lt bin $(BINFORMAT)
|
||||
|
||||
gt: test.rb test_gt.code
|
||||
@./test.rb gt $(BINFORMAT)
|
||||
@./test.rb gt bin $(BINFORMAT)
|
||||
|
||||
ge: test.rb test_ge.code
|
||||
@./test.rb ge $(BINFORMAT)
|
||||
@./test.rb ge bin $(BINFORMAT)
|
||||
|
||||
le: test.rb test_le.code
|
||||
@./test.rb le $(BINFORMAT)
|
||||
@./test.rb le bin $(BINFORMAT)
|
||||
|
||||
eq: test.rb test_eq.code
|
||||
@./test.rb eq $(BINFORMAT)
|
||||
@./test.rb eq bin $(BINFORMAT)
|
||||
|
||||
neq: test.rb test_neq.code
|
||||
@./test.rb neq $(BINFORMAT)
|
||||
@./test.rb neq bin $(BINFORMAT)
|
||||
|
||||
if: test.rb test_if.code
|
||||
@./test.rb if $(BINFORMAT)
|
||||
@./test.rb if bin $(BINFORMAT)
|
||||
|
||||
while: test.rb test_while.code
|
||||
@./test.rb while $(BINFORMAT)
|
||||
@./test.rb while bin $(BINFORMAT)
|
||||
|
||||
until: test.rb test_until.code
|
||||
@./test.rb until $(BINFORMAT)
|
||||
@./test.rb until bin $(BINFORMAT)
|
||||
|
||||
repeat: test.rb test_repeat.code
|
||||
@./test.rb repeat $(BINFORMAT)
|
||||
@./test.rb repeat bin $(BINFORMAT)
|
||||
|
||||
for: test.rb test_for.code
|
||||
@./test.rb for $(BINFORMAT)
|
||||
@./test.rb for bin $(BINFORMAT)
|
||||
|
||||
do: test.rb test_do.code
|
||||
@./test.rb do $(BINFORMAT)
|
||||
@./test.rb do bin $(BINFORMAT)
|
||||
|
||||
break: test.rb test_break.code
|
||||
@./test.rb break $(BINFORMAT)
|
||||
@./test.rb break bin $(BINFORMAT)
|
||||
|
||||
print: test.rb test_print.code
|
||||
@./test.rb print $(BINFORMAT)
|
||||
@./test.rb print bin $(BINFORMAT)
|
||||
|
||||
big: test.rb test_big.code
|
||||
@./test.rb big $(BINFORMAT)
|
||||
@./test.rb big bin $(BINFORMAT)
|
||||
|
||||
huge: test.rb test_huge.code
|
||||
@./test.rb huge $(BINFORMAT)
|
||||
@./test.rb huge bin $(BINFORMAT)
|
||||
|
||||
or: test.rb test_or.code
|
||||
@./test.rb or $(BINFORMAT)
|
||||
@./test.rb or bin $(BINFORMAT)
|
||||
|
||||
and: test.rb test_and.code
|
||||
@./test.rb and $(BINFORMAT)
|
||||
@./test.rb and bin $(BINFORMAT)
|
||||
|
||||
bit_ops: test.rb test_bit_ops.code
|
||||
@./test.rb bit_ops $(BINFORMAT)
|
||||
@./test.rb bit_ops bin $(BINFORMAT)
|
||||
|
||||
clean:
|
||||
@rm -f test*.asm test*.o
|
||||
@rm -f test_big test_lt test_gt test_ge test_le test_eq test_neq
|
||||
@rm -f test_while test_if test_until test_repeat test_do
|
||||
@rm -f test_for test_break test_print test_huge
|
||||
@rm -f test_and test_or test_bit_ops
|
||||
@rm -f bin/*
|
||||
|
||||
.PHONY: clean
|
||||
11
test/test.rb
11
test/test.rb
|
|
@ -5,15 +5,16 @@ $LOAD_PATH << ROOT
|
|||
|
||||
require 'build'
|
||||
|
||||
# usage: test.rb <func> [binformat] [format]
|
||||
# usage: test.rb <func> [outdir] [binformat] [format]
|
||||
|
||||
def main
|
||||
func = ARGV[0].to_s
|
||||
binformat = ARGV[1] ? ARGV[1].downcase : 'elf'
|
||||
format = ARGV[2] ? ARGV[2].downcase : 'asm'
|
||||
func = ARGV.shift
|
||||
outdir = ARGV.shift || '.'
|
||||
binformat = (ARGV.shift || 'elf').downcase
|
||||
format = (ARGV.shift || 'asm').downcase
|
||||
platform = `uname -s`.chomp.downcase
|
||||
print "testing #{func} ... "
|
||||
success = run( build("test_#{func}.code", platform, binformat) )
|
||||
success = run( build("test_#{func}.code", outdir, platform, binformat) )
|
||||
if success == 0
|
||||
puts "pass"
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue