├── .gitignore ├── CMakeLists.txt ├── LICENSE.TXT ├── README.txt ├── include ├── CMakeLists.txt └── flang │ ├── AST │ ├── ASTConsumer.h │ ├── ASTContext.h │ ├── BuiltinTypeKinds.def │ ├── CMakeLists.txt │ ├── Decl.h │ ├── DeclContextInternals.h │ ├── DeclGroup.h │ ├── DeclVisitor.h │ ├── DeclarationName.h │ ├── Expr.h │ ├── ExprConstant.h │ ├── ExprVisitor.h │ ├── FormatItem.h │ ├── FormatSpec.h │ ├── IOSpec.h │ ├── IntrinsicFunctions.def │ ├── IntrinsicFunctions.h │ ├── Rename.h │ ├── Stmt.h │ ├── StmtVisitor.h │ ├── StorageSet.h │ ├── Type.h │ ├── TypeNodes.def │ └── TypeVisitor.h │ ├── Basic │ ├── AllDiagnostics.h │ ├── CMakeLists.txt │ ├── CharInfo.h │ ├── DeclNodes.td │ ├── Diagnostic.h │ ├── Diagnostic.td │ ├── DiagnosticCommonKinds.td │ ├── DiagnosticFrontendKinds.td │ ├── DiagnosticGroups.td │ ├── DiagnosticIDs.h │ ├── DiagnosticLexKinds.td │ ├── DiagnosticParseKinds.td │ ├── DiagnosticSemaKinds.td │ ├── ExprNodes.td │ ├── IdentifierTable.h │ ├── LLVM.h │ ├── LangOptions.h │ ├── MacroBuilder.h │ ├── MakePtr.h │ ├── SourceLocation.h │ ├── Specifiers.h │ ├── StmtNodes.td │ ├── TargetInfo.h │ ├── TargetOptions.h │ ├── Token.h │ ├── TokenKinds.def │ ├── TokenKinds.h │ ├── Version.h │ ├── Version.inc.in │ └── VersionTuple.h │ ├── CMakeLists.txt │ ├── CodeGen │ ├── BackendUtil.h │ ├── CodeGenAction.h │ └── ModuleBuilder.h │ ├── Config │ └── config.h.cmake │ ├── Frontend │ ├── ASTConsumers.h │ ├── ASTUnit.h │ ├── CodeGenOptions.def │ ├── CodeGenOptions.h │ ├── CommandLineSourceLoc.h │ ├── CompilerInstance.h │ ├── CompilerInvocation.h │ ├── FrontendAction.h │ ├── FrontendDiagnostic.h │ ├── FrontendOptions.h │ ├── TextDiagnosticBuffer.h │ ├── TextDiagnosticPrinter.h │ └── VerifyDiagnosticConsumer.h │ ├── Parse │ ├── FixedForm.h │ ├── LexDiagnostic.h │ ├── Lexer.h │ ├── ParseDiagnostic.h │ └── Parser.h │ └── Sema │ ├── DeclSpec.h │ ├── Ownership.h │ ├── Scope.h │ ├── Sema.h │ ├── SemaDiagnostic.h │ └── SemaInternal.h ├── lib ├── AST │ ├── ASTContext.cpp │ ├── ASTDumper.cpp │ ├── CMakeLists.txt │ ├── Decl.cpp │ ├── DeclGroup.cpp │ ├── DeclarationName.cpp │ ├── Expr.cpp │ ├── ExprArray.cpp │ ├── ExprConstant.cpp │ ├── FormatItem.cpp │ ├── FormatSpec.cpp │ ├── IOSpec.cpp │ ├── IntrinsicFunctions.cpp │ ├── Stmt.cpp │ └── Type.cpp ├── Basic │ ├── CMakeLists.txt │ ├── CharInfo.cpp │ ├── Diagnostic.cpp │ ├── DiagnosticIDs.cpp │ ├── IdentifierTable.cpp │ ├── TargetInfo.cpp │ ├── Targets.cpp │ ├── Token.cpp │ ├── TokenKinds.cpp │ └── Version.cpp ├── CMakeLists.txt ├── CodeGen │ ├── ABIInfo.h │ ├── BackendUtil.cpp │ ├── CGABI.cpp │ ├── CGABI.h │ ├── CGArray.cpp │ ├── CGArray.h │ ├── CGArrayIntrinsic.cpp │ ├── CGBuilder.h │ ├── CGCall.cpp │ ├── CGCall.h │ ├── CGDecl.cpp │ ├── CGExpr.cpp │ ├── CGExprAgg.cpp │ ├── CGExprCharacter.cpp │ ├── CGExprComplex.cpp │ ├── CGExprScalar.cpp │ ├── CGIOLibflang.cpp │ ├── CGIORuntime.cpp │ ├── CGIORuntime.h │ ├── CGIntrinsic.cpp │ ├── CGStmt.cpp │ ├── CGSystemLibflang.cpp │ ├── CGSystemRuntime.cpp │ ├── CGSystemRuntime.h │ ├── CGValue.h │ ├── CMakeLists.txt │ ├── CodeGenAction.cpp │ ├── CodeGenFunction.cpp │ ├── CodeGenFunction.h │ ├── CodeGenModule.cpp │ ├── CodeGenModule.h │ ├── CodeGenTypes.cpp │ ├── CodeGenTypes.h │ ├── ModuleBuilder.cpp │ ├── TargetInfo.cpp │ └── TargetInfo.h ├── Frontend │ ├── ASTConsumers.cpp │ ├── CMakeLists.txt │ ├── TextDiagnosticBuffer.cpp │ ├── TextDiagnosticPrinter.cpp │ └── VerifyDiagnosticConsumer.cpp ├── Parse │ ├── CMakeLists.txt │ ├── FixedForm.cpp │ ├── Lexer.cpp │ ├── ParseDecl.cpp │ ├── ParseExec.cpp │ ├── ParseExpr.cpp │ ├── ParseFormat.cpp │ ├── ParseSpecStmt.cpp │ └── Parser.cpp └── Sema │ ├── CMakeLists.txt │ ├── DeclSpec.cpp │ ├── Scope.cpp │ ├── Sema.cpp │ ├── SemaArrayExpr.cpp │ ├── SemaChecking.cpp │ ├── SemaDataStmt.cpp │ ├── SemaDecl.cpp │ ├── SemaEquivalence.cpp │ ├── SemaExecStmt.cpp │ ├── SemaExpr.cpp │ ├── SemaFormat.cpp │ ├── SemaIO.cpp │ ├── SemaIntrinsic.cpp │ └── Spec.cpp ├── test ├── CMakeLists.txt ├── CodeGen │ ├── Intrinsics │ │ ├── bitops.f95 │ │ ├── inquiry.f95 │ │ └── maxminloc.f95 │ ├── array.f95 │ ├── array.o │ ├── arrayArgument.f95 │ ├── arrayAssignment.f95 │ ├── arrayConstructor.f95 │ ├── arrayOperations.f95 │ ├── arrayTempAndPacking.f95 │ ├── callableArguments.f95 │ ├── character.f95 │ ├── characterIntrinsic.f95 │ ├── common.f95 │ ├── complexArithmetic.f95 │ ├── complexIntrinsic.f95 │ ├── complexIntrinsicMath.f95 │ ├── computedGoto.f95 │ ├── core.f95 │ ├── data.f95 │ ├── defaultDouble8.f95 │ ├── defaultInt8.f95 │ ├── defaultReal8.f95 │ ├── do.f95 │ ├── dowhile.f95 │ ├── equivalence.f95 │ ├── exitCycle.f95 │ ├── goto.f95 │ ├── if.f95 │ ├── implicitConversion.f95 │ ├── intrinsicConversion.f95 │ ├── mainProgram.f95 │ ├── save.f95 │ ├── scalarArithmetic.f95 │ ├── scalarIntrinsicMath.f95 │ ├── scalarIntrinsicTruncRound.f95 │ ├── scalarLogical.f95 │ ├── selectcase.f95 │ ├── statementFunctions.f95 │ ├── subprogram.f95 │ ├── systemIntrinsics.f95 │ ├── type.f95 │ ├── unformattedWrite.f95 │ ├── valueAssignment.f95 │ ├── where.f95 │ ├── x86LinuxAggregateABI.f95 │ └── x86_64LinuxAggregateABI.f95 ├── Lexer │ ├── constants.f95 │ ├── continuation.f95 │ ├── definedOperator.f95 │ ├── fixedForm.f │ ├── fixedForm2.f │ ├── fixedFormDefinedOperators.f │ ├── fixedFormSquash.f │ ├── fixedFormString.f │ ├── include.f95 │ ├── includeFail.f95 │ ├── includedFile.inc │ ├── numberConstants.f95 │ └── torture.f95 ├── Parser │ ├── array.f95 │ ├── arrayConstructor.f95 │ ├── assignedGoto.f │ ├── assignedGoto.f95 │ ├── assignedGotoImplicitDecl.f95 │ ├── call.f95 │ ├── characterSubstring.f95 │ ├── common.f95 │ ├── complexConstants.f95 │ ├── computedGoto.f95 │ ├── continue.f95 │ ├── data.f95 │ ├── dimension.f95 │ ├── do.f95 │ ├── doImplicitDecl.f95 │ ├── doRecovery.f95 │ ├── double.f95 │ ├── empty.f95 │ ├── end.f │ ├── equivalence.f95 │ ├── exitCycle.f95 │ ├── expressions.f95 │ ├── external.f95 │ ├── fixedForm.f95 │ ├── fixedFormDo.f │ ├── fixedFormExitCycle.f │ ├── fixedFormFunction.f │ ├── fixedFormLength.f │ ├── fixedFormNamedConstructs.f │ ├── fixedif.f │ ├── format.f95 │ ├── freeForm.f │ ├── freeFormLength.f95 │ ├── goto.f95 │ ├── hello_world.f95 │ ├── if.f95 │ ├── ifRecovery.f95 │ ├── implicit.f95 │ ├── implicitFunctions.f95 │ ├── implicitNone.f95 │ ├── intrinsic.f95 │ ├── minimal.f95 │ ├── minimalAmbiguous.f95 │ ├── namedConstructs.f95 │ ├── parameter.f95 │ ├── program.f95 │ ├── readWritePrint.f95 │ ├── recursive.f │ ├── recursive.f95 │ ├── result.f │ ├── result.f95 │ ├── return.f95 │ ├── save.f │ ├── save.f95 │ ├── selectcase.f95 │ ├── statementFunctions.f95 │ ├── statementTermination.f95 │ ├── stop.f95 │ ├── subprogram.f │ ├── subprogram.f95 │ ├── type.f95 │ ├── variables.f95 │ └── where.f95 ├── Sema │ ├── Intrinsics │ │ ├── bitops.f95 │ │ ├── etime.f95 │ │ ├── inquiry.f95 │ │ └── numericInquiry.f95 │ ├── arithmeticExpressions.f95 │ ├── arrayAssignment.f95 │ ├── arrayConstructor.f95 │ ├── arrayIntrinsics.f95 │ ├── arrayOperations.f95 │ ├── arraySections.f95 │ ├── arraySpec.f95 │ ├── arraySubscript.f95 │ ├── assignedGoto.f95 │ ├── assignment.f95 │ ├── beginEndRecovery.f95 │ ├── call.f95 │ ├── callableArguments.f95 │ ├── characterExpressions.f95 │ ├── characterSpec.f95 │ ├── characterSubstring.f95 │ ├── common.f95 │ ├── computedGoto.f95 │ ├── data.f95 │ ├── declarationAttributes.f95 │ ├── dimension.f95 │ ├── do.f95 │ ├── double.f95 │ ├── dowhile.f95 │ ├── equivalence.f95 │ ├── exitCycle.f95 │ ├── external.f95 │ ├── format.f95 │ ├── formatSpecifiers.f95 │ ├── goto.f95 │ ├── if.f95 │ ├── immutableDoVars.f95 │ ├── implicit.f95 │ ├── implicitArgumentInArraySpec.f95 │ ├── implicitDefault.f95 │ ├── implicitNone.f95 │ ├── intrinsic.f95 │ ├── intrinsicArrayOperations.f95 │ ├── intrinsicFunctions.f95 │ ├── logicalExpressions.f95 │ ├── mainProgram.f95 │ ├── namedConstructs.f95 │ ├── parameter.f95 │ ├── readWritePrint.f95 │ ├── recursive.f95 │ ├── relationalExpressions.f95 │ ├── result.f95 │ ├── return.f95 │ ├── returnVarDo.f95 │ ├── save.f95 │ ├── selectcase.f95 │ ├── statementFunctions.f95 │ ├── subprogram.f95 │ ├── type.f95 │ ├── typeKinds.f95 │ ├── variables.f95 │ └── where.f95 ├── TestRunner.sh.in ├── lit.cfg └── lit.site.cfg.in ├── tools ├── CMakeLists.txt └── driver │ ├── CMakeLists.txt │ ├── Info.plist.in │ └── Main.cpp ├── unittests ├── AST │ ├── CMakeLists.txt │ └── ExprEvaluator.cpp └── CMakeLists.txt └── utils └── TableGen ├── CMakeLists.txt ├── FlangASTNodesEmitter.cpp ├── FlangDiagnosticsEmitter.cpp ├── TableGen.cpp └── TableGenBackends.h /.gitignore: -------------------------------------------------------------------------------- 1 | #==============================================================================# 2 | # This file specifies intentionally untracked files that git should ignore. 3 | # See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html 4 | # 5 | # This file is intentionally different from the output of `git svn show-ignore`, 6 | # as most of those are useless. 7 | #==============================================================================# 8 | 9 | #==============================================================================# 10 | # File extensions to be ignored anywhere in the tree. 11 | #==============================================================================# 12 | # Temp files created by most text editors. 13 | *~ 14 | # Merge files created by git. 15 | *.orig 16 | # Byte compiled python modules. 17 | *.pyc 18 | # vim swap files 19 | .*.swp 20 | 21 | #==============================================================================# 22 | # Explicit files to ignore (only matches one). 23 | #==============================================================================# 24 | cscope.files 25 | cscope.out 26 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(flang) 2 | -------------------------------------------------------------------------------- /include/flang/AST/ASTConsumer.h: -------------------------------------------------------------------------------- 1 | //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the ASTConsumer class. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_FLANG_AST_ASTCONSUMER_H 15 | #define LLVM_FLANG_AST_ASTCONSUMER_H 16 | 17 | namespace flang { 18 | class ASTContext; 19 | class FunctionDecl; 20 | 21 | /// ASTConsumer - This is an abstract interface that should be implemented by 22 | /// clients that read ASTs. This abstraction layer allows the client to be 23 | /// independent of the AST producer (e.g. parser vs AST dump file reader, etc). 24 | class ASTConsumer { 25 | public: 26 | ASTConsumer() { } 27 | 28 | virtual ~ASTConsumer() {} 29 | 30 | /// Initialize - This is called to initialize the consumer, providing the 31 | /// ASTContext. 32 | virtual void Initialize(ASTContext &Context) {} 33 | 34 | /// HandleTranslationUnit - This method is called when the ASTs for entire 35 | /// translation unit have been parsed. 36 | virtual void HandleTranslationUnit(ASTContext &Ctx) {} 37 | 38 | /// PrintStats - If desired, print any statistics. 39 | virtual void PrintStats() {} 40 | }; 41 | 42 | } // end namespace flang. 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/flang/AST/BuiltinTypeKinds.def: -------------------------------------------------------------------------------- 1 | //===-- BuiltinTypeKinds.def - Metadata about BuiltinType kinds -*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef INTEGER_KIND 11 | #define INTEGER_KIND(NAME, VALUE) 12 | #endif 13 | 14 | #ifndef FLOATING_POINT_KIND 15 | #define FLOATING_POINT_KIND(NAME, VALUE) 16 | #endif 17 | 18 | INTEGER_KIND(Int1, 1) 19 | INTEGER_KIND(Int2, 2) 20 | INTEGER_KIND(Int4, 4) 21 | INTEGER_KIND(Int8, 8) 22 | 23 | FLOATING_POINT_KIND(Real4, 4) 24 | FLOATING_POINT_KIND(Real8, 8) 25 | FLOATING_POINT_KIND(Real16, 16) 26 | 27 | #undef FLOATING_POINT_KIND 28 | #undef INTEGER_KIND 29 | -------------------------------------------------------------------------------- /include/flang/AST/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | flang_tablegen(DeclNodes.inc -gen-flang-decl-nodes 2 | SOURCE ../Basic/DeclNodes.td 3 | TARGET FlangDeclNodes) 4 | 5 | flang_tablegen(StmtNodes.inc -gen-flang-stmt-nodes 6 | SOURCE ../Basic/StmtNodes.td 7 | TARGET FlangStmtNodes) 8 | 9 | flang_tablegen(ExprNodes.inc -gen-flang-expr-nodes 10 | SOURCE ../Basic/ExprNodes.td 11 | TARGET FlangExprNodes) 12 | -------------------------------------------------------------------------------- /include/flang/AST/ExprConstant.h: -------------------------------------------------------------------------------- 1 | //===--- ExprConstant.h - Expression Constant Evaluator -------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef FLANG_AST_EXPR_CONSTANT_H 11 | #define FLANG_AST_EXPR_CONSTANT_H 12 | 13 | #include "flang/Basic/LLVM.h" 14 | #include "llvm/ADT/DenseMap.h" 15 | 16 | namespace flang { 17 | 18 | class Expr; 19 | class VarDecl; 20 | class ASTContext; 21 | 22 | /// ExprEvalScope - represents a scope which can be used 23 | /// to associate variables with values when evaluating expressions. 24 | class ExprEvalScope { 25 | llvm::SmallDenseMap InlinedVars; 26 | ASTContext &Context; 27 | public: 28 | 29 | ExprEvalScope(ASTContext &C); 30 | 31 | std::pair get(const Expr *E) const; 32 | void Assign(const VarDecl *Var, int64_t Value); 33 | }; 34 | 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/flang/AST/IntrinsicFunctions.h: -------------------------------------------------------------------------------- 1 | //===----- IntrinsicFunctions.h - enum values for intrinsic functions -----===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the FunctionKind enum and support functions. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef FLANG_AST_INTRINSICFUNCTIONS_H__ 15 | #define FLANG_AST_INTRINSICFUNCTIONS_H__ 16 | 17 | #include "flang/Basic/IdentifierTable.h" 18 | #include "flang/Basic/LangOptions.h" 19 | #include "llvm/ADT/StringMap.h" 20 | 21 | namespace flang { 22 | namespace intrinsic { 23 | 24 | enum FunctionArgumentCountKind { 25 | ArgumentCount1, 26 | ArgumentCount2, 27 | ArgumentCount3, 28 | ArgumentCount1or2, 29 | ArgumentCount2orMore 30 | }; 31 | 32 | /// FunctionKind - This provides a simple uniform namespace for 33 | /// intrinsic functions from all Fortran languages. 34 | enum FunctionKind { 35 | #define INTRINSIC_FUNCTION(NAME, GENERICNAME, NUMARGS, VERSION) NAME, 36 | #include "IntrinsicFunctions.def" 37 | NUM_FUNCTIONS 38 | }; 39 | 40 | /// Group - the list of function groups. 41 | enum Group { 42 | GROUP_NONE, 43 | #define INTRINSIC_GROUP(NAME, FIRST, LAST) GROUP_ ## NAME, 44 | #include "IntrinsicFunctions.def" 45 | NUM_GROUPS 46 | }; 47 | 48 | /// \brief Returns the id of the generic function of this overload. 49 | FunctionKind getGenericFunctionKind(FunctionKind Function); 50 | 51 | /// \brief Returns the id of the group that this function belongs to. 52 | Group getFunctionGroup(FunctionKind Function); 53 | 54 | /// \brief Returns the name of the function. 55 | const char *getFunctionName(FunctionKind Kind); 56 | 57 | /// \brief Returns the number of arguments that the function accepts. 58 | FunctionArgumentCountKind getFunctionArgumentCount(FunctionKind Function); 59 | 60 | /// Maps the intrinsic function identifiers to function IDs 61 | class FunctionMapping { 62 | llvm::StringMap Mapping; 63 | public: 64 | FunctionMapping(const LangOptions &Options); 65 | 66 | struct Result { 67 | FunctionKind Function; 68 | bool IsInvalid; 69 | }; 70 | 71 | Result Resolve(const IdentifierInfo *IDInfo); 72 | }; 73 | 74 | } // end namespace intrinsic 75 | } // end namespace flang 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/flang/AST/Rename.h: -------------------------------------------------------------------------------- 1 | //===-- Rename.h - Renamed Objects ------------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef FLANG_AST_RENAME_H__ 14 | #define FLANG_AST_RENAME_H__ 15 | 16 | #include "llvm/ADT/StringRef.h" 17 | #include "llvm/Support/raw_stream.h" 18 | 19 | namespace flang { 20 | 21 | //===----------------------------------------------------------------------===// 22 | /// Rename - Used in a 'USE' statement to rename a module name to a local name. 23 | /// 24 | class Rename { 25 | llvm::StringRef LocalName; 26 | llvm::StringRef UseName; 27 | public: 28 | Rename(llvm::StringRef LN, llvm::StringRef UN) 29 | : LocalName(LN), UseName(UN) {} 30 | 31 | friend llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const Rename &RN) { 32 | return O << RN.LocalName << " => " << RN.UseName; 33 | } 34 | }; 35 | 36 | } // end flang namespace 37 | 38 | #endif // FLANG_AST_RENAME_H__ 39 | -------------------------------------------------------------------------------- /include/flang/AST/TypeNodes.def: -------------------------------------------------------------------------------- 1 | //===-- TypeNodes.def - Metadata about Type AST nodes -----------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef TYPE 11 | #define TYPE(Name, Parent) 12 | #endif 13 | 14 | #ifndef BUILTIN_TYPE 15 | #define BUILTIN_TYPE(Name) 16 | #endif 17 | 18 | TYPE(Void, Type) 19 | TYPE(Builtin, Type) 20 | BUILTIN_TYPE(Integer) 21 | BUILTIN_TYPE(Real) 22 | BUILTIN_TYPE(Complex) 23 | BUILTIN_TYPE(Logical) 24 | TYPE(Character, Type) 25 | TYPE(Record, Type) 26 | TYPE(Pointer, Type) 27 | TYPE(Array, Type) 28 | TYPE(Function, Type) 29 | 30 | #ifdef LAST_TYPE 31 | LAST_TYPE(Array) 32 | #undef LAST_TYPE 33 | #endif 34 | 35 | #undef BUILTIN_TYPE 36 | #undef TYPE 37 | -------------------------------------------------------------------------------- /include/flang/Basic/AllDiagnostics.h: -------------------------------------------------------------------------------- 1 | //===--- AllDiagnostics.h - Aggregate Diagnostic headers --------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | /// 10 | /// \file 11 | /// \brief Includes all the separate Diagnostic headers & some related helpers. 12 | /// 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef LLVM_FLANG_ALL_DIAGNOSTICS_H 16 | #define LLVM_FLANG_ALL_DIAGNOSTICS_H 17 | 18 | #include "flang/Frontend/FrontendDiagnostic.h" 19 | #include "flang/Parse/LexDiagnostic.h" 20 | #include "flang/Parse/ParseDiagnostic.h" 21 | #include "flang/Sema/SemaDiagnostic.h" 22 | 23 | namespace flang { 24 | template 25 | class StringSizerHelper { 26 | char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1]; 27 | public: 28 | enum { Size = SizeOfStr }; 29 | }; 30 | } // end namespace flang 31 | 32 | #define STR_SIZE(str, fieldTy) flang::StringSizerHelper::Size 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/flang/Basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | macro(flang_diag_gen component) 2 | flang_tablegen(Diagnostic${component}Kinds.inc 3 | -gen-flang-diags-defs -flang-component=${component} 4 | SOURCE Diagnostic.td 5 | TARGET FlangDiagnostic${component}) 6 | endmacro(flang_diag_gen) 7 | 8 | 9 | flang_diag_gen(Common) 10 | flang_diag_gen(Lex) 11 | flang_diag_gen(Parse) 12 | flang_diag_gen(Frontend) 13 | flang_diag_gen(Sema) 14 | flang_tablegen(DiagnosticGroups.inc -gen-flang-diag-groups 15 | SOURCE Diagnostic.td 16 | TARGET FlangDiagnosticGroups) 17 | -------------------------------------------------------------------------------- /include/flang/Basic/DeclNodes.td: -------------------------------------------------------------------------------- 1 | //===-- DeclNodes.td - Declaration Nodes -------------------*- tablegen -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // Fortran declaration nodes. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | class AttrSubject; 15 | 16 | class Decl : AttrSubject { 17 | bit Abstract = abstract; 18 | } 19 | 20 | class DDecl : Decl { 21 | Decl Base = base; 22 | } 23 | 24 | class DeclContext { } 25 | 26 | def TranslationUnit : Decl, DeclContext; 27 | def Named : Decl<1>; 28 | def Type : DDecl; 29 | def Record : DDecl, DeclContext; 30 | def Value : DDecl; 31 | def EnumConstant : DDecl; 32 | def Declarator : DDecl; 33 | def MainProgram : DDecl, DeclContext; 34 | def Function : DDecl, DeclContext; 35 | def IntrinsicFunction : DDecl; 36 | def Module : DDecl, DeclContext; 37 | def Submodule : DDecl, DeclContext; 38 | def Field : DDecl; 39 | def Var : DDecl; 40 | def Self : DDecl; 41 | def CommonBlock : DDecl; 42 | def FileScopeAsm : Decl; 43 | -------------------------------------------------------------------------------- /include/flang/Basic/ExprNodes.td: -------------------------------------------------------------------------------- 1 | class AttrSubject; 2 | 3 | class Expr : AttrSubject { 4 | bit Abstract = abstract; 5 | } 6 | 7 | class DExpr : Expr { 8 | Expr Base = base; 9 | } 10 | 11 | // Constants 12 | def ConstantExpr : Expr; 13 | def IntegerConstantExpr : DExpr; 14 | def RealConstantExpr : DExpr; 15 | def ComplexConstantExpr : DExpr; 16 | def CharacterConstantExpr : DExpr; 17 | def BOZConstantExpr : DExpr; 18 | def LogicalConstantExpr : DExpr; 19 | def RepeatedConstantExpr : Expr; 20 | 21 | def FunctionRefExpr : Expr; 22 | def VarExpr : Expr; 23 | def UnresolvedIdentifierExpr : Expr; 24 | def UnaryExpr : Expr; 25 | def DefinedUnaryOperatorExpr : DExpr; 26 | def ImplicitCastExpr : Expr; 27 | 28 | def BinaryExpr : Expr; 29 | def DefinedBinaryOperatorExpr : DExpr; 30 | 31 | def DesignatorExpr : Expr<1>; 32 | def MemberExpr : DExpr; 33 | def SubstringExpr : DExpr; 34 | def ArrayElementExpr : DExpr; 35 | def ArraySectionExpr : DExpr; 36 | def ImplicitArrayOperationExpr : Expr<1>; 37 | def ImplicitArrayPackExpr : DExpr; 38 | def ImplicitTempArrayExpr : DExpr; 39 | 40 | // Call Expressions 41 | def CallExpr : Expr; 42 | def IntrinsicCallExpr : Expr; 43 | 44 | //Other 45 | def ImpliedDoExpr : Expr; 46 | def ArrayConstructorExpr : Expr; // (/ /) 47 | def TypeConstructorExpr : Expr; 48 | def RangeExpr : Expr; // a : b 49 | def StridedRangeExpr : DExpr; 50 | -------------------------------------------------------------------------------- /include/flang/Basic/LLVM.h: -------------------------------------------------------------------------------- 1 | //===--- LLVM.h - Import various common LLVM datatypes ----------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file forward declares and imports various common LLVM datatypes that 11 | // flang wants to use unqualified. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef FLANG_BASIC_LLVM_H__ 16 | #define FLANG_BASIC_LLVM_H__ 17 | 18 | // This should be the only #include, force #includes of all the others on 19 | // clients. 20 | #include "llvm/Support/Casting.h" 21 | 22 | namespace llvm { 23 | // ADT's. 24 | class APInt; 25 | class APFloat; 26 | class StringRef; 27 | class Twine; 28 | #if 0 29 | template class ArrayRef; 30 | template class SmallVector; 31 | template class SmallVectorImpl; 32 | #endif 33 | template class ArrayRef; 34 | template class SmallString; 35 | template class SmallVector; 36 | template class SmallVectorImpl; 37 | template class Optional; 38 | 39 | class raw_ostream; 40 | class raw_pwrite_stream; 41 | // TODO: DenseMap, ... 42 | } 43 | 44 | 45 | namespace flang { 46 | // Casting operators. 47 | using llvm::isa; 48 | using llvm::cast; 49 | using llvm::dyn_cast; 50 | using llvm::dyn_cast_or_null; 51 | using llvm::cast_or_null; 52 | 53 | // ADT's. 54 | using llvm::APInt; 55 | using llvm::APFloat; 56 | using llvm::StringRef; 57 | using llvm::Twine; 58 | using llvm::ArrayRef; 59 | using llvm::SmallString; 60 | using llvm::SmallVector; 61 | using llvm::SmallVectorImpl; 62 | 63 | using llvm::raw_ostream; 64 | using llvm::raw_pwrite_stream; 65 | } // end namespace flang. 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /include/flang/Basic/LangOptions.h: -------------------------------------------------------------------------------- 1 | //===--- LangOptions.h - Fortran Language Family Language Opts --*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the LangOptions interface. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef FLANG_LANGOPTIONS_H__ 15 | #define FLANG_LANGOPTIONS_H__ 16 | 17 | #include "llvm/ADT/IntrusiveRefCntPtr.h" 18 | #include 19 | 20 | namespace flang { 21 | 22 | /// LangOptions - This class keeps track of the various options that can be 23 | /// enabled, which controls the dialect of Fortran that is accepted. 24 | class LangOptions : public llvm::RefCountedBase { 25 | public: 26 | unsigned Fortran77 : 1; // Fortran 77 27 | unsigned Fortran90 : 1; // Fortran 90 28 | unsigned Fortran95 : 1; // Fortran 95 29 | unsigned Fortran2000 : 1; // Fortran 2000 30 | unsigned Fortran2003 : 1; // Fortran 2003 31 | unsigned Fortran2008 : 1; // Fortran 2008 32 | 33 | unsigned FixedForm : 1; // Fixed-form style 34 | unsigned FreeForm : 1; // Free-form style 35 | 36 | unsigned ReturnComments : 1; // Return comments as lexical tokens 37 | 38 | unsigned SpellChecking : 1; // Whether to perform spell-checking for error 39 | // recovery. 40 | 41 | unsigned DefaultReal8 : 1; // Sets the default real type to be 8 bytes wide 42 | unsigned DefaultDouble8 : 1; // Sets the default double precision type to be 8 bytes wide 43 | unsigned DefaultInt8 : 1; // Sets the default integer type to be 8 bytes wide 44 | unsigned TabWidth; // The tab character is treated as N spaces. 45 | unsigned LineLength; // Maximum allowed line length 46 | 47 | LangOptions() { 48 | Fortran77 = 0; 49 | Fortran90 = Fortran95 = Fortran2000 = Fortran2003 = 1; 50 | FixedForm = 0; 51 | FreeForm = 1; 52 | ReturnComments = 0; 53 | SpellChecking = 1; 54 | DefaultReal8 = DefaultDouble8 = DefaultInt8 = 0; 55 | TabWidth = 6; 56 | LineLength = 132; // Free form 57 | } 58 | }; 59 | 60 | } // end namespace flang 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/flang/Basic/MacroBuilder.h: -------------------------------------------------------------------------------- 1 | //===--- MacroBuilder.h - CPP Macro building utility ------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | /// 10 | /// \file 11 | /// \brief Defines the flang::MacroBuilder utility class. 12 | /// 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef LLVM_FLANG_BASIC_MACROBUILDER_H 16 | #define LLVM_FLANG_BASIC_MACROBUILDER_H 17 | 18 | #include "flang/Basic/LLVM.h" 19 | #include "llvm/ADT/Twine.h" 20 | #include "llvm/Support/raw_ostream.h" 21 | 22 | namespace flang { 23 | 24 | class MacroBuilder { 25 | raw_ostream &Out; 26 | public: 27 | MacroBuilder(raw_ostream &Output) : Out(Output) {} 28 | 29 | /// Append a \#define line for macro of the form "\#define Name Value\n". 30 | void defineMacro(const Twine &Name, const Twine &Value = "1") { 31 | Out << "#define " << Name << ' ' << Value << '\n'; 32 | } 33 | 34 | /// Append a \#undef line for Name. Name should be of the form XXX 35 | /// and we emit "\#undef XXX". 36 | void undefineMacro(const Twine &Name) { 37 | Out << "#undef " << Name << '\n'; 38 | } 39 | 40 | /// Directly append Str and a newline to the underlying buffer. 41 | void append(const Twine &Str) { 42 | Out << Str << '\n'; 43 | } 44 | }; 45 | 46 | } // end namespace flang 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/flang/Basic/MakePtr.h: -------------------------------------------------------------------------------- 1 | //===--- MakePtr.h - pointer type templates --------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the make_ptr and make_const_ptr templates. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_FLANG_BASIC_MAKEPTR_H 15 | #define LLVM_FLANG_BASIC_MAKEPTR_H 16 | 17 | namespace flang { 18 | 19 | template struct make_ptr { typedef T *type; }; 20 | template struct make_const_ptr { typedef const T *type; }; 21 | 22 | } // end namespace flang 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/flang/Basic/SourceLocation.h: -------------------------------------------------------------------------------- 1 | //===--- SourceLocation.h - Compact identifier for Source Files -*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the SourceLocation class. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_FLANG_SOURCELOCATION_H 15 | #define LLVM_FLANG_SOURCELOCATION_H 16 | 17 | #include "llvm/Support/SMLoc.h" 18 | 19 | namespace flang { 20 | 21 | typedef llvm::SMLoc SourceLocation; 22 | typedef llvm::SMRange SourceRange; 23 | 24 | } // end flang namespace 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/flang/Basic/Specifiers.h: -------------------------------------------------------------------------------- 1 | //===--- Specifiers.h - Declaration and Type Specifiers ---------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines various enumerations that describe declaration and 11 | // type specifiers. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef FLANG_BASIC_SPECIFIERS_H 16 | #define FLANG_BASIC_SPECIFIERS_H 17 | 18 | namespace flang { 19 | /// \brief [R404] Specifies the intrinsic type specifier. 20 | enum TypeSpecifierType { 21 | TST_unspecified, 22 | TST_integer, 23 | TST_real, 24 | TST_complex, 25 | TST_character, 26 | TST_logical, 27 | TST_struct 28 | }; 29 | 30 | /// \brief [R502] Specifies the attribute specifiers for types. 31 | enum AttributeSpecifier { 32 | AS_unspecified = 0, 33 | AS_allocatable = 1 << 0, 34 | AS_asynchronous = 1 << 1, 35 | AS_codimension = 1 << 2, 36 | AS_contiguous = 1 << 3, 37 | AS_dimension = 1 << 4, 38 | AS_external = 1 << 5, 39 | AS_intrinsic = 1 << 6, 40 | AS_optional = 1 << 7, 41 | AS_parameter = 1 << 8, 42 | AS_pointer = 1 << 9, 43 | AS_protected = 1 << 10, 44 | AS_save = 1 << 11, 45 | AS_target = 1 << 12, 46 | AS_value = 1 << 13, 47 | AS_volatile = 1 << 14 48 | }; 49 | 50 | /// \brief [R523] Specifies the intent specifier. 51 | enum IntentSpecifier { 52 | IS_unspecified, 53 | IS_in, 54 | IS_out, 55 | IS_inout 56 | }; 57 | 58 | /// \brief [R507] Access specifier (public, private). 59 | enum AccessSpecifier { 60 | AC_unspecified, 61 | AC_public, 62 | AC_private 63 | }; 64 | 65 | } // end namespace flang 66 | 67 | #endif // FLANG_BASIC_SPECIFIERS_H 68 | -------------------------------------------------------------------------------- /include/flang/Basic/StmtNodes.td: -------------------------------------------------------------------------------- 1 | class AttrSubject; 2 | 3 | class Stmt : AttrSubject { 4 | bit Abstract = abstract; 5 | } 6 | 7 | class DStmt : Stmt { 8 | Stmt Base = base; 9 | } 10 | 11 | // Statements 12 | def ConstructPartStmt : Stmt; 13 | def DeclStmt : Stmt; 14 | def CompoundStmt : Stmt; 15 | def ProgramStmt : Stmt; 16 | def UseStmt : Stmt; 17 | def ImportStmt : Stmt; 18 | def ImplicitStmt : Stmt; 19 | def DimensionStmt : Stmt; 20 | def FormatStmt : Stmt; 21 | def EntryStmt : Stmt; 22 | def AsynchronousStmt : Stmt; 23 | def ParameterStmt : Stmt; 24 | def ExternalStmt : Stmt; 25 | def IntrinsicStmt : Stmt; 26 | def SaveStmt : Stmt; 27 | def EquivalenceStmt : Stmt; 28 | def DataStmt : Stmt; 29 | 30 | // executable statements 31 | def BlockStmt : Stmt; 32 | def AssignStmt : Stmt; 33 | def AssignedGotoStmt : Stmt; 34 | def GotoStmt : Stmt; 35 | def ComputedGotoStmt : Stmt; 36 | def NamedConstructStmt : Stmt<1>; 37 | def IfStmt : DStmt; 38 | def CFBlockStmt : DStmt; 39 | def DoStmt : DStmt; 40 | def DoWhileStmt : DStmt; 41 | def CycleStmt : Stmt; 42 | def ExitStmt : Stmt; 43 | def SelectCaseStmt : DStmt; 44 | def SelectionCase : DStmt; 45 | def CaseStmt : DStmt; 46 | def DefaultCaseStmt : DStmt; 47 | def WhereStmt : Stmt; 48 | def ContinueStmt : Stmt; 49 | def StopStmt : Stmt; 50 | def ReturnStmt : Stmt; 51 | def CallStmt : Stmt; 52 | def AssignmentStmt : Stmt; 53 | def PrintStmt : Stmt; 54 | def WriteStmt : Stmt; 55 | -------------------------------------------------------------------------------- /include/flang/Basic/TargetOptions.h: -------------------------------------------------------------------------------- 1 | //===--- TargetOptions.h ----------------------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | /// 10 | /// \file 11 | /// \brief Defines the flang::TargetOptions class. 12 | /// 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef LLVM_FLANG_FRONTEND_TARGETOPTIONS_H 16 | #define LLVM_FLANG_FRONTEND_TARGETOPTIONS_H 17 | 18 | #include 19 | #include 20 | #include "flang/Basic/LLVM.h" 21 | #include "llvm/Target/TargetOptions.h" 22 | #include "llvm/ADT/IntrusiveRefCntPtr.h" 23 | 24 | namespace flang { 25 | 26 | /// \brief Options for controlling the target. 27 | class TargetOptions : public llvm::RefCountedBase { 28 | public: 29 | /// If given, the name of the target triple to compile for. If not given the 30 | /// target will be selected to match the host. 31 | std::string Triple; 32 | 33 | /// If given, the name of the target CPU to generate code for. 34 | std::string CPU; 35 | 36 | /// If given, the unit to use for floating point math 37 | std::string FPMath; 38 | 39 | /// If given, the name of the target ABI to use. 40 | std::string ABI; 41 | 42 | /// The EABI version to use 43 | llvm::EABI EABIVersion; 44 | 45 | /// If given, the version string of the linker in use. 46 | std::string LinkerVersion; 47 | 48 | /// \brief The list of target specific features to enable or disable, as written on the command line. 49 | std::vector FeaturesAsWritten; 50 | 51 | /// The list of target specific features to enable or disable -- this should 52 | /// be a list of strings starting with by '+' or '-'. 53 | std::vector Features; 54 | }; 55 | 56 | } // end namespace flang 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/flang/Basic/TokenKinds.h: -------------------------------------------------------------------------------- 1 | //===--- TokenKinds.h - Enum values for Fortran Token Kinds -----*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the TokenKind enum and support functions. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_FLANG_TOKENKINDS_H__ 15 | #define LLVM_FLANG_TOKENKINDS_H__ 16 | 17 | namespace flang { 18 | namespace tok { 19 | 20 | /// TokenKind - This provides a simple uniform namespace for tokens from all 21 | /// Fortran languages. 22 | enum TokenKind { 23 | #define TOK(X) X, 24 | #include "flang/Basic/TokenKinds.def" 25 | NUM_TOKENS 26 | }; 27 | 28 | /// \brief Determines the name of a token as used within the front end. 29 | /// 30 | /// The name of a token will be an internal name (such as "l_paren") and should 31 | /// not be used as part of diagnostic messages. 32 | const char *getTokenName(enum TokenKind Kind); 33 | 34 | /// \brief Determines the spelling of simple punctuation tokens like '**' or 35 | /// '(', and returns NULL for literal and annotation tokens. 36 | /// 37 | /// This routine only retrieves the "simple" spelling of the token, and will not 38 | /// produce any alternative spellings. 39 | const char *getTokenSimpleSpelling(enum TokenKind Kind); 40 | 41 | } // end namespace tok 42 | } // end namespace flang 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/flang/Basic/Version.inc.in: -------------------------------------------------------------------------------- 1 | #define FLANG_VERSION @FLANG_VERSION@ 2 | #define FLANG_VERSION_STRING "@FLANG_VERSION@" 3 | #define FLANG_VERSION_MAJOR @FLANG_VERSION_MAJOR@ 4 | #define FLANG_VERSION_MINOR @FLANG_VERSION_MINOR@ 5 | #define FLANG_VERSION_PATCHLEVEL @FLANG_VERSION_PATCHLEVEL@ 6 | -------------------------------------------------------------------------------- /include/flang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Basic) 2 | add_subdirectory(AST) 3 | -------------------------------------------------------------------------------- /include/flang/CodeGen/BackendUtil.h: -------------------------------------------------------------------------------- 1 | //===--- BackendUtil.h - LLVM Backend Utilities -----------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_FLANG_CODEGEN_BACKEND_UTIL_H 11 | #define LLVM_FLANG_CODEGEN_BACKEND_UTIL_H 12 | 13 | #include "flang/Basic/LLVM.h" 14 | 15 | namespace llvm { 16 | class Module; 17 | } 18 | 19 | namespace flang { 20 | class DiagnosticsEngine; 21 | class CodeGenOptions; 22 | class TargetOptions; 23 | class LangOptions; 24 | 25 | enum BackendAction { 26 | Backend_EmitAssembly, ///< Emit native assembly files 27 | Backend_EmitBC, ///< Emit LLVM bitcode files 28 | Backend_EmitLL, ///< Emit human-readable LLVM assembly 29 | Backend_EmitNothing, ///< Don't emit anything (benchmarking mode) 30 | Backend_EmitMCNull, ///< Run CodeGen, but don't emit anything 31 | Backend_EmitObj ///< Emit native object files 32 | }; 33 | 34 | void EmitBackendOutput(DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts, 35 | const TargetOptions &TOpts, const LangOptions &LOpts, 36 | StringRef TDesc, llvm::Module *M, BackendAction Action, 37 | raw_pwrite_stream *OS); 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/flang/CodeGen/ModuleBuilder.h: -------------------------------------------------------------------------------- 1 | //===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the ModuleBuilder interface. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_FLANG_CODEGEN_MODULEBUILDER_H 15 | #define LLVM_FLANG_CODEGEN_MODULEBUILDER_H 16 | 17 | #include "flang/AST/ASTConsumer.h" 18 | #include "flang/Basic/TargetOptions.h" 19 | #include "flang/Frontend/CodeGenOptions.h" 20 | #include 21 | 22 | namespace llvm { 23 | class LLVMContext; 24 | class Module; 25 | } 26 | 27 | namespace flang { 28 | class DiagnosticsEngine; 29 | class LangOptions; 30 | 31 | class CodeGenerator : public ASTConsumer { 32 | virtual void anchor(); 33 | public: 34 | virtual llvm::Module* GetModule() = 0; 35 | virtual llvm::Module* ReleaseModule() = 0; 36 | }; 37 | 38 | /// CreateLLVMCodeGen - Create a CodeGenerator instance. 39 | /// It is the responsibility of the caller to call delete on 40 | /// the allocated CodeGenerator instance. 41 | CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags, 42 | const std::string &ModuleName, 43 | const CodeGenOptions &CGO, 44 | const TargetOptions &TO, 45 | llvm::LLVMContext& C); 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/flang/Config/config.h.cmake: -------------------------------------------------------------------------------- 1 | /* This generated file is for internal use. Do not include it from headers. */ 2 | 3 | #ifdef FLANG_CONFIG_H 4 | #error config.h can only be included once 5 | #else 6 | #define FLANG_CONFIG_H 7 | 8 | /* Bug report URL. */ 9 | #define BUG_REPORT_URL "${BUG_REPORT_URL}" 10 | 11 | /* Default linker to use. */ 12 | #define FLANG_DEFAULT_LINKER "${FLANG_DEFAULT_LINKER}" 13 | 14 | /* Default runtime library to use. */ 15 | #define FLANG_DEFAULT_RTLIB "${FLANG_DEFAULT_RTLIB}" 16 | 17 | /* Default OpenMP runtime used by -fopenmp. */ 18 | #define FLANG_DEFAULT_OPENMP_RUNTIME "${FLANG_DEFAULT_OPENMP_RUNTIME}" 19 | 20 | /* Multilib suffix for libdir. */ 21 | #define FLANG_LIBDIR_SUFFIX "${FLANG_LIBDIR_SUFFIX}" 22 | 23 | /* Relative directory for resource files */ 24 | #define FLANG_RESOURCE_DIR "${FLANG_RESOURCE_DIR}" 25 | 26 | /* Default to all compiler invocations for --sysroot=. */ 27 | #define DEFAULT_SYSROOT "${DEFAULT_SYSROOT}" 28 | 29 | /* Directory where gcc is installed. */ 30 | #define GCC_INSTALL_PREFIX "${GCC_INSTALL_PREFIX}" 31 | 32 | /* Define if we have libxml2 */ 33 | #cmakedefine FLANG_HAVE_LIBXML ${FLANG_HAVE_LIBXML} 34 | 35 | /* Define if we have z3 and want to build it */ 36 | #cmakedefine FLANG_ANALYZER_WITH_Z3 ${FLANG_ANALYZER_WITH_Z3} 37 | 38 | /* Define if we have sys/resource.h (rlimits) */ 39 | #cmakedefine FLANG_HAVE_RLIMITS ${FLANG_HAVE_RLIMITS} 40 | 41 | /* The LLVM product name and version */ 42 | #define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}" 43 | 44 | /* Linker version detected at compile time. */ 45 | #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" 46 | 47 | /* pass --build-id to ld */ 48 | #cmakedefine ENABLE_LINKER_BUILD_ID 49 | 50 | /* enable x86 relax relocations by default */ 51 | #cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS 52 | 53 | /* Enable each functionality of modules */ 54 | #cmakedefine FLANG_ENABLE_ARCMT 55 | #cmakedefine FLANG_ENABLE_OBJC_REWRITER 56 | #cmakedefine FLANG_ENABLE_STATIC_ANALYZER 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/flang/Frontend/ASTConsumers.h: -------------------------------------------------------------------------------- 1 | //===--- ASTConsumers.h - ASTConsumer implementations -----------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // AST Consumers. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef FLANG_FRONTEND_ASTCONSUMERS_H 15 | #define FLANG_FRONTEND_ASTCONSUMERS_H 16 | 17 | #include "flang/Basic/LLVM.h" 18 | 19 | namespace llvm { 20 | namespace sys { class Path; } 21 | } 22 | 23 | namespace flang { 24 | 25 | class ASTConsumer; 26 | 27 | // AST dumper: dumps the raw AST in human-readable form to stderr; this is 28 | // intended for debugging. 29 | ASTConsumer *CreateASTDumper(StringRef FilterString); 30 | 31 | } // end namespace flang 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/flang/Frontend/FrontendDiagnostic.h: -------------------------------------------------------------------------------- 1 | //===--- DiagnosticFrontend.h - Diagnostics for frontend --------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_FLANG_FRONTENDDIAGNOSTIC_H 11 | #define LLVM_FLANG_FRONTENDDIAGNOSTIC_H 12 | 13 | #include "flang/Basic/Diagnostic.h" 14 | 15 | namespace flang { 16 | namespace diag { 17 | enum { 18 | #define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\ 19 | SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM, 20 | #define FRONTENDSTART 21 | #include "flang/Basic/DiagnosticFrontendKinds.inc" 22 | #undef DIAG 23 | NUM_BUILTIN_FRONTEND_DIAGNOSTICS 24 | }; 25 | } // end namespace diag 26 | } // end namespace flang 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/flang/Frontend/TextDiagnosticBuffer.h: -------------------------------------------------------------------------------- 1 | //===--- TextDiagnosticBuffer.h - Buffer Text Diagnostics -------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This is a concrete diagnostic client, which buffers the diagnostic messages. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_FLANG_FRONTEND_TEXT_DIAGNOSTIC_BUFFER_H_ 15 | #define LLVM_FLANG_FRONTEND_TEXT_DIAGNOSTIC_BUFFER_H_ 16 | 17 | #include "flang/Basic/Diagnostic.h" 18 | #include 19 | #include 20 | 21 | namespace flang { 22 | 23 | class Lexer; 24 | 25 | class TextDiagnosticBuffer : public DiagnosticClient { 26 | public: 27 | typedef std::vector > DiagList; 28 | typedef DiagList::iterator iterator; 29 | typedef DiagList::const_iterator const_iterator; 30 | private: 31 | DiagList Errors, Warnings, Notes; 32 | public: 33 | const_iterator err_begin() const { return Errors.begin(); } 34 | const_iterator err_end() const { return Errors.end(); } 35 | 36 | const_iterator warn_begin() const { return Warnings.begin(); } 37 | const_iterator warn_end() const { return Warnings.end(); } 38 | 39 | const_iterator note_begin() const { return Notes.begin(); } 40 | const_iterator note_end() const { return Notes.end(); } 41 | 42 | virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, SourceLocation L, 43 | const llvm::Twine &Msg); 44 | 45 | /// FlushDiagnostics - Flush the buffered diagnostics to an given 46 | /// diagnostic engine. 47 | void FlushDiagnostics(DiagnosticsEngine &Diags) const; 48 | }; 49 | 50 | } // end namspace flang 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/flang/Frontend/TextDiagnosticPrinter.h: -------------------------------------------------------------------------------- 1 | //===--- TextDiagnosticPrinter.h - Text Diagnostic Client -------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This is a concrete diagnostic client, which prints the diagnostics to 11 | // standard error. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef FLANG_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_ 16 | #define FLANG_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_ 17 | 18 | #include "flang/Basic/Diagnostic.h" 19 | 20 | namespace llvm { 21 | class raw_ostream; 22 | class SourceLocation; 23 | class SourceMgr; 24 | } // end namespace llvm 25 | 26 | namespace flang { 27 | 28 | class LangOptions; 29 | 30 | class TextDiagnosticPrinter : public DiagnosticClient { 31 | llvm::SourceMgr &SrcMgr; 32 | public: 33 | TextDiagnosticPrinter(llvm::SourceMgr &SM) : SrcMgr(SM) {} 34 | virtual ~TextDiagnosticPrinter(); 35 | 36 | // TODO: Emit caret diagnostics and Highlight range. 37 | virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, SourceLocation L, 38 | const llvm::Twine &Msg, 39 | llvm::ArrayRef Ranges, 40 | llvm::ArrayRef FixIts); 41 | }; 42 | 43 | } // end namespace flang 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/flang/Parse/LexDiagnostic.h: -------------------------------------------------------------------------------- 1 | //===--- LexDiagnostic.h - Diagnostics for lexer --------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_FLANG_LEXDIAGNOSTIC_H 11 | #define LLVM_FLANG_LEXDIAGNOSTIC_H 12 | 13 | #include "flang/Basic/Diagnostic.h" 14 | 15 | namespace flang { 16 | namespace diag { 17 | enum { 18 | #define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\ 19 | SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM, 20 | #define LEXSTART 21 | #include "flang/Basic/DiagnosticLexKinds.inc" 22 | #undef DIAG 23 | NUM_BUILTIN_LEX_DIAGNOSTICS 24 | }; 25 | } // end namespace diag 26 | } // end namespace flang 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/flang/Parse/ParseDiagnostic.h: -------------------------------------------------------------------------------- 1 | //===--- ParseDiagnostic.h - Diagnostics for parser --------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_FLANG_PARSEDIAGNOSTIC_H 11 | #define LLVM_FLANG_PARSEDIAGNOSTIC_H 12 | 13 | #include "flang/Basic/Diagnostic.h" 14 | 15 | namespace flang { 16 | namespace diag { 17 | enum { 18 | #define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\ 19 | SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM, 20 | #define PARSESTART 21 | #include "flang/Basic/DiagnosticParseKinds.inc" 22 | #undef DIAG 23 | NUM_BUILTIN_PARSE_DIAGNOSTICS 24 | }; 25 | } // end namespace diag 26 | } // end namespace flang 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/flang/Sema/SemaDiagnostic.h: -------------------------------------------------------------------------------- 1 | //===--- SemaDiagnostic.h - Diagnostics for semantics --------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_FLANG_SEMADIAGNOSTIC_H 11 | #define LLVM_FLANG_SEMADIAGNOSTIC_H 12 | 13 | #include "flang/Basic/Diagnostic.h" 14 | 15 | namespace flang { 16 | namespace diag { 17 | enum { 18 | #define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\ 19 | SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM, 20 | #define SEMASTART 21 | #include "flang/Basic/DiagnosticSemaKinds.inc" 22 | #undef DIAG 23 | NUM_BUILTIN_SEMA_DIAGNOSTICS 24 | }; 25 | } // end namespace diag 26 | } // end namespace flang 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/flang/Sema/SemaInternal.h: -------------------------------------------------------------------------------- 1 | //===--- SemaInternal.h - Internal Sema Interfaces --------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_FLANG_SEMA_SEMA_INTERNAL_H 11 | #define LLVM_FLANG_SEMA_SEMA_INTERNAL_H 12 | 13 | #include "flang/AST/ASTContext.h" 14 | #include "flang/AST/StmtVisitor.h" 15 | #include "flang/AST/FormatSpec.h" 16 | #include "flang/Sema/Sema.h" 17 | 18 | namespace flang { 19 | 20 | /// StmtLabelResolver - 'Sends' a notification 21 | /// about the statement labels declared after they are used 22 | /// to the statements that use them. 23 | class StmtLabelResolver : public StmtVisitor { 24 | DiagnosticsEngine &Diags; 25 | flang::Sema &Sema; 26 | StmtLabelScope::ForwardDecl Info; 27 | Stmt *StmtLabelDecl; 28 | bool Error; 29 | 30 | public: 31 | void VisitStmt(Stmt *S) { 32 | Error = true; 33 | } 34 | void VisitAssignStmt(AssignStmt *S); 35 | void VisitAssignedGotoStmt(AssignedGotoStmt *S); 36 | void VisitGotoStmt (GotoStmt *S); 37 | void VisitComputedGotoStmt(ComputedGotoStmt *S); 38 | void VisitDoStmt (DoStmt *S); 39 | 40 | void VisitLabelFormatSpec(LabelFormatSpec *FS); 41 | void Visit(FormatSpec *FS) { 42 | if(auto LFS = dyn_cast(FS)) 43 | VisitLabelFormatSpec(LFS); 44 | else Error = true; 45 | } 46 | 47 | StmtLabelResolver(flang::Sema &TheSema, 48 | DiagnosticsEngine &Diag) 49 | : Sema(TheSema), Diags(Diag), 50 | Info(nullptr, (Stmt*)nullptr) {} 51 | 52 | /// \brief Returns false if the forward declaration has no notification 53 | /// handler. Notifies the statement with a statement label that the label 54 | /// is used. 55 | void ResolveForwardUsage(const StmtLabelScope::ForwardDecl &S, Stmt *Decl) { 56 | Decl->setStmtLabelUsed(); 57 | Error = false; 58 | Info = S; 59 | StmtLabelDecl = Decl; 60 | if(S.Statement) 61 | StmtVisitor::Visit(S.Statement); 62 | else 63 | Visit(S.FS); 64 | assert(!Error); 65 | } 66 | }; 67 | 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /lib/AST/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_flang_library(flangAST 4 | ASTContext.cpp 5 | Decl.cpp 6 | DeclGroup.cpp 7 | DeclarationName.cpp 8 | Expr.cpp 9 | ExprConstant.cpp 10 | ExprArray.cpp 11 | FormatSpec.cpp 12 | FormatItem.cpp 13 | IOSpec.cpp 14 | Stmt.cpp 15 | ASTDumper.cpp 16 | Type.cpp 17 | IntrinsicFunctions.cpp 18 | ) 19 | 20 | add_dependencies(flangAST 21 | FlangDiagnosticCommon 22 | FlangDeclNodes 23 | FlangStmtNodes 24 | FlangExprNodes 25 | ) 26 | 27 | target_link_libraries(flangAST 28 | PRIVATE 29 | flangBasic 30 | ) 31 | -------------------------------------------------------------------------------- /lib/AST/DeclGroup.cpp: -------------------------------------------------------------------------------- 1 | //===--- DeclGroup.cpp - Classes for representing groups of Decls ----------==// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements the DeclGroup and DeclGroupRef classes. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "flang/AST/DeclGroup.h" 15 | #include "flang/AST/Decl.h" 16 | #include "flang/AST/ASTContext.h" 17 | #include "llvm/Support/Allocator.h" 18 | #include 19 | 20 | namespace flang { 21 | 22 | DeclGroup *DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) { 23 | assert(NumDecls > 1 && "Invalid DeclGroup"); 24 | unsigned Size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls; 25 | void* Mem = C.Allocate(Size, alignof(DeclGroup)); 26 | new (Mem) DeclGroup(NumDecls, Decls); 27 | return static_cast(Mem); 28 | } 29 | 30 | DeclGroup::DeclGroup(unsigned numdecls, Decl **decls) : NumDecls(numdecls) { 31 | assert(numdecls > 0); 32 | assert(decls); 33 | memcpy(this + 1, decls, numdecls * sizeof(*decls)); 34 | } 35 | 36 | } //namespace flang 37 | -------------------------------------------------------------------------------- /lib/AST/ExprArray.cpp: -------------------------------------------------------------------------------- 1 | //===--- ExprArray.cpp - Array expression classification ------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include "flang/AST/Decl.h" 11 | #include "flang/AST/Expr.h" 12 | #include "flang/AST/ExprVisitor.h" 13 | 14 | namespace flang { 15 | 16 | class ContiguousArrayChecker 17 | : public ConstExprVisitor { 18 | public: 19 | 20 | bool VisitArraySectionExpr(const ArraySectionExpr *E) { 21 | if(!E->getTarget()) 22 | return false; 23 | auto Subs = E->getSubscripts(); 24 | 25 | size_t LastElementSection = 0; 26 | bool HasElements = false; 27 | bool LastSliced = false; 28 | 29 | for(size_t I = 0; I < Subs.size(); ++I) { 30 | auto Sub = Subs[I]; 31 | if(isa(Sub)) 32 | return false; 33 | if(auto Range = dyn_cast(Sub)) { 34 | if(HasElements) 35 | return false; 36 | if(LastSliced) 37 | return false; 38 | if(!Range->hasFirstExpr() && 39 | !Range->hasSecondExpr()) { 40 | // Ok. 41 | } else 42 | LastSliced = true; 43 | } else { 44 | if(HasElements) { 45 | if(I != LastElementSection) 46 | return false; 47 | } 48 | LastElementSection = I+1; 49 | HasElements = true; 50 | LastSliced = false; 51 | } 52 | } 53 | return true; 54 | } 55 | 56 | bool VisitBinaryExpr(const BinaryExpr *E) { 57 | return Visit(E->getLHS()) && 58 | Visit(E->getRHS()); 59 | } 60 | 61 | bool VisitUnaryExpr(const UnaryExpr *E) { 62 | return Visit(E->getExpression()); 63 | } 64 | 65 | bool VisitImplicitCastExpr(const ImplicitCastExpr *E) { 66 | return Visit(E->getExpression()); 67 | } 68 | 69 | bool VisitVarExpr(const VarExpr *E) { 70 | return true; 71 | } 72 | }; 73 | 74 | bool Expr::IsArrayExprContiguous() const { 75 | assert(getType()->isArrayType()); 76 | ContiguousArrayChecker EV; 77 | return EV.Visit(this); 78 | } 79 | 80 | } // end namespace flang 81 | -------------------------------------------------------------------------------- /lib/AST/FormatSpec.cpp: -------------------------------------------------------------------------------- 1 | //===--- FormatSpec.cpp - Fortran FormatSpecifier -------------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include "flang/AST/FormatSpec.h" 11 | #include "flang/AST/ASTContext.h" 12 | 13 | namespace flang { 14 | 15 | StarFormatSpec::StarFormatSpec(SourceLocation Loc) 16 | : FormatSpec(FormatSpec::FS_Star, Loc) {} 17 | 18 | StarFormatSpec *StarFormatSpec::Create(ASTContext &C, SourceLocation Loc) { 19 | return new (C) StarFormatSpec(Loc); 20 | } 21 | 22 | CharacterExpFormatSpec::CharacterExpFormatSpec(SourceLocation Loc, Expr *F) 23 | : FormatSpec(FormatSpec::FS_CharExpr, Loc), Fmt(F) {} 24 | 25 | CharacterExpFormatSpec *CharacterExpFormatSpec::Create(ASTContext &C, SourceLocation Loc, 26 | Expr *Fmt) { 27 | return new (C) CharacterExpFormatSpec(Loc, Fmt); 28 | } 29 | 30 | LabelFormatSpec::LabelFormatSpec(SourceLocation Loc, StmtLabelReference Label) 31 | : FormatSpec(FormatSpec::FS_Label, Loc), StmtLabel(Label) {} 32 | 33 | LabelFormatSpec *LabelFormatSpec::Create(ASTContext &C, SourceLocation Loc, 34 | StmtLabelReference Label) { 35 | return new (C) LabelFormatSpec(Loc, Label); 36 | } 37 | 38 | void LabelFormatSpec::setLabel(StmtLabelReference Label) { 39 | assert(!StmtLabel.Statement); 40 | assert(Label.Statement); 41 | StmtLabel = Label; 42 | } 43 | 44 | VarLabelFormatSpec::VarLabelFormatSpec(SourceLocation Loc, VarExpr *VarRef) 45 | : FormatSpec(FormatSpec::FS_VarLabel, Loc), Var(VarRef) {} 46 | 47 | VarLabelFormatSpec *VarLabelFormatSpec::Create(ASTContext &C, SourceLocation Loc, 48 | VarExpr *Var) { 49 | return new (C) VarLabelFormatSpec(Loc, Var); 50 | } 51 | 52 | } //namespace flang 53 | -------------------------------------------------------------------------------- /lib/AST/IOSpec.cpp: -------------------------------------------------------------------------------- 1 | //===--- IOSpec.cpp - Fortran IO Specifier -------------------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include "flang/AST/IOSpec.h" 11 | #include "flang/AST/ASTContext.h" 12 | 13 | namespace flang { 14 | 15 | ExternalStarUnitSpec::ExternalStarUnitSpec(SourceLocation Loc, bool IsLabeled) 16 | : UnitSpec(US_ExternalStar, Loc, IsLabeled) {} 17 | 18 | ExternalStarUnitSpec *ExternalStarUnitSpec::Create(ASTContext &C, SourceLocation Loc, 19 | bool IsLabeled) { 20 | return new(C) ExternalStarUnitSpec(Loc, IsLabeled); 21 | } 22 | 23 | ExternalIntegerUnitSpec::ExternalIntegerUnitSpec(SourceLocation Loc, 24 | Expr *Value, bool IsLabeled) 25 | : UnitSpec(US_ExternalInt, Loc, IsLabeled), E(Value) {} 26 | 27 | ExternalIntegerUnitSpec *ExternalIntegerUnitSpec::Create(ASTContext &C, SourceLocation Loc, 28 | Expr *Value, bool IsLabeled) { 29 | return new(C) ExternalIntegerUnitSpec(Loc, Value, IsLabeled); 30 | } 31 | 32 | InternalUnitSpec::InternalUnitSpec(SourceLocation Loc, Expr *Value, bool IsLabeled) 33 | : UnitSpec(US_Internal, Loc, IsLabeled), E(Value) {} 34 | 35 | InternalUnitSpec *InternalUnitSpec::Create(ASTContext &C, SourceLocation Loc, 36 | Expr *Value, bool IsLabeled) { 37 | return new(C) InternalUnitSpec(Loc, Value, IsLabeled); 38 | } 39 | 40 | } // end namespace flang 41 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(AST) 2 | add_subdirectory(Basic) 3 | add_subdirectory(Frontend) 4 | add_subdirectory(Parse) 5 | add_subdirectory(Sema) 6 | add_subdirectory(CodeGen) 7 | -------------------------------------------------------------------------------- /lib/CodeGen/CGABI.cpp: -------------------------------------------------------------------------------- 1 | //===----- CGABI.h - ABI types-----------------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include "CGABI.h" 11 | 12 | namespace flang { 13 | namespace CodeGen { 14 | 15 | ABIArgInfo FortranABI::GetArgABI(QualType ArgType) { 16 | if(ArgType->isCharacterType()) 17 | return ABIArgInfo(ABIArgInfo::ExpandCharacterPutLengthToAdditionalArgsAsInt); 18 | else if(ArgType->isFunctionType()) 19 | return ABIArgInfo(ABIArgInfo::Value); 20 | 21 | return ABIArgInfo(ABIArgInfo::Reference); 22 | } 23 | 24 | ABIRetInfo FortranABI::GetRetABI(QualType RetType) { 25 | if(RetType.isNull() || RetType->isVoidType()) 26 | return ABIRetInfo(ABIRetInfo::Nothing); 27 | if(RetType->isCharacterType()) 28 | return ABIRetInfo(ABIRetInfo::CharacterValueAsArg); 29 | 30 | return ABIRetInfo(ABIRetInfo::Value); 31 | } 32 | 33 | ABIArgInfo LibflangABI::GetArgABI(QualType ArgType) { 34 | if(ArgType->isComplexType() || 35 | ArgType->isCharacterType()) 36 | return ABIArgInfo(ABIArgInfo::Expand); 37 | return ABIArgInfo(ABIArgInfo::Value); 38 | } 39 | 40 | ABIRetInfo LibflangABI::GetRetABI(QualType RetType) { 41 | return FortranABI::GetRetABI(RetType); 42 | } 43 | 44 | ABIArgInfo LibflangTransferABI::GetArgABI(QualType ArgType) { 45 | if(ArgType->isCharacterType()) 46 | return LibflangABI::GetArgABI(ArgType); 47 | 48 | return ABIArgInfo(ABIArgInfo::ReferenceAsVoidExtraSize); 49 | } 50 | 51 | } 52 | } // end namespace flang 53 | -------------------------------------------------------------------------------- /lib/CodeGen/CGABI.h: -------------------------------------------------------------------------------- 1 | //===----- CGABI.h - ABI types-----------------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef FLANG_CODEGEN_ABI_H 11 | #define FLANG_CODEGEN_ABI_H 12 | 13 | #include "ABIInfo.h" 14 | 15 | namespace flang { 16 | namespace CodeGen { 17 | 18 | class FortranABI { 19 | public: 20 | virtual ~FortranABI() {} 21 | virtual ABIArgInfo GetArgABI(QualType ArgType); 22 | virtual ABIRetInfo GetRetABI(QualType RetType); 23 | }; 24 | 25 | class LibflangABI : public FortranABI { 26 | public: 27 | virtual ~LibflangABI() {} 28 | ABIArgInfo GetArgABI(QualType ArgType); 29 | ABIRetInfo GetRetABI(QualType RetType); 30 | }; 31 | 32 | class LibflangTransferABI : public LibflangABI { 33 | public: 34 | virtual ~LibflangTransferABI() {} 35 | ABIArgInfo GetArgABI(QualType ArgType); 36 | }; 37 | 38 | } 39 | } // end namespace flang 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/CodeGen/CGBuilder.h: -------------------------------------------------------------------------------- 1 | //===-- CGBuilder.h - Choose IRBuilder implementation ----------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef FLANG_CODEGEN_CGBUILDER_H 11 | #define FLANG_CODEGEN_CGBUILDER_H 12 | 13 | #include "llvm/IR/IRBuilder.h" 14 | 15 | namespace flang { 16 | namespace CodeGen { 17 | 18 | // Don't preserve names on values in an optimized build. 19 | #ifdef NDEBUG 20 | typedef llvm::IRBuilder CGBuilderTy; 21 | #else 22 | typedef llvm::IRBuilder<> CGBuilderTy; 23 | #endif 24 | 25 | } // end namespace CodeGen 26 | } // end namespace flang 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/CodeGen/CGIORuntime.cpp: -------------------------------------------------------------------------------- 1 | //===----- CGIORuntime.h - Interface to IO Runtimes -------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This provides an abstract class for IO statements code generation. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "CGIORuntime.h" 15 | #include "CodeGenFunction.h" 16 | 17 | namespace flang { 18 | namespace CodeGen { 19 | 20 | CGIORuntime::~CGIORuntime() { 21 | } 22 | 23 | } 24 | } // end namespace flang 25 | 26 | -------------------------------------------------------------------------------- /lib/CodeGen/CGIORuntime.h: -------------------------------------------------------------------------------- 1 | //===----- CGIORuntime.h - Interface to IO Runtimes -------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This provides an abstract class for IO statements code generation. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef FLANG_CODEGEN_IORUNTIME_H 15 | #define FLANG_CODEGEN_IORUNTIME_H 16 | 17 | #include "flang/AST/Stmt.h" 18 | 19 | namespace flang { 20 | namespace CodeGen { 21 | 22 | class CodeGenFunction; 23 | class CodeGenModule; 24 | 25 | class CGIORuntime { 26 | protected: 27 | CodeGenModule &CGM; 28 | 29 | public: 30 | CGIORuntime(CodeGenModule &cgm) : CGM(cgm) {} 31 | virtual ~CGIORuntime(); 32 | 33 | virtual void EmitWriteStmt(CodeGenFunction &CGF, const WriteStmt *S) = 0; 34 | virtual void EmitPrintStmt(CodeGenFunction &CGF, const PrintStmt *S) = 0; 35 | }; 36 | 37 | /// Creates an instance of a Libflang IO runtime class. 38 | CGIORuntime *CreateLibflangIORuntime(CodeGenModule &CGM); 39 | 40 | } 41 | } // end namespace flang 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /lib/CodeGen/CGSystemRuntime.cpp: -------------------------------------------------------------------------------- 1 | //===----- CGSystemRuntime.h - Interface to System specific Runtimes ------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This provides an abstract class for system specific runtime calls. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "CGSystemRuntime.h" 15 | #include "CodeGenFunction.h" 16 | 17 | namespace flang { 18 | namespace CodeGen { 19 | 20 | CGSystemRuntime::~CGSystemRuntime() { 21 | } 22 | 23 | llvm::Value *CGSystemRuntime::EmitMalloc(CodeGenFunction &CGF, llvm::Type *T, llvm::Value *Size) { 24 | return CGF.getBuilder().CreateBitCast(EmitMalloc(CGF, Size), T); 25 | } 26 | 27 | } 28 | } // end namespace flang 29 | 30 | -------------------------------------------------------------------------------- /lib/CodeGen/CGSystemRuntime.h: -------------------------------------------------------------------------------- 1 | //===----- CGSystemRuntime.h - Interface to System specific Runtimes ------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This provides an abstract class for system specific runtime calls. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef FLANG_CODEGEN_SYSTEMRUNTIME_H 15 | #define FLANG_CODEGEN_SYSTEMRUNTIME_H 16 | 17 | #include "flang/AST/Stmt.h" 18 | 19 | namespace llvm { 20 | class Value; 21 | class Type; 22 | } 23 | 24 | namespace flang { 25 | namespace CodeGen { 26 | 27 | class CodeGenFunction; 28 | class CodeGenModule; 29 | 30 | class CGSystemRuntime { 31 | protected: 32 | CodeGenModule &CGM; 33 | 34 | public: 35 | CGSystemRuntime(CodeGenModule &cgm) : CGM(cgm) {} 36 | virtual ~CGSystemRuntime(); 37 | 38 | virtual void EmitInit(CodeGenFunction &CGF) = 0; 39 | 40 | virtual llvm::Value *EmitMalloc(CodeGenFunction &CGF, llvm::Value *Size) = 0; 41 | llvm::Value *EmitMalloc(CodeGenFunction &CGF, llvm::Type *T, llvm::Value *Size); 42 | virtual void EmitFree(CodeGenFunction &CGF, llvm::Value *Ptr) = 0; 43 | 44 | virtual llvm::Value *EmitETIME(CodeGenFunction &CGF, ArrayRef Arguments) = 0; 45 | }; 46 | 47 | /// Creates an instance of a Libflang System runtime class. 48 | CGSystemRuntime *CreateLibflangSystemRuntime(CodeGenModule &CGM); 49 | 50 | } 51 | } // end namespace flang 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lib/CodeGen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_flang_library(flangCodeGen 2 | ModuleBuilder.cpp 3 | CodeGenModule.cpp 4 | CodeGenFunction.cpp 5 | CodeGenTypes.cpp 6 | CodeGenAction.cpp 7 | BackendUtil.cpp 8 | TargetInfo.cpp 9 | CGABI.cpp 10 | CGDecl.cpp 11 | CGStmt.cpp 12 | CGExpr.cpp 13 | CGExprScalar.cpp 14 | CGExprComplex.cpp 15 | CGExprCharacter.cpp 16 | CGExprAgg.cpp 17 | CGArray.cpp 18 | CGIntrinsic.cpp 19 | CGArrayIntrinsic.cpp 20 | CGCall.cpp 21 | CGIORuntime.cpp 22 | CGIOLibflang.cpp 23 | CGSystemRuntime.cpp 24 | CGSystemLibflang.cpp 25 | ) 26 | 27 | target_link_libraries(flangCodeGen 28 | flangAST 29 | LLVMCore 30 | ) 31 | -------------------------------------------------------------------------------- /lib/CodeGen/TargetInfo.h: -------------------------------------------------------------------------------- 1 | //===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // These classes wrap the information about a call or function 11 | // definition used to handle ABI compliancy. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef FLANG_CODEGEN_TARGETINFO_H 16 | #define FLANG_CODEGEN_TARGETINFO_H 17 | 18 | #include "flang/AST/Type.h" 19 | #include "flang/Basic/LLVM.h" 20 | #include "llvm/ADT/StringRef.h" 21 | #include "llvm/ADT/SmallString.h" 22 | 23 | namespace llvm { 24 | class GlobalValue; 25 | class Type; 26 | class Value; 27 | } 28 | 29 | namespace flang { 30 | class ABIInfo; 31 | class Decl; 32 | 33 | namespace CodeGen { 34 | class CallArgList; 35 | class CodeGenModule; 36 | class CodeGenFunction; 37 | class CGFunctionInfo; 38 | } 39 | 40 | /// TargetCodeGenInfo - This class organizes various target-specific 41 | /// codegeneration issues, like target-specific attributes, builtins and so 42 | /// on. 43 | class TargetCodeGenInfo { 44 | ABIInfo *Info; 45 | public: 46 | TargetCodeGenInfo(ABIInfo *info = nullptr):Info(info) { } 47 | virtual ~TargetCodeGenInfo(); 48 | 49 | /// getABIInfo() - Returns ABI info helper for the target. 50 | const ABIInfo& getABIInfo() const { return *Info; } 51 | }; 52 | } 53 | 54 | #endif // FLANG_CODEGEN_TARGETINFO_H 55 | -------------------------------------------------------------------------------- /lib/Frontend/ASTConsumers.cpp: -------------------------------------------------------------------------------- 1 | //===--- ASTConsumers.cpp - ASTConsumer implementations -------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // AST Consumer Implementations. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include 15 | #include "flang/Frontend/ASTConsumers.h" 16 | #include "flang/AST/ASTContext.h" 17 | #include "flang/AST/ASTConsumer.h" 18 | 19 | using namespace flang; 20 | 21 | namespace { 22 | 23 | class ASTPrinter : public ASTConsumer { 24 | public: 25 | std::string FilterString; 26 | 27 | ASTPrinter(StringRef Filter) 28 | : FilterString(Filter) { 29 | } 30 | 31 | void HandleTranslationUnit(ASTContext &Ctx) { 32 | Ctx.getTranslationUnitDecl()->dump(); 33 | } 34 | }; 35 | 36 | } 37 | 38 | ASTConsumer *flang::CreateASTDumper(StringRef FilterString) { 39 | return new ASTPrinter(FilterString); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /lib/Frontend/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_flang_library(flangFrontend 2 | ASTConsumers.cpp 3 | TextDiagnosticPrinter.cpp 4 | TextDiagnosticBuffer.cpp 5 | VerifyDiagnosticConsumer.cpp 6 | ) 7 | -------------------------------------------------------------------------------- /lib/Frontend/TextDiagnosticBuffer.cpp: -------------------------------------------------------------------------------- 1 | //===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This is a concrete diagnostic client, which buffers the diagnostic messages. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "flang/Frontend/TextDiagnosticBuffer.h" 15 | #include "llvm/ADT/SmallString.h" 16 | #include "llvm/Support/ErrorHandling.h" 17 | #include "llvm/ADT/Twine.h" 18 | 19 | namespace flang { 20 | 21 | /// HandleDiagnostic - Store the errors, warnings, and notes that are 22 | /// reported. 23 | /// 24 | void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, SourceLocation L, 25 | const llvm::Twine &Msg) { 26 | // Default implementation (Warnings/errors count). 27 | DiagnosticClient::HandleDiagnostic(DiagLevel, L, Msg); 28 | 29 | switch (DiagLevel) { 30 | default: llvm_unreachable( 31 | "Diagnostic not handled during diagnostic buffering!"); 32 | case DiagnosticsEngine::Note: 33 | Notes.push_back(std::make_pair(L, Msg.str())); 34 | break; 35 | case DiagnosticsEngine::Warning: 36 | Warnings.push_back(std::make_pair(L, Msg.str())); 37 | break; 38 | case DiagnosticsEngine::Error: 39 | case DiagnosticsEngine::Fatal: 40 | Errors.push_back(std::make_pair(L, Msg.str())); 41 | break; 42 | } 43 | } 44 | 45 | void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { 46 | // FIXME: Flush the diagnostics in order. 47 | for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) 48 | Diags.ReportError(it->first,it->second); 49 | for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) 50 | Diags.ReportWarning(it->first,it->second); 51 | for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) 52 | Diags.ReportNote(it->first,it->second); 53 | } 54 | 55 | } // end namespace flang 56 | -------------------------------------------------------------------------------- /lib/Parse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_flang_library(flangParse 2 | Lexer.cpp 3 | ParseDecl.cpp 4 | ParseSpecStmt.cpp 5 | ParseExec.cpp 6 | ParseExpr.cpp 7 | ParseFormat.cpp 8 | Parser.cpp 9 | FixedForm.cpp 10 | ) 11 | 12 | add_dependencies(flangParse 13 | FlangDeclNodes 14 | FlangDiagnosticParse 15 | ) 16 | 17 | target_link_libraries(flangParse 18 | flangAST 19 | ) 20 | -------------------------------------------------------------------------------- /lib/Sema/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_flang_library(flangSema 2 | DeclSpec.cpp 3 | Scope.cpp 4 | Sema.cpp 5 | SemaDecl.cpp 6 | SemaExecStmt.cpp 7 | SemaDataStmt.cpp 8 | SemaExpr.cpp 9 | SemaArrayExpr.cpp 10 | SemaChecking.cpp 11 | SemaIntrinsic.cpp 12 | SemaFormat.cpp 13 | SemaIO.cpp 14 | SemaEquivalence.cpp 15 | Spec.cpp 16 | ) 17 | 18 | target_link_libraries(flangSema 19 | flangAST 20 | ) 21 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message("Making Flang test configuration files") 2 | 3 | set(FLANG_PATH_TO_LLVM_LIT ${FLANG_PATH_TO_LLVM_BUILD}/bin/llvm-lit) 4 | set(LLVM_SOURCE_DIR ${FLANG_PATH_TO_LLVM_SOURCE}) 5 | set(LLVM_BINARY_DIR ${FLANG_PATH_TO_LLVM_BUILD}) 6 | set(LLVM_TOOLS_DIR ${FLANG_PATH_TO_LLVM_BUILD}/tools) 7 | set(LLVM_LIBS_DIR ${FLANG_PATH_TO_LLVM_BUILD}/lib) 8 | 9 | #configure_file(lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg) 10 | configure_lit_site_cfg( 11 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in 12 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg 13 | ) 14 | 15 | configure_file(TestRunner.sh.in ${CMAKE_CURRENT_BINARY_DIR}/TestRunner.sh) 16 | 17 | option(FLANG_TEST_USE_VG "Run Flang tests under Valgrind" OFF) 18 | if(FLANG_TEST_USE_VG) 19 | set(FLANG_TEST_EXTRA_ARGS ${FLANG_TEST_EXTRA_ARGS} "--vg") 20 | endif () 21 | 22 | list(APPEND FLANG_TEST_DEPS 23 | flang 24 | ) 25 | 26 | set(FLANG_TEST_PARAMS 27 | flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg 28 | ) 29 | 30 | if( NOT FLANG_BUILT_STANDALONE ) 31 | list(APPEND FLANG_TEST_DEPS 32 | llvm-config 33 | FileCheck 34 | ) 35 | endif() 36 | 37 | add_lit_testsuite(check-flang "Running Flang regression tests" 38 | ${CMAKE_CURRENT_BINARY_DIR} 39 | PARAMS ${FLANG_TEST_PARAMS} 40 | DEPENDS ${FLANG_TEST_DEPS} 41 | ARGS ${FLANG_TEST_EXTRA_ARGS} 42 | ) 43 | set_target_properties(check-flang PROPERTIES FOLDER "Flang tests") 44 | 45 | -------------------------------------------------------------------------------- /test/CodeGen/Intrinsics/bitops.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | PROGRAM bittest 4 | 5 | integer i 6 | integer(8) i64 7 | logical l 8 | 9 | i = 12 10 | i = not(i) ! CHECK: xor i32 {{.*}}, -1 11 | i = iand(i, 15) ! CHECK: and i32 12 | i = iand(1,2) ! CHECK: store i32 0 13 | i = ior(i, 1) ! CHECK: or i32 14 | i = ior(7,8) ! CHECK: store i32 15 15 | i64 = ieor(i64, i64) ! CHECK: xor i64 16 | i = ieor(1,3) ! CHECK: store i32 2 17 | 18 | l = btest(i, 2) ! CHECK: and i32 {{.*}}, 4 19 | continue ! CHECK-NEXT: icmp ne i32 20 | continue ! CHECK-NEXT: select i1 {{.*}}, i1 true, i1 false 21 | l = btest(8,3) ! CHECK: store i32 1 22 | 23 | i = ibset(i, 2) ! CHECK: or i32 {{.*}}, 4 24 | i = ibset(12,1) ! CHECK: store i32 14 25 | i64 = ibclr(i64, 1) ! CHECK: and i64 {{.*}}, -3 26 | i = ibclr(14,1) ! CHECK: store i32 12 27 | 28 | i = ibits(i, 2, 4) ! CHECK: lshr i32 {{.*}}, 2 29 | continue ! CHECK-NEXT: and i32 {{.*}}, 15 30 | i = ibits(14, 1, 3) ! CHECK: store i32 7 31 | 32 | i = ishft(i, 4) ! CHECK: shl i32 {{.*}}, 4 33 | i = ishft(i, -2) ! CHECK: lshr i32 {{.*}}, 2 34 | i = ishft(i, i/4) ! CHECK: icmp sge i32 {{.*}}, 0 35 | continue ! CHECK: select i1 36 | 37 | i = ishft(3, 1) ! CHECK: store i32 6 38 | i = ishft(8, -1) ! CHECK: store i32 4 39 | 40 | end 41 | -------------------------------------------------------------------------------- /test/CodeGen/Intrinsics/inquiry.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | PROGRAM inquirytest 4 | 5 | integer i 6 | integer(8) i64 7 | complex(8) c8 8 | 9 | data i / bit_size(23) / 10 | 11 | i = kind(i) ! CHECK: store i32 4 12 | i = kind(i64) ! CHECK-NEXT: store i32 8 13 | i64 = kind(c8) ! CHECK-NEXT: store i64 8 14 | 15 | i = bit_size(i) ! CHECK-NEXT: store i32 32 16 | i = bit_size(i64) ! CHECK-NEXT: store i32 64 17 | 18 | i = selected_int_kind(7) ! CHECK-NEXT: store i32 4 19 | i = selected_int_kind(1000) ! CHECK-NEXT: store i32 -1 20 | 21 | i = selected_int_kind(i) ! CHECK: call i32 @libflang_selected_int_kind(i32 22 | i64 = selected_int_kind(i64) ! CHECK: call i32 @libflang_selected_int_kind(i32 23 | 24 | end 25 | -------------------------------------------------------------------------------- /test/CodeGen/Intrinsics/maxminloc.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | PROGRAM maxminloctest 4 | 5 | INTRINSIC maxloc, minloc 6 | integer i_arr(5) 7 | real r_arr(5) 8 | 9 | i_arr = (/ 4, 7, 2, 1, 0 /) 10 | i = maxloc(i_arr, 1) ! CHECK: icmp sgt i32 11 | continue ! CHECK: br i1 12 | 13 | i = minloc((/ 0, 5, 42, -54, 1 /), 1) 14 | 15 | r_arr = 1.0 16 | i = maxloc(r_arr, 1) 17 | 18 | i = maxloc(r_arr + (/ 1.0, 0.0, 2.0, 3.0, 4.0 /), 1) 19 | 20 | i = maxloc(r_arr(:3), 1) 21 | 22 | ! FIXME: add codegen for other variations of max/min loc 23 | 24 | END 25 | -------------------------------------------------------------------------------- /test/CodeGen/array.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | PROGRAM helloArrays 4 | 5 | REAL R(10) ! CHECK: alloca [10 x float] 6 | INTEGER I(-1:5) ! CHECK: alloca [7 x i32] 7 | COMPLEX C(10, 0:9, 10) ! CHECK: alloca [1000 x { float, float }] 8 | CHARACTER*20 STR(-5:4, 9) ! CHECK: alloca [90 x [20 x i8]] 9 | 10 | INTEGER ii 11 | INTEGER (Kind=1) is 12 | REAL rr 13 | COMPLEX cc 14 | CHARACTER*20 STRSTR 15 | 16 | rr = r(1) ! CHECK: getelementptr inbounds [10 x float], [10 x float]* 17 | CONTINUE ! CHECK: getelementptr float, float* 18 | CONTINUE ! CHECK: load float, float* 19 | 20 | ii = i(0) ! CHECK: getelementptr i32, i32* 21 | 22 | is = 1 23 | i(is) = r(is) ! CHECK: sext i8 24 | 25 | cc = c(1, 1, 1) ! CHECK: getelementptr { float, float }, { float, float }* 26 | 27 | STRSTR = STR(4, 9) ! CHECK: getelementptr [20 x i8], [20 x i8]* 28 | 29 | i(5) = 11 30 | r(1) = 1.0 31 | c(10, 9, 10) = (1.0, 0.0) 32 | str(1,1) = 'Hello' 33 | 34 | END 35 | -------------------------------------------------------------------------------- /test/CodeGen/array.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llvm-flang/flang/45dec2772a6696ad28dca16e976aeaf980ff4052/test/CodeGen/array.o -------------------------------------------------------------------------------- /test/CodeGen/arrayArgument.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | SUBROUTINE SUB(IARR, IARR2, LEN, RARR) 4 | INTEGER IARR(10), IARR2(*) 5 | INTEGER LEN, I, J 6 | REAL RARR(LEN, *) 7 | 8 | IARR(1) = 11 9 | IARR2(25) = 13 10 | 11 | RARR(22, 4) = 1.0 ! CHECK: load i32, i32* 12 | CONTINUE ! CHECK: mul i64 3 13 | CONTINUE ! CHECK: add i64 21 14 | CONTINUE ! CHECK: getelementptr float, float* 15 | 16 | DO I = 1, 10 17 | IARR(I) = -1 ! CHECK: load i32, i32* 18 | CONTINUE ! CHECK: sub i64 19 | CONTINUE ! CHECK: getelementptr i32, i32* 20 | END DO 21 | 22 | DO I = 1, LEN 23 | DO J = 1, LEN 24 | RARR(I, J) = 0.0 25 | END DO 26 | END DO 27 | END 28 | 29 | PROGRAM f77ArrayArgs 30 | 31 | PARAMETER(xdim = 42) 32 | INTEGER i1(10), i2(50) 33 | REAL r1(xdim, xdim) 34 | 35 | CALL sub(i1, i2, xdim, r1) 36 | 37 | END 38 | 39 | -------------------------------------------------------------------------------- /test/CodeGen/arrayAssignment.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s 2 | 3 | PROGRAM test 4 | 5 | integer i_mat(4,4), i_mat2(4,4) 6 | integer i 7 | 8 | i = 11 9 | i_mat = i 10 | i_mat2 = i_mat 11 | i_mat(1:3,:) = 2 12 | i_mat(:1,:1) = 11 13 | i_mat(1,:) = 10 14 | i_mat(:2,4) = 12 15 | i_mat(:3:2,1:3:1) = 13 16 | 17 | END 18 | -------------------------------------------------------------------------------- /test/CodeGen/arrayConstructor.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | PROGRAM test ! CHECK: private constant [4 x i32] [i32 1, i32 2, i32 3, i32 4] 4 | 5 | integer i_arr(4), i_mat(4,4) 6 | logical l_arr(4) 7 | integer i 8 | parameter(i = 0) 9 | integer n 10 | 11 | 12 | i_arr = (/ 1, 2, 3, 4 /) 13 | i_arr = (/ i, i, 2, 4 /) 14 | n = 42 15 | i_arr = (/ n, i, 2, n /) 16 | 17 | i_arr = i_arr + (/ 0, 1, 2, 3 /) 18 | 19 | l_arr = (/ .false., .true., .false., i == n /) 20 | 21 | END 22 | -------------------------------------------------------------------------------- /test/CodeGen/arrayOperations.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s 2 | 3 | PROGRAM test 4 | 5 | integer i_mat(4,4), i_mat2(4,4) 6 | real r_mat(4,4) 7 | complex c_mat(4,4), c_mat2(4,4) 8 | logical l_mat(4,4) 9 | integer i 10 | 11 | i = 11 12 | i_mat = 11 13 | i_mat2 = 12 14 | i_mat = 1.0 15 | r_mat = 1.0 16 | c_mat = (1.0,0.0) 17 | c_mat2 = c_mat 18 | i_mat = r_mat 19 | 20 | i_mat = i_mat + i_mat2 21 | i_mat2 = i_mat * (2 - 4) + r_mat 22 | 23 | c_mat = c_mat * c_mat2 24 | i_mat = c_mat + i_mat2 25 | 26 | l_mat = i_mat <= i_mat2 27 | 28 | i_mat = int(r_mat) 29 | r_mat = real(i_mat) 30 | c_mat = cmplx(c_mat2) 31 | c_mat = cmplx(i_mat,r_mat) 32 | 33 | r_mat = aimag(c_mat) 34 | c_mat = conjg(c_mat) 35 | i_mat = abs(i_mat) + sqrt(r_mat) 36 | r_mat = sin(r_mat) * cos(r_mat) + tan(r_mat) 37 | c_mat = exp(c_mat) + sin(c_mat) 38 | 39 | END 40 | -------------------------------------------------------------------------------- /test/CodeGen/arrayTempAndPacking.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s 2 | 3 | SUBROUTINE SUB(LEN, IMAT) 4 | INTEGER LEN, IMAT(LEN, *) 5 | END 6 | 7 | PROGRAM test 8 | INTEGER IMAT(4,4) 9 | 10 | IMAT = 0 11 | CALL SUB(4, -IMAT + 1) 12 | END 13 | -------------------------------------------------------------------------------- /test/CodeGen/callableArguments.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | SUBROUTINE SUB(F, G) ! CHECK: void (i32*)* %f, i32 (float*)* %g 4 | EXTERNAL F 5 | LOGICAL G 6 | EXTERNAL G 7 | 8 | CALL F(2) ! CHECK: call void %f(i32* 9 | IF(G(3.0)) THEN ! CHECK: call i32 %g(float* 10 | END IF 11 | END 12 | 13 | SUBROUTINE F(I) 14 | END 15 | 16 | LOGICAL FUNCTION FOO(R) 17 | Foo = .true. 18 | END 19 | 20 | PROGRAM test 21 | CALL SUB(F, FOO) ! CHECK: call void @sub_(void (i32*)* @f_, i32 (float*)* @foo_) 22 | END 23 | -------------------------------------------------------------------------------- /test/CodeGen/character.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | SUBROUTINE FOO(STR) ! CHECK: define void @foo_(i8* %str, i32 %str.length) 4 | CHARACTER*(*) STR 5 | STR = 'AGAIN' 6 | END 7 | 8 | SUBROUTINE OOF(STR, R) ! CHECK: define void @oof_(i8* %str, float* noalias %r, i32 %str.length) 9 | CHARACTER*(*) STR 10 | REAL R 11 | STR = 'AGAIN' 12 | END 13 | 14 | 15 | CHARACTER*10 FUNCTION BAR(I) ! CHECK: define void @bar_(i32* noalias %i, { i8*, i64 } %bar) 16 | INTEGER I 17 | BAR = 'STRING' 18 | BAR = BAR 19 | END 20 | 21 | SUBROUTINE SUB(C,C2) 22 | CHARACTER C 23 | CHARACTER*2 C2 24 | IF(C.EQ.'A') RETURN ! CHECK: call i32 @libflang_compare_char1(i8* {{.*}}, i64 1, i8* {{.*}}, i64 1) 25 | IF(C2.NE.'HI') RETURN ! CHECK: call i32 @libflang_compare_char1(i8* {{.*}}, i64 2, i8* {{.*}}, i64 2) 26 | END 27 | 28 | PROGRAM test 29 | CHARACTER STR ! CHECK: alloca [1 x i8] 30 | CHARACTER*20 STR2 ! CHECK: alloca [20 x i8] 31 | PARAMETER (Label = '...') 32 | LOGICAL L 33 | 34 | STR = 'HELLO' ! CHECK: call void @libflang_assignment_char1 35 | STR = STR 36 | STR = STR(1:1) 37 | 38 | STR = STR // ' WORLD' ! CHECK: call void @libflang_concat_char1 39 | 40 | L = STR .EQ. STR ! CHECK: call i32 @libflang_compare_char1 41 | CONTINUE ! CHECK: icmp eq i32 42 | 43 | L = STR .NE. STR ! CHECK: call i32 @libflang_compare_char1 44 | CONTINUE ! CHECK: icmp ne i32 45 | 46 | CALL FOO(STR) 47 | 48 | STR = BAR(2) 49 | 50 | STR2 = 'GREETINGS' 51 | STR2 = Label 52 | 53 | CALL FOO(BAR(1)) 54 | 55 | STR2 = 'JK ' // BAR(10) // ' KG' 56 | 57 | END PROGRAM 58 | -------------------------------------------------------------------------------- /test/CodeGen/characterIntrinsic.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM test 3 | CHARACTER STR 4 | LOGICAL L 5 | INTEGER I 6 | 7 | INTRINSIC len, len_trim, index, lle, lgt 8 | 9 | I = len('Hello') ! CHECK: store i32 5 10 | 11 | I = len_trim('Hello ') ! CHECK: @libflang_lentrim_char1 12 | 13 | STR = 'Hello' 14 | 15 | I = index(STR, STR(:)) ! CHECK: call i{{.*}} @libflang_index_char1 16 | 17 | L = lle(STR, 'Hello') 18 | L = lgt(STR, 'World') ! CHECK: call i32 @libflang_lexcompare_char1 19 | 20 | END PROGRAM 21 | -------------------------------------------------------------------------------- /test/CodeGen/common.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | program com ! CHECK: @__BLNK__ = common global { i32, i32, float, { float, float } } zeroinitializer, align 16 4 | integer i,j ! CHECK: @dir_ = common global { [20 x i8], i32 } zeroinitializer, align 16 5 | real r 6 | complex c 7 | common i,j,r,c 8 | 9 | integer str_len 10 | character(20) str 11 | common /dir/ str 12 | common /dir/ str_len 13 | save /dir/ 14 | 15 | i = 0 ! CHECK: store i32 0, i32* getelementptr inbounds ({ i32, i32, float, { float, float } }, { i32, i32, float, { float, float } }* @__BLNK__, i32 0, i32 0) 16 | r = 1.0 17 | str_len = j ! CHECK: load i32, i32* getelementptr inbounds ({ i32, i32, float, { float, float } }, { i32, i32, float, { float, float } }* @__BLNK__, i32 0, i32 1) 18 | continue ! CHECK-NEXT: i32* getelementptr inbounds ({ [20 x i8], i32 }, { [20 x i8], i32 }* @dir_, i32 0, i32 1) 19 | 20 | str = 'Hello' 21 | 22 | end 23 | 24 | subroutine sub1 25 | integer j 26 | real r 27 | common j, r 28 | character(10) str 29 | common /dir/ str 30 | j = 1 ! CHECK: store i32 1, i32* getelementptr inbounds ({ i32, float }, { i32, float }* bitcast ({ i32, i32, float, { float, float } }* @__BLNK__ to { i32, float }*), i32 0, i32 0) 31 | r = 1.0 32 | str = 'Foo' 33 | end 34 | -------------------------------------------------------------------------------- /test/CodeGen/complexArithmetic.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM test 3 | COMPLEX C ! CHECK: alloca { float, float } 4 | DOUBLE COMPLEX DC ! CHECK: alloca { double, double } 5 | LOGICAL L 6 | 7 | C = C ! CHECK: getelementptr inbounds { float, float }, { float, float }* 8 | CONTINUE ! CHECK: load float, float* 9 | 10 | C = +C 11 | C = -C ! CHECK: fsub float 12 | CONTINUE ! CHECK: fsub float 13 | 14 | C = C + C ! CHECK: fadd float 15 | CONTINUE ! CHECK: fadd float 16 | 17 | C = C - C ! CHECK: fsub float 18 | CONTINUE ! CHECK: fsub float 19 | 20 | C = C * C ! CHECK: fmul float 21 | CONTINUE ! CHECK: fmul float 22 | CONTINUE ! CHECK: fsub float 23 | CONTINUE ! CHECK: fmul float 24 | CONTINUE ! CHECK: fmul float 25 | CONTINUE ! CHECK: fadd float 26 | 27 | C = C / C ! CHECK: br i1 28 | 29 | C = (1, 2) + C ! CHECK: fadd float 1 30 | CONTINUE ! CHECK: fadd float 2 31 | 32 | C = (-7.0, 7.0) - C ! CHECK: fsub float -7 33 | CONTINUE ! CHECK: fsub float 7 34 | 35 | L = (0.0, 1.0) .EQ. C ! CHECK: fcmp oeq float 0 36 | CONTINUE ! CHECK: fcmp oeq float 1 37 | CONTINUE ! CHECK: and i1 38 | 39 | L = (1.0, 0.0) .NE. C ! CHECK: fcmp une float 1 40 | CONTINUE ! CHECK: fcmp une float 0 41 | CONTINUE ! CHECK: or i1 42 | 43 | C = (1.0, 1.0) 44 | C = C ** 1 45 | C = C ** 2 46 | C = C ** 3 ! CHECK: call void @libflang_cpowif(float {{.*}}, float {{.*}}, i32 3, { float, float }* 47 | C = C ** C ! CHECK: call void @libflang_cpowf(float {{.*}}, float {{.*}}, float {{.*}}, float {{.*}}, { float, float }* 48 | 49 | DC = (2d0, 1d0) + DC ! CHECK: fadd double 2 50 | CONTINUE ! CHECK: fadd double 1 51 | END 52 | -------------------------------------------------------------------------------- /test/CodeGen/complexIntrinsic.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM testcomplexintrinsics 3 | COMPLEX c 4 | INTRINSIC aimag, conjg 5 | REAL r 6 | 7 | c = (1.0, 0.0) ! CHECK: store float 8 | CONTINUE ! CHECK: store float 9 | r = aimag(c) ! CHECK: store float 10 | c = conjg(c) ! CHECK: fsub float 11 | CONTINUE ! CHECK: store float 12 | CONTINUE ! CHECK: store float 13 | 14 | END 15 | 16 | -------------------------------------------------------------------------------- /test/CodeGen/complexIntrinsicMath.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - -O1 %s | %file_check %s 2 | PROGRAM testcomplexintrinsicmath 3 | COMPLEX c 4 | INTRINSIC abs, sqrt, sin, cos, log, exp 5 | 6 | c = (1.0, 0.0) 7 | 8 | c = abs(c) ! CHECK: call float @libflang_cabsf 9 | c = sqrt(c) ! CHECK: call void @libflang_csqrtf(float {{.*}}, float {{.*}}, { float, float }* 10 | c = sin(c) ! CHECK: call void @libflang_csinf(float {{.*}}, float {{.*}}, { float, float }* 11 | c = cos(c) ! CHECK: call void @libflang_ccosf(float {{.*}}, float {{.*}}, { float, float }* 12 | c = log(c) ! CHECK: call void @libflang_clogf(float {{.*}}, float {{.*}}, { float, float }* 13 | c = exp(c) ! CHECK: call void @libflang_cexpf(float {{.*}}, float {{.*}}, { float, float }* 14 | 15 | END 16 | -------------------------------------------------------------------------------- /test/CodeGen/computedGoto.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM gototest 3 | INTEGER I 4 | 5 | 10 I = 0 6 | 20 GOTO (10,30) I ! CHECK: switch i32 7 | 8 | 30 I = 1 9 | 10 | END PROGRAM 11 | -------------------------------------------------------------------------------- /test/CodeGen/core.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM test 3 | STOP ! CHECK: call void @libflang_stop() 4 | END PROGRAM 5 | -------------------------------------------------------------------------------- /test/CodeGen/data.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM datatest 3 | INTEGER I, J 4 | REAL X 5 | INTEGER I_ARR(10) 6 | LOGICAL L_ARR(4) 7 | character(len=5) str1 8 | 9 | DATA (I_ARR(I), I = 1,10) / 2*0, 5*2, 3*-1 / 10 | 11 | DATA L_ARR / .false., .true., .false., .true. / 12 | 13 | data str1 / 'Hello' / 14 | 15 | DATA I / 1 / J, X / 2*0 / ! CHECK: store i32 1 16 | CONTINUE ! CHECK-NEXT: store i32 0 17 | CONTINUE ! CHECK-NEXT: store float 0 18 | 19 | continue ! CHECK: call void @llvm.memcpy.p0i8.p0i8 20 | 21 | END PROGRAM 22 | -------------------------------------------------------------------------------- /test/CodeGen/defaultDouble8.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -fdefault-real-8 -fdefault-double-8 -emit-llvm -o - %s | %file_check %s 2 | 3 | program test 4 | real x ! CHECK: alloca double 5 | double precision y ! CHECK-NEXT: alloca double 6 | integer i ! CHECK-NEXT: alloca i32 7 | end 8 | -------------------------------------------------------------------------------- /test/CodeGen/defaultInt8.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -fdefault-integer-8 -emit-llvm -o - %s | %file_check %s 2 | 3 | program test 4 | integer i ! CHECK: alloca i64 5 | logical l ! CHECK-NEXT: alloca i64 6 | end 7 | -------------------------------------------------------------------------------- /test/CodeGen/defaultReal8.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -fdefault-real-8 -emit-llvm -o - %s | %file_check %s 2 | 3 | program test 4 | real x ! CHECK: alloca double 5 | double precision y ! CHECK-NEXT: alloca fp128 6 | integer i ! CHECK-NEXT: alloca i32 7 | end 8 | -------------------------------------------------------------------------------- /test/CodeGen/do.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s 2 | PROGRAM dowhiletest 3 | INTEGER I 4 | INTEGER J 5 | REAL R, Z 6 | 7 | J = 1 8 | DO I = 1, 10 9 | J = J * I 10 | END DO 11 | 12 | DO I = 1, 10, -2 13 | J = J - I 14 | END DO 15 | 16 | Z = 0.0 17 | DO R = 1.0, 2.5, 0.25 18 | Z = Z + R 19 | END DO 20 | 21 | END PROGRAM 22 | -------------------------------------------------------------------------------- /test/CodeGen/dowhile.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM dowhiletest 3 | INTEGER I 4 | 5 | I = 0 6 | DO WHILE(I .LT. 10) ! CHECK: icmp slt 7 | I = I + 1 ! CHECK: br i1 8 | END DO ! CHECK: br label 9 | 10 | END PROGRAM 11 | -------------------------------------------------------------------------------- /test/CodeGen/equivalence.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | 3 | PROGRAM eqtest 4 | INTEGER I, J ! CHECK: alloca i8, i64 4, align 5 | REAL X ! CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 0 6 | EQUIVALENCE(I, J, X) 7 | INTEGER IS 8 | INTEGER I_MAT(4,4), I_MAT2(4,4) ! CHECK: alloca i8, i64 80, align 9 | EQUIVALENCE (IS, I_MAT) ! CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 16 10 | EQUIVALENCE (IS, I_MAT2(1,2)) 11 | 12 | I = 0 13 | X = 1.0 14 | 15 | IS = 1 16 | I_MAT(1,1) = 2 17 | END PROGRAM 18 | -------------------------------------------------------------------------------- /test/CodeGen/exitCycle.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s 2 | PROGRAM test 3 | 4 | do i = 1,10 5 | exit 6 | end do 7 | 8 | outer: do i = 1,10 9 | inner: do j = 1, 10 10 | cycle outer 11 | end do inner 12 | exit outer 13 | end do outer 14 | 15 | END 16 | -------------------------------------------------------------------------------- /test/CodeGen/goto.f95: -------------------------------------------------------------------------------- 1 | ! RUN: %flang -emit-llvm -o - %s | %file_check %s 2 | PROGRAM gototest 3 | 4 | 1000 CONTINUE ! CHECK: ;