| 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 boxTy = fir::BoxType::get(firBuilder->getNoneType()); |
| 24 |
mlir::Value number = firBuilder->create<fir::UndefOp>(loc, intTy); |
| 25 |
mlir::Value value = firBuilder->create<fir::UndefOp>(loc, boxTy); |
| 26 |
mlir::Value length = firBuilder->create<fir::UndefOp>(loc, boxTy); |
| 27 |
mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, boxTy); |
| 28 |
mlir::Value result = fir::runtime::genGetCommandArgument( |
| 29 |
*firBuilder, loc, number, value, length, errmsg); |
| 30 |
checkCallOp(result.getDefiningOp(), "_FortranAGetCommandArgument", |
| 31 |
/*nbArgs=*/4, |
| 32 |
/*addLocArgs=*/true); |
| 33 |
} |
| 34 |
|
| 35 |
TEST_F(RuntimeCallTest, genEnvVariableValue) { |
| 36 |
mlir::Location loc = firBuilder->getUnknownLoc(); |
| 37 |
mlir::Type charTy = fir::BoxType::get(firBuilder->getNoneType()); |
| 38 |
mlir::Value name = firBuilder->create<fir::UndefOp>(loc, charTy); |
| 39 |
mlir::Value value = firBuilder->create<fir::UndefOp>(loc, charTy); |
| 40 |
mlir::Value trimName = firBuilder->create<fir::UndefOp>(loc, i1Ty); |
| 41 |
mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, charTy); |
| 42 |
mlir::Value result = fir::runtime::genEnvVariableValue( |
| 43 |
*firBuilder, loc, name, value, trimName, errmsg); |
| 44 |
checkCallOp(result.getDefiningOp(), "_FortranAEnvVariableValue", /*nbArgs=*/4, |
| 45 |
/*addLocArgs=*/true); |
| 46 |
} |
| 47 |
|
| 48 |
TEST_F(RuntimeCallTest, genEnvVariableLength) { |
| 49 |
mlir::Location loc = firBuilder->getUnknownLoc(); |
| 50 |
mlir::Type charTy = fir::BoxType::get(firBuilder->getNoneType()); |
| 51 |
mlir::Value name = firBuilder->create<fir::UndefOp>(loc, charTy); |
| 52 |
mlir::Value trimName = firBuilder->create<fir::UndefOp>(loc, i1Ty); |
| 53 |
mlir::Value result = |
| 54 |
fir::runtime::genEnvVariableLength(*firBuilder, loc, name, trimName); |
| 55 |
checkCallOp(result.getDefiningOp(), "_FortranAEnvVariableLength", |
| 56 |
/*nbArgs=*/2, /*addLocArgs=*/true); |
| 57 |
} |