int main (int argc, char* argv[]) { /**************************************************************** 1 - process command line *****************************************************************/ process_cmdline(argc, argv); if (gHelpSwitch) { printhelp(); exit(0); } if (gVersionSwitch) { printversion(); exit(0); } initFaustDirectories(); alarm(gTimeout); /**************************************************************** 2 - parse source files *****************************************************************/ startTiming("parser"); list<string>::iterator s; gResult2 = nil; yyerr = 0; if (gInputFiles.begin() == gInputFiles.end()) { exit(1); } for (s = gInputFiles.begin(); s != gInputFiles.end(); s++) { if (s == gInputFiles.begin()) { gMasterDocument = *s; } gResult2 = cons(importFile(tree(s->c_str())), gResult2); } if (yyerr > 0) { cerr << "ERROR : paorsing count = " << yyerr << endl; exit(1); } gExpandedDefList = gReader.expandlist(gResult2); endTiming("parser"); /**************************************************************** 3 - evaluate 'process' definition *****************************************************************/ startTiming("evaluation"); Tree process = evalprocess(gExpandedDefList); if (gErrorCount > 0) { // cerr << "Total of " << gErrorCount << " errors during evaluation of : process = " << boxpp(process) << ";\n"; cerr << "Total of " << gErrorCount << " errors during the compilation of " << gMasterDocument << ";\n"; exit(1); } if (gDetailsSwitch) { cerr << "process = " << boxpp(process) << ";\n"; } if (gDrawPSSwitch || gDrawSVGSwitch) { string projname = makeDrawPathNoExt(); if (gDrawPSSwitch) { drawSchema( process, subst("$0-ps", projname).c_str(), "ps" ); } if (gDrawSVGSwitch) { drawSchema( process, subst("$0-svg", projname).c_str(), "svg" ); } } int numInputs, numOutputs; if (!getBoxType(process, &numInputs, &numOutputs)) { cerr << "ERROR during the evaluation of process : " << boxpp(process) << endl; exit(1); } if (gDetailsSwitch) { cerr <<"process has " << numInputs <<" inputs, and " << numOutputs <<" outputs" << endl; } endTiming("evaluation"); if (gExportDSP) { ofstream xout(subst("$0_exp.dsp", makeDrawPathNoExt()).c_str()); xout << "process = " << boxpp(process) << ";" << endl; return 0; } /**************************************************************** 3.5 - output file list is needed *****************************************************************/ if (gPrintFileListSwitch) { cout << "******* "; // print the pathnames of the files used to evaluate process vector<string> pathnames = gReader.listSrcFiles(); for (unsigned int i=0; i< pathnames.size(); i++) cout << pathnames[i] << ' '; cout << endl; } /**************************************************************** 4 - compute output signals of 'process' *****************************************************************/ startTiming("propagation"); Tree lsignals = boxPropagateSig(nil, process , makeSigInputList(numInputs) ); if (gDetailsSwitch) { cerr << "output signals are : " << endl; printSignal(lsignals, stderr); } endTiming("propagation"); /**************************************************************** 5 - translate output signals into C++ code *****************************************************************/ startTiming("compilation"); Compiler* C; if (gSchedulerSwitch) C = new SchedulerCompiler(gClassName, "dsp", numInputs, numOutputs); else if (gVectorSwitch) C = new VectorCompiler(gClassName, "dsp", numInputs, numOutputs); else C = new ScalarCompiler(gClassName, "dsp", numInputs, numOutputs); if (gPrintXMLSwitch) C->setDescription(new Description()); if (gPrintDocSwitch) C->setDescription(new Description()); C->compileMultiSignal(lsignals); endTiming("compilation"); /**************************************************************** 6 - generate XML description (if required) *****************************************************************/ if (gPrintXMLSwitch) { Description* D = C->getDescription(); assert(D); ofstream xout(subst("$0.xml", makeDrawPath()).c_str()); if(gMetaDataSet.count(tree("name"))>0) D->name(tree2str(*(gMetaDataSet[tree("name")].begin()))); if(gMetaDataSet.count(tree("author"))>0) D->author(tree2str(*(gMetaDataSet[tree("author")].begin()))); if(gMetaDataSet.count(tree("copyright"))>0) D->copyright(tree2str(*(gMetaDataSet[tree("copyright")].begin()))); if(gMetaDataSet.count(tree("license"))>0) D->license(tree2str(*(gMetaDataSet[tree("license")].begin()))); if(gMetaDataSet.count(tree("version"))>0) D->version(tree2str(*(gMetaDataSet[tree("version")].begin()))); D->className(gClassName); D->inputs(C->getClass()->inputs()); D->outputs(C->getClass()->outputs()); D->print(0, xout); } /**************************************************************** 7 - generate documentation from Faust comments (if required) *****************************************************************/ if (gPrintDocSwitch) { if (gLatexDocSwitch) { printDoc(subst("$0-mdoc", makeDrawPathNoExt()).c_str(), "tex", FAUSTVERSION); } } /**************************************************************** 8 - generate output file *****************************************************************/ ostream* dst; istream* enrobage; //istream* intrinsic; if (gOutputFile != "") { string outpath = (gOutputDir != "") ? (gOutputDir + "/" + gOutputFile) : gOutputFile; dst = new ofstream(outpath.c_str()); } else { dst = &cout; } if (gArchFile != "") { if ( (enrobage = open_arch_stream(gArchFile.c_str())) ) { printheader(*dst); C->getClass()->printLibrary(*dst); C->getClass()->printIncludeFile(*dst); C->getClass()->printAdditionalCode(*dst); streamCopyUntil(*enrobage, *dst, "<<includeIntrinsic>>"); // if ( gVectorSwitch && (intrinsic = open_arch_stream("intrinsic.hh")) ) { // streamCopyUntilEnd(*intrinsic, *dst); // } if (gSchedulerSwitch) { istream* scheduler_include = open_arch_stream("scheduler.cpp"); if (scheduler_include) { streamCopy(*scheduler_include, *dst); } else { cerr << "ERROR : can't include \"scheduler.cpp\", file not found" << endl; exit(1); } } streamCopyUntil(*enrobage, *dst, "<<includeclass>>"); printfloatdef(*dst); C->getClass()->println(0,*dst); streamCopyUntilEnd(*enrobage, *dst); } else { cerr << "ERROR : can't open architecture file " << gArchFile << endl; return 1; } } else { printheader(*dst); printfloatdef(*dst); C->getClass()->printLibrary(*dst); C->getClass()->printIncludeFile(*dst); C->getClass()->printAdditionalCode(*dst); C->getClass()->println(0,*dst); } /**************************************************************** 9 - generate the task graph file in dot format *****************************************************************/ if (gGraphSwitch) { ofstream dotfile(subst("$0.dot", makeDrawPath()).c_str()); C->getClass()->printGraphDotFormat(dotfile); } delete C; return 0; }