Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv5090
Modified Files:
mswhello.tran tran.py
Log Message:
made tran.py able to generate PE executables
Index: mswhello.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mswhello.tran 22 Apr 2003 22:29:30 -0000 1.7
+++ mswhello.tran 16 May 2003 17:27:01 -0000 1.8
@@ -6,27 +6,28 @@
\
\\\\ @(#) $Id$
-\ NOTE that mswhello.tran is not currently translatable
+\ Don't forget to translate with -fpe
include ia32
lit :macro $call #xe8 b, 4 - $-t, ;
// :macro GetStdHandle \ (handle-number -- handle)
- commit ref GetStdHandle@kernel32#344 $call %eax ;
+ commit ref GetStdHandle@kernel32 $call %eax ;
\ FIXME: reverse arguments
-// :macro WriteFile \ (file buffer count result* overlapped* -- result)
- commit ref WriteFile@kernel32#730 $call %eax ;
+\ // :macro WriteFile \ (file buffer count result* overlapped* -- result)
+\ commit ref WriteFile@kernel32 $call %eax ;
// :macro ExitProcess \ (code --)
- commit ref ExitProcess@kernel32#131 $call ;
+ commit ref ExitProcess@kernel32 $call ;
\ main entry point
label _start
-11 GetStdHandle
- ref message 7 ref rckeep 0 WriteFile drop
+ 0 $push ref rckeep $push 7 $push ref message $push $push
+ ref WriteFile@kernel32 $call
0 ExitProcess
.data
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- tran.py 16 May 2003 15:41:19 -0000 1.74
+++ tran.py 16 May 2003 17:27:01 -0000 1.75
@@ -15,6 +15,7 @@
from linkie import Linkie
from shlex import shlex
import elf
+import pe
import string
import sys
@@ -284,17 +285,21 @@
interpreter.bss = Linkie('<')
interpreter.current = interpreter.text
+default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'}
verbose = 0
+format = 'elf'
def main ():
global prep, verbose
- opts, args = getopt(sys.argv[1:], 'vo:', ['verbose', 'output=', 'list-words'])
- output_name = 'a.out'
+ opts, args = getopt(sys.argv[1:], 'vo:f:', ['verbose', 'output=', 'format=', 'list-words'])
+ output_name = None
list_words = 0
for opt, arg in opts:
if opt in ('-o', '--output'): output_name = arg
if opt in ('-v', '--verbose'): verbose = 1
+ if opt in ('-f', '--format'): format = arg
if opt == '--list-words': list_words = 1
+ if output_name == None: output_name = default_output_names[format]
if list_words:
wd = {}
for w in Meaning.keys():
@@ -318,10 +323,15 @@
print 'BSS'; interpreter.bss.dump()
if Regstack:
raise 'Regstack not empty after parsing ended', Regstack
- binary = elf.make_ELF32_object(text = interpreter.text,
- data = interpreter.data,
- bss = interpreter.bss,
- flags = 's')
+ if format == 'elf':
+ binary = elf.make_ELF32_object(text = interpreter.text,
+ data = interpreter.data,
+ bss = interpreter.bss,
+ flags = 's')
+ elif format == 'pe':
+ binary = pe.make_pe_executable(text = interpreter.text,
+ data = interpreter.data,
+ bss = interpreter.bss)
f = open(output_name, 'w')
binary.get_file().tofile(f)
f.close()
|