SHARE
TWEET

Untitled

a guest May 19th, 2017 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import os, sys
  4. import subprocess
  5. from optparse import OptionParser
  6.  
  7. compiler = "pipoca"
  8. assembler = "yasm"
  9. linker = "gcc"
  10.  
  11. def exec_wait(args, err):
  12.     try:
  13.         subprocess.check_call(args, stdout=subprocess.PIPE)
  14.     except subprocess.CalledProcessError:
  15.         error(err)
  16.  
  17. def check_file_exists(f, err):
  18.     if not os.path.isfile(f):
  19.         error(err)
  20.  
  21. def error(s):
  22.     print "error: %s" % (s)
  23.     sys.exit()
  24.  
  25. def check_args():
  26.     usage = "usage: %prog [options] example.pip -o example"
  27.     parser = OptionParser(usage=usage, version="%prog 0.1")
  28.  
  29.     parser.add_option("-o", "--output", dest="filename",
  30.                       help="writes the program to prog", metavar="prog")
  31.  
  32.     global options, args
  33.     (options, args) = parser.parse_args()
  34.  
  35.  
  36.     if len(sys.argv) < 2 or len(args) < 1:
  37.         parser.print_help()
  38.         sys.exit()
  39.  
  40. def compile():
  41.     global file
  42.     file = args[0]
  43.  
  44.     # check for the program and the compiler
  45.     check_file_exists(file, "file '%s' not found or does not exist" % (file))
  46.     check_file_exists(compiler, "compiler '%s' not found or does not exist" % (compiler))
  47.    
  48.     # compile the program
  49.     exec_wait(["pipoca", file], "error compiling '%s'" % (file))
  50.  
  51. def assembly():
  52.     # check for the assembler
  53.  
  54.     # assembly it
  55.     #exec_wait(["yasm
  56.     pass
  57.  
  58. def link():
  59.     pass
  60.  
  61. def main():
  62.     check_args()
  63.     compile()
  64.     assembly()
  65.     link()
  66.  
  67. if __name__ == '__main__':
  68.     main()
RAW Paste Data
Top