OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GeoIR.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "CodeGenerator.h"
18 #include "Execute.h"
19 
20 std::vector<llvm::Value*> CodeGenerator::codegenGeoExpr(Analyzer::GeoExpr const* geo_expr,
21  CompilationOptions const& co) {
22  using ValueVector = std::vector<llvm::Value*>;
23  ValueVector argument_list;
24 
25  for (const auto arg : geo_expr->getArgs()) {
26  const auto arg_lvs = codegen(arg.get(), true, co);
27  argument_list.insert(argument_list.end(), arg_lvs.begin(), arg_lvs.end());
28  const auto arg_ti = arg->get_type_info();
29  if (arg_ti.is_array() && arg_lvs.size() == 1) {
30  // Array size is sometimes discarded during codegen, e.g. for cast ArrayExpr
31  // which needs to be addressed (TODO)
32  // Append constant array size if codegen hasn't supplied it
33  const auto arr_size = arg_ti.get_size();
34  if (arr_size > 0) {
35  argument_list.push_back(cgen_state_->llInt(int32_t(arr_size)));
36  } else {
37  throw std::runtime_error("Unable to handle Geo construction.");
38  }
39  }
40  }
41  return argument_list;
42 }
CgenState * cgen_state_
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
Definition: Analyzer.h:1473
std::vector< llvm::Value * > codegenGeoExpr(const Analyzer::GeoExpr *, const CompilationOptions &)
Definition: GeoIR.cpp:20
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
Definition: IRCodegen.cpp:25
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:248