[117] | 1 | #! ruby -Ke
|
---|
| 2 |
|
---|
| 3 | if ARGV.size != 1 then
|
---|
| 4 | puts "Argment Error!"
|
---|
| 5 | exit
|
---|
| 6 | end
|
---|
| 7 |
|
---|
| 8 | #Input from gcc file
|
---|
| 9 | begin
|
---|
| 10 | gcc_asm_file = open(ARGV[0])
|
---|
| 11 | rescue
|
---|
| 12 | puts "File Open Error!"
|
---|
| 13 | exit
|
---|
| 14 | end
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | cx_asm = ""
|
---|
| 18 |
|
---|
| 19 | #Convert
|
---|
| 20 | while line = gcc_asm_file.gets
|
---|
| 21 | line = line.gsub('.section .reset.text', "RESET .cseg text")
|
---|
| 22 |
|
---|
| 23 | line = line.sub('/*', ';/*')
|
---|
| 24 |
|
---|
| 25 | line = line.sub(/^(\s*)\*/, '\1;*')
|
---|
| 26 |
|
---|
| 27 | line = line.sub(/.macro\s+(\w+)/, '\1 .macro')
|
---|
| 28 |
|
---|
| 29 | line = line.sub(/#include\s+[<"](.+)[>"]/, '$include (\1)')
|
---|
| 30 |
|
---|
| 31 | line = line.sub('.global', '.extern')
|
---|
| 32 |
|
---|
| 33 | line = line.sub('.globl', '.public')
|
---|
| 34 |
|
---|
| 35 | line = line.gsub(/AMARG\((\w+)\)/, '\1')
|
---|
| 36 |
|
---|
| 37 | line = line.gsub(/FLABEL\((\w+)\)/, '\1:')
|
---|
| 38 |
|
---|
| 39 | line = line.gsub('~', '!')
|
---|
| 40 |
|
---|
| 41 | line = line.gsub('#ifdef', '$ifdef')
|
---|
| 42 |
|
---|
| 43 | line = line.gsub('#ifndef', '$ifndef')
|
---|
| 44 |
|
---|
| 45 | line = line.gsub('#endif', '$endif')
|
---|
| 46 |
|
---|
| 47 | line = line.gsub('#else', '$else')
|
---|
| 48 |
|
---|
| 49 | line = line.gsub('#elif', '$elseif')
|
---|
| 50 |
|
---|
| 51 | line = line.gsub('.section', '.cseg')
|
---|
| 52 |
|
---|
| 53 | line = line.gsub(/\.endr/i, '.endm')
|
---|
| 54 |
|
---|
| 55 | line = line.gsub(/\.text/i, 'text')
|
---|
| 56 |
|
---|
| 57 | line = line.gsub('.word', '.dw')
|
---|
| 58 |
|
---|
| 59 | cx_asm = cx_asm + line
|
---|
| 60 | end
|
---|
| 61 |
|
---|
| 62 | cx_asm_file_name = File::basename(ARGV[0].sub(".S", ".asm"))
|
---|
| 63 | print sprintf("Output %s\n", cx_asm_file_name)
|
---|
| 64 |
|
---|
| 65 | #Output to asm file
|
---|
| 66 | File.open(cx_asm_file_name, 'w') {|file|
|
---|
| 67 | file.write cx_asm
|
---|
| 68 | }
|
---|