Mercurial > lcfOS
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/serve_arm_as.py Sat Sep 14 17:29:10 2013 +0200 @@ -0,0 +1,66 @@ + +""" + 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() +