#ifdef UNICODE#undef UNICODE#endif#include <windows.h>#include <conio.h>#include <cstdlib>#include <iostream>using std::cout;using std::cerr;using std::endl;#include <string>using std::string;string command;extern "C" __declspec(dllexport) int _cdecl Compile(int argc, char* argv[]);int getParametersForCompile(int argc, char* argv[]);int getParametersForLinking(int argc, char* argv[]);
#include "GoCompile.h"#define CLS system("cls")#define getch() (option = _getch())char option;extern "C" __declspec(dllexport) int _cdecl Compile(int argc, char* argv[]){ if(argc < 2) { cerr << "Invalid number of arguments." << endl; return EXIT_FAILURE; } command = "8g "; if(getParametersForCompile(argc, argv) & EXIT_FAILURE) return EXIT_FAILURE; if(getParametersForLinking(argc, argv) & EXIT_FAILURE) return EXIT_FAILURE; return EXIT_SUCCESS;}int getParametersForCompile(int argc, char* argv[]){ cout << "Would you like to include packages from a specific directory? <y\n>" << endl; if(getch() == 'y') { char directory[50]; cout << "Please enter the directory." << endl; std::cin.getline(directory, 50); command.append("-I ").append(directory).append(" "); } CLS; cout << "Would you like to have the compiler print declarations? <y\n>" << endl; if(getch() == 'y') command.append("-d "); CLS; cout << "Would you like to have the compiler remove limits on errors printed? <y\n>" << endl; if(getch() == 'y') command.append("-e "); CLS; cout << "Would you like to have the compiler print the stack frame structure? <y\n>" << endl; if(getch() == 'y') command.append("-f "); CLS; cout << "Would you like the compile to panic on error? <y\n>" << endl; if(getch() == 'y') command.append("-h "); CLS; cout << "Would you like to specify the package name? <y\n>" << endl; if(getch() == 'y') { char name[50]; cout << "Please enter the package name." << endl; std::cin.getline(name, 50); command.append("-k ").append(name).append(" "); } CLS; cout << "Would you like to specify the name of the output file? <y\n>" << endl; if(getch() == 'y') { char output[50]; cout << "Please enter the output file name. (Including extention)" << endl; std::cin.getline(output, 50); command.append("-o ").append(output).append(" "); } CLS; cout << "Would you like the compiler to print the assembly language? <y\n>" << endl; if(getch() == 'y') command.append("-S "); CLS; cout << "Would you like the compiler to print the parse tree? <y\n>" << endl; if(getch() == 'y') command.append("-w "); CLS; cout << "Would you like the compiler to print lex tokens? <y\n>" << endl; if(getch() == 'y') command.append("-x "); CLS; string command_temp; for(short i = 1;i < argc;i++) { command_temp = command; if(system(command_temp.append(argv[i]).append(".go").c_str()) == 0) continue; else return EXIT_FAILURE; } cout << "Press any key to link files." << endl; _getch(); return EXIT_SUCCESS;}int getParametersForLinking(int argc, char* argv[]){ CLS; cout << "Would you like to specify a name for the executable? <y\n>" << endl; command = "8l "; string command_temp; if(getch() =='y') { char name[50]; cout << "Please enter the executable name" << endl; std::cin.getline(name, 50); command.append("-o ").append(name).append(" "); } for(short i = 1;i < argc;i++) { command_temp = command; if(system(command_temp.append(argv[i]).append(".8").c_str()) == 0) continue; else return EXIT_FAILURE; } cout << "Linking Succesful. Press any key to end session" << endl; _getch(); return EXIT_SUCCESS;}