275
|
1
|
|
2 """
|
|
3 Tornado webserver interface to arm-elf-as.
|
|
4 """
|
263
|
5
|
|
6 import subprocess
|
|
7 import tornado.web
|
275
|
8 import tornado.ioloop
|
|
9 import io
|
263
|
10
|
275
|
11 def mangle(inp, outstream):
|
|
12 print('assembling...', file=outstream)
|
263
|
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')
|
275
|
18 print(output, file=outstream)
|
263
|
19
|
|
20 p_objdump = subprocess.Popen(['arm-elf-objdump', '-s'], stdout=subprocess.PIPE)
|
|
21 output = p_objdump.communicate()[0].decode('ascii')
|
275
|
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 """
|
263
|
46
|
|
47 class MainHandler(tornado.web.RequestHandler):
|
|
48 def get(self):
|
275
|
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)])
|
263
|
62
|
|
63 if __name__ == '__main__':
|
275
|
64 application.listen(8888)
|
|
65 tornado.ioloop.IOLoop.instance().start()
|
263
|
66
|