1 //===- FrontendOptions.cpp ------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "flang/Frontend/FrontendOptions.h" 10 #include "flang/Evaluate/expression.h" 11 12 using namespace Fortran::frontend; 13 14 bool Fortran::frontend::isFixedFormSuffix(llvm::StringRef suffix) { 15 // Note: Keep this list in-sync with flang/test/lit.cfg.py 16 return suffix == "f" || suffix == "F" || suffix == "ff" || suffix == "for" || 17 suffix == "FOR" || suffix == "fpp" || suffix == "FPP"; 18 } 19 20 bool Fortran::frontend::isFreeFormSuffix(llvm::StringRef suffix) { 21 // Note: Keep this list in-sync with flang/test/lit.cfg.py 22 // TODO: Add Cuda Fortan files (i.e. `*.cuf` and `*.CUF`). 23 return suffix == "f77" || suffix == "f90" || suffix == "F90" || 24 suffix == "ff90" || suffix == "f95" || suffix == "F95" || 25 suffix == "ff95" || suffix == "f03" || suffix == "F03" || 26 suffix == "f08" || suffix == "F08" || suffix == "f18" || suffix == "F18"; 27 } 28 29 // TODO: This is a copy of `asFortran` from f18.cpp and is added here for 30 // compatiblity. It doesn't really belong here, but I couldn't find a better 31 // place. We should decide whether to add it to the Evaluate or Parse/Unparse 32 // APIs or some dedicated utility library in the driver. 33 Fortran::parser::AnalyzedObjectsAsFortran 34 Fortran::frontend::getBasicAsFortran() { 35 return Fortran::parser::AnalyzedObjectsAsFortran{ 36 [](llvm::raw_ostream &o, const Fortran::evaluate::GenericExprWrapper &x) { 37 if (x.v) { 38 x.v->AsFortran(o); 39 } else { 40 o << "(bad expression)"; 41 } 42 }, 43 [](llvm::raw_ostream &o, 44 const Fortran::evaluate::GenericAssignmentWrapper &x) { 45 if (x.v) { 46 x.v->AsFortran(o); 47 } else { 48 o << "(bad assignment)"; 49 } 50 }, 51 [](llvm::raw_ostream &o, const Fortran::evaluate::ProcedureRef &x) { 52 x.AsFortran(o << "CALL "); 53 }, 54 }; 55 } 56 57 InputKind FrontendOptions::GetInputKindForExtension(llvm::StringRef extension) { 58 if (isFixedFormSuffix(extension) || isFreeFormSuffix(extension)) { 59 return Language::Fortran; 60 } 61 return Language::Unknown; 62 } 63