// Returns a rapidjson Value with the type rapidjson::Value SuperastCPP::createTypeValue(const std::string& type) { rapidjson::Value typeValue(rapidjson::kObjectType); rapidjson::Value nameValue(type.c_str(), type.size(), allocator); addId(typeValue); typeValue.AddMember("name", nameValue, allocator); return typeValue; }
void jsonifyModuleType(const ModuleType& moduleType, rapidjson::Value& moduleTypeValue, rapidjson::Document& document){ //TODO assert moduleType.isComposite moduleTypeValue.SetObject(); moduleTypeValue.AddMember("name", moduleType.getName().c_str(), document.GetAllocator()); moduleTypeValue.AddMember("description", moduleType.getDescription().c_str(), document.GetAllocator()); //handle inputs rapidjson::Value inputs; inputs.SetArray(); for(unsigned int i=0; i<moduleType.numInputs(); ++i){ const ModuleInput* input = moduleType.getInput(i); rapidjson::Value inputValue; inputValue.SetObject(); inputValue.AddMember("name", input->getName().c_str(), document.GetAllocator()); int dimensionality = input->getSignalType().dimensionality; std::stringstream ss; ss << dimensionality << "f"; rapidjson::Value typeValue(ss.str().c_str(), document.GetAllocator()); inputValue.AddMember("type", typeValue, document.GetAllocator()); inputs.PushBack(inputValue, document.GetAllocator()); } moduleTypeValue.AddMember("inputs", inputs, document.GetAllocator()); //handle outputs rapidjson::Value outputs; outputs.SetArray(); for(unsigned int i=0; i<moduleType.numOutputs(); ++i){ const ModuleOutput* output = moduleType.getOutput(i); const Module* outputsModule = moduleType.getGraph()->getModule("outputs"); rapidjson::Value outputValue; outputValue.SetObject(); outputValue.AddMember("name", output->getName().c_str(), document.GetAllocator()); auto inputLink = outputsModule->getInput(i); auto outputLink = outputsModule->getInput(i)->getOutputLink(); if(outputLink!=nullptr){ std::string sourceString = outputLink->getOwner().getName() + "." + outputLink->getModuleOutput().getName(); rapidjson::Value sourceStringValue(sourceString.c_str(),document.GetAllocator()); outputValue.AddMember("source", sourceStringValue, document.GetAllocator()); } else { rapidjson::Value vectorValue; vectorValue.SetArray(); auto unlinkedValue = inputLink->getUnlinkedValue(); for(int j=0; j<unlinkedValue.getSignalType().dimensionality; ++j){ vectorValue.PushBack(unlinkedValue[j], document.GetAllocator()); } outputValue.AddMember("source", vectorValue, document.GetAllocator()); } outputs.PushBack(outputValue, document.GetAllocator()); } moduleTypeValue.AddMember("outputs", outputs, document.GetAllocator()); //handle internal modules rapidjson::Value modulesValue; modulesValue.SetArray(); auto graph = moduleType.getGraph(); graph->traverseModulesTopological([&](const Module& module){ //skip input/output modules if(module.getType().isGraphInput() || module.getType().isGraphOutput())return; rapidjson::Value moduleValue; jsonifyModule(module, moduleValue, document); modulesValue.PushBack(moduleValue, document.GetAllocator()); }); moduleTypeValue.AddMember("modules", modulesValue, document.GetAllocator()); }
Type* PrimitiveTypeExpression::type() { return new PrimitiveType(typeValue(), false); }
int main (int argc, char **argv) { int idx; register char *progname; atexit (cleanup); signal (SIGINT, (void (*)(int))abnormal); progname = getcwd (orgdir, _MAX_PATH - 1); /* keeps the compiler happy */ if (argc == 1) { copyright("ICMAKE Binary Makefile Executor", version, release); progname = program_name(argv[0]); printf ("This program is run as a child process of icmake.\n" "Usage: %s [-t] bimfile\n" "where: -t - option indicating that 'bimfile' must be\n" " removed on exit.\n" " bimfile - binary makefile to execute.\n\n" , progname); return 1; } if (!strcmp(argv[1], "-t")) /* -t option found */ { argv[1] = argv[0]; /* remove the -t argument */ argv++; argc--; bimname = argv[1]; /* define temporary name */ } if (!(infile = fopen (argv [1], READBINARY))) error("cannot open bimfile '%s' to read", argv[1]); headerp = readheader(infile, (size_t)version[0]); /* return array of global vars */ if ((INT16)(nvar = getvar(infile, headerp, &var)) == -1) error("invalid macro file, cannot read variable section"); /* global strings haven't been initialized by the compiler yet, */ /* so that's icm-exec's job */ for (idx = 0; idx < nvar; ++idx) { if (typeValue(var + idx) == e_str) var[idx] = *stringConstructor(); } fseek(infile, headerp->offset[3], SEEK_SET); { LISTVAR_ env = *listConstructor(); environ2list(&env); push(&env); /* envp: 3rd arg of main() */ listDestructor(&env); } { LISTVAR_ args = *listConstructor_s_cPP((size_t)argc, argv); push(&args); /* argv: 2nd arg of main() */ listDestructor(&args); } { INTVAR_ nArgs = *intConstructor_i(argc - 1); push(&nArgs); /* argc: 1st arg of main() */ } process(); return retval; }