| 32 | } |
| 33 | |
| 34 | int main(int argc, char** argv) { |
| 35 | const char* mode = argv[1]; |
| 36 | const char* file = argv[2]; |
| 37 | const char* expectedErr = argv[3]; |
| 38 | |
| 39 | assert(boost::filesystem::is_regular_file(file) && "Pass a real file"); |
| 40 | |
| 41 | std::ifstream ifile(file); |
| 42 | std::string str((std::istreambuf_iterator<char>(ifile)), std::istreambuf_iterator<char>()); |
| 43 | |
| 44 | json newData; |
| 45 | try { |
| 46 | newData = json::parse(str); |
| 47 | } catch (std::exception& e) { |
| 48 | std::cerr << "Error parsing: " << e.what(); |
| 49 | return 1; |
| 50 | } |
| 51 | Context c; |
| 52 | Result res; |
| 53 | |
| 54 | if (strcmp(mode, "mod") == 0) { |
| 55 | GraphModule* mod; |
| 56 | res += jsonToGraphModule(c, newData, "main", &mod); |
| 57 | |
| 58 | int ret = checkForErrors(res, expectedErr); |
| 59 | if (ret != 1) return ret; |
| 60 | |
| 61 | std::unique_ptr<llvm::Module> llmod = nullptr; |
| 62 | res += c.compileModule(mod->fullName(), true, &llmod); |
| 63 | |
| 64 | ret = checkForErrors(res, expectedErr); |
| 65 | if (ret != 1) return ret; |
| 66 | |
| 67 | return 1; |
| 68 | |
| 69 | } else if (strcmp(mode, "func") == 0) { |
| 70 | auto mod = c.newGraphModule("main"); |
| 71 | mod->addDependency("lang"); |
| 72 | |
| 73 | GraphFunction* func; |
| 74 | res += createGraphFunctionDeclarationFromJson(*mod, newData, &func); |
| 75 | |
| 76 | int ret = checkForErrors(res, expectedErr); |
| 77 | if (ret != 1) return ret; |
| 78 | |
| 79 | res += jsonToGraphFunction(*func, newData); |
| 80 | |
| 81 | ret = checkForErrors(res, expectedErr); |
| 82 | if (ret != 1) return ret; |
| 83 | |
| 84 | // create module for the functions |
| 85 | std::unique_ptr<llvm::Module> llmod; |
| 86 | |
| 87 | res += c.compileModule("main", true, &llmod); |
| 88 | |
| 89 | ret = checkForErrors(res, expectedErr); |
| 90 | if (ret != 1) return ret; |
| 91 |
nothing calls this directly
no test coverage detected