[flang] Some initial bridge code

add QualifiedStmt class

Original-commit: flang-compiler/f18@b2d89fe696
This commit is contained in:
Eric Schweitz 2019-04-01 11:09:03 -07:00
parent bb832078a1
commit 0b7fa133ae
6 changed files with 128 additions and 65 deletions

View File

@ -17,3 +17,4 @@ add_subdirectory(evaluate)
add_subdirectory(FIR)
add_subdirectory(parser)
add_subdirectory(semantics)
add_subdirectory(bridge)

View File

@ -137,8 +137,7 @@ static std::vector<SwitchRankStmt::ValueType> populateSwitchValues(
auto &rank{std::get<parser::SelectRankCaseStmt::Rank>(
std::get<parser::Statement<parser::SelectRankCaseStmt>>(v.t)
.statement.t)};
std::visit(
common::visitors{
std::visit(common::visitors{
[&](const parser::ScalarIntConstantExpr &exp) {
const auto &e{exp.thing.thing.thing.value()};
result.emplace_back(SwitchRankStmt::Exactly{ExprRef(e)});
@ -161,10 +160,10 @@ static std::vector<SwitchTypeStmt::ValueType> populateSwitchValues(
for (auto &v : list) {
auto &guard{std::get<parser::TypeGuardStmt::Guard>(
std::get<parser::Statement<parser::TypeGuardStmt>>(v.t).statement.t)};
std::visit(
common::visitors{
std::visit(common::visitors{
[&](const parser::TypeSpec &spec) {
result.emplace_back(SwitchTypeStmt::TypeSpec{spec.declTypeSpec});
result.emplace_back(
SwitchTypeStmt::TypeSpec{spec.declTypeSpec});
},
[&](const parser::DerivedTypeSpec &spec) {
result.emplace_back(
@ -470,8 +469,7 @@ public:
template<typename STMTTYPE, typename CT>
Statement *GetSwitchSelector(const CT *selectConstruct) {
return std::visit(
common::visitors{
return std::visit(common::visitors{
[&](const parser::Expr &e) {
return builder_->CreateExpr(ExprRef(e));
},
@ -596,8 +594,7 @@ public:
// extract options from list -> opts
AllocOpts opts;
for (auto &allocOpt : std::get<std::list<parser::AllocOpt>>(stmt.t)) {
std::visit(
common::visitors{
std::visit(common::visitors{
[&](const parser::AllocOpt::Mold &m) {
opts.mold = *ExprRef(m.v);
},
@ -1320,11 +1317,12 @@ void FortranIRLowering::ConstructFIR(AnalysisData &ad) {
[&](const parser::ReturnStmt *s) {
// alt-return
if (s->v) {
auto *app{
builder_->CreateExpr(ExprRef(s->v->thing.thing))};
auto *exp{ExprRef(s->v->thing.thing)};
auto app{builder_->QualifiedCreateExpr(exp)};
builder_->CreateReturn(app);
} else {
auto *zero{builder_->CreateExpr(CreateConstant(0))};
auto zero{
builder_->QualifiedCreateExpr(CreateConstant(0))};
builder_->CreateReturn(zero);
}
},

View File

@ -107,8 +107,7 @@ BasicBlock *SwitchRankStmt::defaultSucc() const {
// check LoadInsn constraints
static void CheckLoadInsn(const Value &v) {
std::visit(
common::visitors{
std::visit(common::visitors{
[](DataObject *) { /* ok */ },
[](Statement *s) { CHECK(GetAddressable(s)); },
[](auto) { CHECK(!"invalid load input"); },

View File

@ -0,0 +1,23 @@
# Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_library(FortranBridge
ir-gen.cc
)
target_link_libraries(FortranBridge
FortranCommon
FortranFIR
)

View File

@ -0,0 +1,22 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ir-gen.h"
namespace Fortran::bridge {
void GenerateIR(void) {
}
}

20
flang/lib/bridge/ir-gen.h Normal file
View File

@ -0,0 +1,20 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Fortran::bridge {
/// Generate LLVM-IR
void GenerateIR(void);
}