Mercurial > lcfOS
comparison util/serve_arm_as.py @ 275:6f2423df0675
Fixed serve arm-as
author | Windel Bouwman |
---|---|
date | Sat, 14 Sep 2013 17:29:10 +0200 |
parents | python/serve_arm_as.py@c352dec19299 |
children | c7cc54c0dfdf |
comparison
equal
deleted
inserted
replaced
274:ea93e0a7a31e | 275:6f2423df0675 |
---|---|
1 | |
2 """ | |
3 Tornado webserver interface to arm-elf-as. | |
4 """ | |
5 | |
6 import subprocess | |
7 import tornado.web | |
8 import tornado.ioloop | |
9 import io | |
10 | |
11 def mangle(inp, outstream): | |
12 print('assembling...', file=outstream) | |
13 p_as = subprocess.Popen(['arm-elf-as', '-mthumb'], stdin=subprocess.PIPE) | |
14 p_as.communicate(input=inp.encode('ascii')) | |
15 | |
16 p_objdump = subprocess.Popen(['arm-elf-objdump', '-d'], stdout=subprocess.PIPE) | |
17 output = p_objdump.communicate()[0].decode('ascii') | |
18 print(output, file=outstream) | |
19 | |
20 p_objdump = subprocess.Popen(['arm-elf-objdump', '-s'], stdout=subprocess.PIPE) | |
21 output = p_objdump.communicate()[0].decode('ascii') | |
22 print(output, file=outstream) | |
23 print('Done!', file=outstream) | |
24 | |
25 page = """ | |
26 <html> | |
27 <head> | |
28 </head> | |
29 <body> | |
30 <h1> | |
31 | |
32 </h1> | |
33 <form action="" method="post"> | |
34 <textarea name="source" rows="25" cols="80"> | |
35 %src% | |
36 </textarea> | |
37 <br> | |
38 <input type="submit" value="Assemble!"> | |
39 </form> | |
40 <div> | |
41 %result% | |
42 </div> | |
43 </body> | |
44 </html> | |
45 """ | |
46 | |
47 class MainHandler(tornado.web.RequestHandler): | |
48 def get(self): | |
49 src="sub sp,sp,#8" | |
50 self.write(page.replace('%result%', '').replace('%src%', src)) | |
51 def post(self): | |
52 #print(self.request.body) | |
53 src = self.get_argument('source') | |
54 out = io.StringIO() | |
55 mangle(src, out) | |
56 txt = out.getvalue() | |
57 txt = txt.replace('\n', '<br>') | |
58 self.write(page.replace('%result%', txt).replace('%src%', src)) | |
59 | |
60 | |
61 application = tornado.web.Application([(r"/", MainHandler)]) | |
62 | |
63 if __name__ == '__main__': | |
64 application.listen(8888) | |
65 tornado.ioloop.IOLoop.instance().start() | |
66 |