1 //===- CommandTest.cpp -- command line runtime builder unit tests ---------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "flang/Optimizer/Builder/Runtime/Command.h" 10 #include "RuntimeCallTestBase.h" 11 #include "gtest/gtest.h" 12 13 TEST_F(RuntimeCallTest, genCommandArgumentCountTest) { 14 mlir::Location loc = firBuilder->getUnknownLoc(); 15 mlir::Value result = fir::runtime::genCommandArgumentCount(*firBuilder, loc); 16 checkCallOp(result.getDefiningOp(), "_FortranAArgumentCount", /*nbArgs=*/0, 17 /*addLocArgs=*/false); 18 } 19 20 TEST_F(RuntimeCallTest, genGetCommandArgument) { 21 mlir::Location loc = firBuilder->getUnknownLoc(); 22 mlir::Type intTy = firBuilder->getDefaultIntegerType(); 23 mlir::Type charTy = fir::BoxType::get(firBuilder->getNoneType()); 24 mlir::Value number = firBuilder->create<fir::UndefOp>(loc, intTy); 25 mlir::Value value = firBuilder->create<fir::UndefOp>(loc, charTy); 26 mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, charTy); 27 // genGetCommandArgument expects `length` and `status` to be memory references 28 mlir::Value length = firBuilder->create<fir::AllocaOp>(loc, intTy); 29 mlir::Value status = firBuilder->create<fir::AllocaOp>(loc, intTy); 30 31 fir::runtime::genGetCommandArgument( 32 *firBuilder, loc, number, value, length, status, errmsg); 33 checkCallOpFromResultBox( 34 value, "_FortranAArgumentValue", /*nbArgs=*/3, /*addLocArgs=*/false); 35 mlir::Block *block = firBuilder->getBlock(); 36 EXPECT_TRUE(block) << "Failed to retrieve the block!"; 37 checkBlockForCallOp(block, "_FortranAArgumentLength", /*nbArgs=*/1); 38 } 39 40 TEST_F(RuntimeCallTest, genGetEnvironmentVariable) { 41 mlir::Location loc = firBuilder->getUnknownLoc(); 42 mlir::Type intTy = firBuilder->getDefaultIntegerType(); 43 mlir::Type charTy = fir::BoxType::get(firBuilder->getNoneType()); 44 mlir::Value number = firBuilder->create<fir::UndefOp>(loc, intTy); 45 mlir::Value value = firBuilder->create<fir::UndefOp>(loc, charTy); 46 mlir::Value trimName = firBuilder->create<fir::UndefOp>(loc, i1Ty); 47 mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, charTy); 48 // genGetCommandArgument expects `length` and `status` to be memory references 49 mlir::Value length = firBuilder->create<fir::AllocaOp>(loc, intTy); 50 mlir::Value status = firBuilder->create<fir::AllocaOp>(loc, intTy); 51 52 fir::runtime::genGetEnvironmentVariable( 53 *firBuilder, loc, number, value, length, status, trimName, errmsg); 54 checkCallOpFromResultBox( 55 value, "_FortranAEnvVariableValue", /*nbArgs=*/6, /*addLocArgs=*/false); 56 mlir::Block *block = firBuilder->getBlock(); 57 EXPECT_TRUE(block) << "Failed to retrieve the block!"; 58 checkBlockForCallOp(block, "_FortranAEnvVariableLength", /*nbArgs=*/4); 59 } 60