/*

RUN A PROGRAM FROM THE ASM PROGRAM

Author: Matthew W. Coan
Date: Thu Aug 29 21:53:23 EDT 2013

*/
#include <iostream>
#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 != 2) {
      cerr << "usage: " << argv[0] << " <program>" << endl;
      exit(1);
   }
   try {
      Program prog(argv[1]);
      program_ptr = &prog;
cout << "printf == " << (size_t)printf << "\n" << endl;
cout << "load code next..." << endl;
      prog.load_code(argv[1]);
      prog.register_function("printf", (void*)printf);
      prog.register_function("getchar", (void*)getchar);
      prog.register_function("exit", (void*)exit);
cout << "printf == " << (size_t)printf << "\n" << endl;
cout << "link next..." << endl;
      prog.link();
cout << "dump next..." << endl;
      prog.dump(cout);
cout << "run next..." << endl;
      prog.run();
   }
   catch(...) {
      cerr << "unknown exception..." << endl;
      exit(1);
   }
   return rc;
}
