Mercurial > lcfOS
view util/serve_arm_as.py @ 308:2e7f55319858
Merged analyse into codegenerator
author | Windel Bouwman |
---|---|
date | Fri, 13 Dec 2013 11:53:29 +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()