annotate util/serve_arm_as.py @ 290:7b38782ed496

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