/*

DISASSEMBLER PROGRAM...

Author: Matthew W. Coan
Date: Sun Sep  1 07:03:37 EDT 2013

*/
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include "asm.h"

using namespace std;
using namespace asm_tools;

int
main(int argc, char ** argv)
{
   int rc = 0;
   if(argc != 3) {
      cerr << "usage: " << argv[0] << " <program> <output>" << endl;
      exit(1);
   }
   try {
      Program prog(argv[1]);
      program_ptr = &prog;
      prog.load_code(argv[1]);
      prog.register_function("printf", (void*)printf);
      prog.register_function("getchar", (void*)getchar);
      prog.register_function("exit", (void*)exit);
      prog.link();
      ofstream fout(argv[2], ios::ate | ios::trunc | ios::in);
      if(fout) {
         prog.disassemble(fout);
         fout.close();
      }
   }
   catch(...) {
      cerr << "unknown exception..." << endl;
      exit(1);
   }
   return rc;
}
