Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
devops committed Jun 4, 2024
2 parents e0c848f + b29dae5 commit be50c0b
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bindings/python/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ void bind_ast(py::module_ &m) {
py::enum_<sort_category>(ast, "SortCategory")
.value("Uncomputed", sort_category::Uncomputed)
.value("Map", sort_category::Map)
.value("MapIter", sort_category::MapIter)
.value("RangeMap", sort_category::RangeMap)
.value("List", sort_category::List)
.value("Set", sort_category::Set)
.value("SetIter", sort_category::SetIter)
.value("Int", sort_category::Int)
.value("Float", sort_category::Float)
.value("StringBuffer", sort_category::StringBuffer)
Expand Down
4 changes: 3 additions & 1 deletion cmake/RuntimeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ set(STRINGBUFFER_LAYOUT 6)
set(BOOL_LAYOUT 7)
set(SYMBOL_LAYOUT 8)
set(VARIABLE_LAYOUT 9)
set(RANGEMAP_LAYOUT 11)
set(RANGEMAP_LAYOUT 10)
set(SETITER_LAYOUT 11)
set(MAPITER_LAYOUT 12)

get_filename_component(INSTALL_DIR_ABS_PATH "${CMAKE_INSTALL_PREFIX}"
REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
Expand Down
2 changes: 2 additions & 0 deletions config/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define SYMBOL_LAYOUT @SYMBOL_LAYOUT@
#define VARIABLE_LAYOUT @VARIABLE_LAYOUT@
#define RANGEMAP_LAYOUT @RANGEMAP_LAYOUT@
#define SETITER_LAYOUT @SETITER_LAYOUT@
#define MAPITER_LAYOUT @MAPITER_LAYOUT@

#define STRINGIFY(x) #x
#define TOSTRING(X) STRINGIFY(X)
Expand Down
6 changes: 4 additions & 2 deletions include/kllvm/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ enum class sort_category {
Bool,
Symbol,
Variable,
MInt,
RangeMap
RangeMap,
SetIter,
MapIter,
MInt
};

// represents the syntactic category of an LLVM backend term at runtime
Expand Down
9 changes: 6 additions & 3 deletions lib/ast/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,20 @@ std::string kore_symbol::layout_string(kore_definition *definition) const {
value_type cat = sort->get_category(definition);
switch (cat.cat) {
case sort_category::Map: result.push_back('1'); break;
case sort_category::RangeMap: result.push_back('b'); break;
case sort_category::List: result.push_back('2'); break;
case sort_category::Set: result.push_back('3'); break;
case sort_category::Int: result.push_back('4'); break;
case sort_category::Float: result.push_back('5'); break;
case sort_category::StringBuffer: result.push_back('6'); break;
case sort_category::Bool: result.push_back('7'); break;
case sort_category::Variable: result.push_back('8'); break;
case sort_category::Symbol: result.push_back('8'); break;
case sort_category::Variable: result.push_back('9'); break;
case sort_category::RangeMap: result.push_back('a'); break;
case sort_category::SetIter: result.push_back('b'); break;
case sort_category::MapIter: result.push_back('c'); break;
case sort_category::MInt:
result.append("_" + std::to_string(cat.bits) + "_");
case sort_category::Symbol: result.push_back('0'); break;
break;
case sort_category::Uncomputed: abort();
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/codegen/CreateStaticTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ create_static_term::create_token(value_type sort, std::string contents) {
global, llvm::PointerType::getUnqual(llvm::StructType::getTypeByName(
module_->getContext(), block_struct)));
}
case sort_category::SetIter:
case sort_category::MapIter:
case sort_category::Uncomputed: abort();
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/codegen/CreateTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ llvm::Type *getvalue_type(value_type sort, llvm::Module *module) {
case sort_category::Variable:
return llvm::PointerType::getUnqual(
llvm::StructType::getTypeByName(module->getContext(), block_struct));
case sort_category::MapIter:
case sort_category::SetIter:
case sort_category::Uncomputed: abort();
}
}
Expand Down
11 changes: 11 additions & 0 deletions lib/codegen/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ llvm::DIType *get_forward_decl(std::string const &name) {
}

static std::string map_struct = "map";
static std::string iter_struct = "iter";
static std::string rangemap_struct = "rangemap";
static std::string list_struct = "list";
static std::string set_struct = "set";
Expand All @@ -166,9 +167,11 @@ llvm::DIType *get_debug_type(value_type type, std::string const &type_name) {
}
static std::map<std::string, llvm::DIType *> types;
llvm::DIType *map = nullptr;
llvm::DIType *mapiter = nullptr;
llvm::DIType *rangemap = nullptr;
llvm::DIType *list = nullptr;
llvm::DIType *set = nullptr;
llvm::DIType *setiter = nullptr;
llvm::DIType *integer = nullptr;
llvm::DIType *floating = nullptr;
llvm::DIType *buffer = nullptr;
Expand All @@ -183,6 +186,10 @@ llvm::DIType *get_debug_type(value_type type, std::string const &type_name) {
map = get_pointer_debug_type(get_forward_decl(map_struct), type_name);
types[type_name] = map;
return map;
case sort_category::MapIter:
mapiter = get_pointer_debug_type(get_forward_decl(iter_struct), type_name);
types[type_name] = mapiter;
return mapiter;
case sort_category::RangeMap:
rangemap
= get_pointer_debug_type(get_forward_decl(rangemap_struct), type_name);
Expand All @@ -196,6 +203,10 @@ llvm::DIType *get_debug_type(value_type type, std::string const &type_name) {
set = get_pointer_debug_type(get_forward_decl(set_struct), type_name);
types[type_name] = set;
return set;
case sort_category::SetIter:
setiter = get_pointer_debug_type(get_forward_decl(iter_struct), type_name);
types[type_name] = setiter;
return setiter;
case sort_category::Int:
integer = get_pointer_debug_type(get_forward_decl(int_struct), type_name);
types[type_name] = integer;
Expand Down
8 changes: 7 additions & 1 deletion lib/codegen/Decision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void make_pattern_node::codegen(decision *d) {
* the sort that they originated from (int, bool, symbol, ...). In LLVM versions
* < 16, we could encode this information in the LLVM type safely. However,
* after the LLVM opaque pointer migration, we can no longer do so (as the
* legacy types %mpz* and %block* would both be %ptr, for example). We
* legacy types %mpz* and %block* would both be ptr, for example). We
* therefore define a compatibility translation between sort categories and what
* their corresponding LLVM type _would have been_ before opaque pointers.
*/
Expand All @@ -400,9 +400,11 @@ static std::string legacy_value_type_to_string(value_type sort) {
// Cases below are deliberately not implemented; the return values are
// placeholders to help with debugging only.
case sort_category::Map: return "<map>";
case sort_category::MapIter: return "<mapiter>";
case sort_category::RangeMap: return "<rangemap>";
case sort_category::List: return "<list>";
case sort_category::Set: return "<set>";
case sort_category::SetIter: return "<setiter>";
case sort_category::StringBuffer: return "<stringbuffer>";
case sort_category::MInt: return "<mint>";
case sort_category::Uncomputed: abort();
Expand Down Expand Up @@ -1084,6 +1086,8 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
break;
case sort_category::Bool:
case sort_category::MInt: break;
case sort_category::MapIter:
case sort_category::SetIter:
case sort_category::Uncomputed: abort();
}
i++;
Expand Down Expand Up @@ -1120,6 +1124,8 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
break;
case sort_category::Bool:
case sort_category::MInt: break;
case sort_category::MapIter:
case sort_category::SetIter:
case sort_category::Uncomputed: abort();
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/codegen/EmitConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ static llvm::Value *get_arg_value(
case sort_category::Variable:
arg = new llvm::BitCastInst(arg, getvalue_type(cat, mod), "", case_block);
break;
case sort_category::MapIter:
case sort_category::SetIter:
case sort_category::Uncomputed: abort();
}
return arg;
Expand Down Expand Up @@ -402,6 +404,8 @@ static std::pair<llvm::Value *, llvm::BasicBlock *> get_eval(
creator.get_current_block());
break;
}
case sort_category::MapIter:
case sort_category::SetIter:
case sort_category::Uncomputed: abort();
}
inst->insertAfter(&creator.get_current_block()->back());
Expand Down Expand Up @@ -628,6 +632,8 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) {
}
case sort_category::Variable:
case sort_category::Symbol: break;
case sort_category::MapIter:
case sort_category::SetIter:
case sort_category::Uncomputed: abort();
}
current_block = false_block;
Expand Down Expand Up @@ -1171,6 +1177,8 @@ static void get_visitor(
callbacks.at(2), state_ptr, use_sort_name);
break;
}
case sort_category::MapIter:
case sort_category::SetIter:
case sort_category::Uncomputed: abort();
}
if (i != symbol->get_arguments().size() - 1 && use_sort_name) {
Expand Down

0 comments on commit be50c0b

Please sign in to comment.