Mercurial > lcfOS
view util/serve_arm_as.py @ 319:8d07a4254f04
Work on burg
author | Windel Bouwman |
---|---|
date | Sat, 18 Jan 2014 18:58:43 +0100 |
parents | 6f2423df0675 |
children | c7cc54c0dfdf |
line wrap: on
line source
""" Tornado webserver interface to arm-elf-as. """ import subprocess import tornado.web import tornado.ioloop import io def mangle(inp, outstream): print('assembling...', file=outstream) p_as = subprocess.Popen(['arm-elf-as', '-mthumb'], stdin=subprocess.PIPE) p_as.communicate(input=inp.encode('ascii')) p_objdump = subprocess.Popen(['arm-elf-objdump', '-d'], stdout=subprocess.PIPE) output = p_objdump.communicate()[0].decode('ascii') print(output, file=outstream) p_objdump = subprocess.Popen(['arm-elf-objdump', '-s'], stdout=subprocess.PIPE) output = p_objdump.communicate()[0].decode('ascii') print(output, file=outstream) print('Done!', file=outstream) page = """ <html> <head> </head> <body> <h1> </h1> <form action="" method="post"> <textarea name="source" rows="25" cols="80"> %src% </textarea> <br> <input type="submit" value="Assemble!"> </form> <div> %result% </div> </body> </html> """ class MainHandler(tornado.web.RequestHandler): def get(self): src="sub sp,sp,#8" self.write(page.replace('%result%', '').replace('%src%', src)) def post(self): #print(self.request.body) src = self.get_argument('source') out = io.StringIO() mangle(src, out) txt = out.getvalue() txt = txt.replace('\n', '<br>') self.write(page.replace('%result%', txt).replace('%src%', src)) application = tornado.web.Application([(r"/", MainHandler)]) if __name__ == '__main__': application.listen(8888) tornado.ioloop.IOLoop.instance().start()