const char *clm_code_gen_main(ArrayList *statements, ClmScope *globalScope) { data.scope = globalScope; data.labelID = 0; data.temporaryID = 0; data.inFunction = 0; data.size = strlen(ASM_HEADER) + 1; data.capacity = data.size; data.code = malloc(strlen(ASM_HEADER) + 1); strcpy(data.code, ASM_HEADER); gen_functions(statements); writeLine(ASM_START); gen_statements(statements); writeLine(ASM_EXIT_PROCESS); writeLine(ASM_DATA); gen_globals(globalScope); return data.code; }
int main(int argc, char**argv) { int ret = 1; if (argc < 2) { std::cerr << "No parameters given\n" << "Usage:\n" << "xml2ulxr [--gen-server]\n" << " [--gen-client]\n" << " [--gen-class=class-name]\n" << " [--gen-funcs=prefix]\n" << " [--file-name=filename.ext]\n" << " [--dest-dir=dest-path]\n" << " [--disable-timestamp\n" << "\n"; return 1; } std::vector<std::string> classes; for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; if (arg == "--gen-server") gen_server = true; else if (arg == "--gen-client") gen_client = true; else if (arg.substr(0, 12) == "--gen-class=") classes.push_back(arg.substr(12)); else if (arg.substr(0, 12) == "--gen-funcs=") { funcsname = arg.substr(12); gen_funcs = true; } else if (arg.substr(0, 12) == "--file-name=") sourcename = arg.substr(12); else if (arg.substr(0, 11) == "--dest-dir=") destdir = arg.substr(11); else if (arg == "--disable-timestamp") GenerateMethod::setDateOutput(false); else { std::cerr << "Unknown option: " << arg << std::endl; return 1; } } if (sourcename.length() == 0) { std::cerr << "No source file given\n"; return 1; } std::FILE *fs; fs = std::fopen (sourcename.c_str(), "r"); if (fs == 0) { std::cerr << "File not readable: " << sourcename << std::endl; return 2; } char buffer[1000]; UlxrIdlParser parser; try { while (!feof(fs)) { unsigned readed = std::fread(buffer, 1, sizeof(buffer), fs); if (!parser.parse(buffer, readed, false)) { throw XmlException(parser.mapToFaultCode(parser.getErrorCode()), "Problem while parsing idl file", parser.getCurrentLineNumber(), parser.getErrorString(parser.getErrorCode())); } } ret = 0; } catch(std::exception &ex) { std::cerr << ex.what() << std::endl; ret = 1; } catch(...) { std::cerr << "Unexpected problem while parsing idl file\n"; ret = 1; } fclose(fs); if (ret != 0) return ret; try { for (unsigned ii = 0; ii < parser.numClasses(); ++ii) { // std::cout << "Class available: " << parser.getClass(ii).getName() << std::endl; if (classes.size() == 0) gen_file(parser.getClass(ii)); else { for (unsigned ic = 0; ic < classes.size(); ++ic) { if (classes[ic] == parser.getClass(ii).getName()) gen_file(parser.getClass(ii)); else std::cout << "Skipping class: " << parser.getClass(ii).getName() << std::endl; } } } gen_functions(parser.getFunctions()); ret = 0; } catch(std::exception &ex) { std::cerr << ex.what() << std::endl; ret = 2; } catch(...) { std::cerr << "Unexpected problem while generating mock files\n"; ret = 2; } return ret; }