SourceFile LexSource(const char* file) { (void)IsEscapeSequence; SourceFile result; result.file = file; result.source = FileToString(file); //std::cout << file << '\n' << _sourceCode << '\n'; SourceReader reader; reader.source = result.source.data(); reader.index = 0; reader.length = (int)result.source.size(); reader.position = {1, 1}; while (reader.Read() && reader.errorMessage.empty()) { switch (reader.lastSourceToken.tokenType) { case TokenType::StringLiteral: reader.lastSourceToken.tokenIndex = result.strings.size(); result.strings.push_back(reader.buffer); break; case TokenType::CodePointLiteral: case TokenType::Float32Literal: case TokenType::Float64Literal: case TokenType::SignedIntegerLiteral: case TokenType::UnsignedIntegerLiteral: reader.lastSourceToken.tokenIndex = result.literals.size(); result.literals.push_back(reader.literal); break; default: break; } result.sourceTokens.push_back(reader.lastSourceToken); } SourceToken finalToken = {}; finalToken.tokenType = TokenType::None; result.sourceTokens.push_back(finalToken); if (!reader.errorMessage.empty()) { std::cout << reader.errorPosition << " error - " << reader.errorMessage << '\n'; } return result; }
/** * @brief Declare an automatic documentation. * * This function simulates a default documentation : * if no <mdoc> tag was found in the input faust file, * and yet the '-mdoc' option was called, * then print a complete 'process' doc. */ void declareAutoDoc() { Tree autodoc = nil; Tree process = boxIdent("process"); /** Autodoc's "head", with title, author, date, and metadatas. */ /** The latex title macro is bound to the metadata "name" if it exists, (corresponding to "declare name") or else just to the file name. */ autodoc = cons(docTxt("\\title{"), autodoc); if (gMetaDataSet.count(tree("name"))) { autodoc = cons(docMtd(tree("name")), autodoc); } else { autodoc = cons(docTxt(gDocName.c_str()), autodoc); } autodoc = cons(docTxt("}\n"), autodoc); /** The latex author macro is bound to the metadata "author" if it exists, (corresponding to "declare author") or else no author item is printed. */ if (gMetaDataSet.count(tree("author"))) { autodoc = cons(docTxt("\\author{"), autodoc); autodoc = cons(docMtd(tree("author")), autodoc); autodoc = cons(docTxt("}\n"), autodoc); } /** The latex date macro is bound to the metadata "date" if it exists, (corresponding to "declare date") or else to the today latex macro. */ autodoc = cons(docTxt("\\date{"), autodoc); if (gMetaDataSet.count(tree("date"))) { autodoc = cons(docMtd(tree("date")), autodoc); } else { autodoc = cons(docTxt("\\today"), autodoc); } autodoc = cons(docTxt("}\n"), autodoc); /** The latex maketitle macro. */ autodoc = cons(docTxt("\\maketitle\n"), autodoc); /** Insert all declared metadatas in a latex tabular environment. */ if (! gMetaDataSet.empty()) { autodoc = cons(docTxt("\\begin{tabular}{ll}\n"), autodoc); autodoc = cons(docTxt("\t\\hline\n"), autodoc); for (map<Tree, set<Tree> >::iterator i = gMetaDataSet.begin(); i != gMetaDataSet.end(); i++) { string mtdkey = tree2str(i->first); string mtdTranslatedKey = gDocMetadatasStringMap[mtdkey]; if (mtdTranslatedKey.empty()) { mtdTranslatedKey = mtdkey; } autodoc = cons(docTxt("\t\\textbf{"), autodoc); autodoc = cons(docTxt(mtdTranslatedKey.c_str()), autodoc); autodoc = cons(docTxt("} & "), autodoc); autodoc = cons(docMtd(tree(mtdkey.c_str())), autodoc); autodoc = cons(docTxt(" \\\\\n"), autodoc); } autodoc = cons(docTxt("\t\\hline\n"), autodoc); autodoc = cons(docTxt("\\end{tabular}\n"), autodoc); autodoc = cons(docTxt("\\bigskip\n"), autodoc); } /** Autodoc's "body", with equation and diagram of process, and notice and listing. */ string autoPresentationTxt = "\n\\bigskip\n" + gDocAutodocStringMap["thisdoc"] + "\n\n"; autodoc = cons(docTxt(autoPresentationTxt.c_str()), autodoc); string autoEquationTxt = "\n" + gDocAutodocStringMap["autoeqntitle"] + "\n\n"; autoEquationTxt += gDocAutodocStringMap["autoeqntext"] + "\n"; autodoc = cons(docTxt(autoEquationTxt.c_str()), autodoc); autodoc = cons(docEqn(process), autodoc); string autoDiagramTxt = "\n" + gDocAutodocStringMap["autodgmtitle"] + "\n\n"; autoDiagramTxt += gDocAutodocStringMap["autodgmtext"] + "\n"; autodoc = cons(docTxt(autoDiagramTxt.c_str()), autodoc); autodoc = cons(docDgm(process), autodoc); string autoNoticeTxt = "\n" + gDocAutodocStringMap["autontctitle"] + "\n\n"; // autoNoticeTxt += gDocAutodocStringMap["autontctext"] + "\n"; autodoc = cons(docTxt(autoNoticeTxt.c_str()), autodoc); autodoc = cons(docNtc(), autodoc); string autoListingTxt; vector<string> pathnames = gReader.listSrcFiles(); if(pathnames.size() > 1) { autoListingTxt = "\n" + gDocAutodocStringMap["autolsttitle2"] + "\n\n"; autoListingTxt += gDocAutodocStringMap["autolsttext2"] + "\n"; } else { autoListingTxt = "\n" + gDocAutodocStringMap["autolsttitle1"] + "\n\n"; autoListingTxt += gDocAutodocStringMap["autolsttext1"] + "\n"; } autodoc = cons(docTxt(autoListingTxt.c_str()), autodoc); autodoc = cons(docLst(), autodoc); declareDoc(autodoc); }
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; }