16 #include <type_traits>
17 #include <unordered_set>
18 #include <unordered_map>
38 template<
typename ... TL>
39 inline std::size_t compute_hash(TL&& ... l)
41 return (0 ^ ... ^ std::hash<std::remove_cv_t<std::remove_reference_t<TL>>>{}(std::forward<TL>(l)));
44 inline bool compute_equal()
49 template<
typename TA,
typename TB,
typename ... TL>
50 inline bool compute_equal(TA&& a, TB&& b, TL&& ... l)
52 return a == b && compute_equal(std::forward<TL>(l)...);
63 return cecko::CKHashValue(a);
74 class std::hash<cecko::CKTypeRefPack> {
84 using CIOStream = std::ostream;
86 inline CIOStream& (*CIEndl)(CIOStream&) = &std::endl;
93 CIImmovable() =
default;
94 CIImmovable(
const CIImmovable&) =
delete;
95 CIImmovable(CIImmovable&&) =
delete;
96 CIImmovable& operator=(
const CIImmovable&) =
delete;
97 CIImmovable& operator=(CIImmovable&&) =
delete;
102 template<
typename T>
103 class CIHashedStorage : CIImmovable {
105 template<
typename ... TL>
106 const T* emplace(TL&& ... l)
108 auto rv = data_.emplace(std::forward<TL>(l)...);
113 void for_each(F&& f)
const
115 for (
auto&& a : data_)
122 std::size_t operator()(
const T& a)
const {
return a.hash(); }
129 using container_type_ = std::unordered_set< T, hasher_t>;
130 container_type_ data_;
142 template<
typename T>
143 class CINamedStorage : CIImmovable {
145 template<
typename ... TL>
146 T* try_emplace(
const CIName& n, TL&& ... l)
148 auto rv = data_.try_emplace(n, std::forward<TL>(l)...);
149 rv.first->second.set_name_ptr(&rv.first->first);
150 return &rv.first->second;
155 auto it = data_.find(n);
156 return it == data_.end() ? nullptr : &it->second;
159 const T* find(
const CIName& n)
const
161 auto it = data_.find(n);
162 return it == data_.end() ? nullptr : &it->second;
166 void for_each(F&& f)
const
168 using container_pair_obs =
const std::pair< const CIName, T>*;
169 auto pair_less = [](
auto a,
auto b) {
170 return a->first < b->first;
172 using ordering_set = std::vector< container_pair_obs>;
173 ordering_set os(data_.size(),
nullptr);
174 std::transform(data_.begin(), data_.end(), os.begin(),
178 std::sort(os.begin(), os.end(), pair_less);
185 using container_type_ = std::unordered_map< CIName, T>;
186 container_type_ data_;
195 : name_ptr_(
nullptr), def_loc_(def_loc)
206 std::string get_dump_name()
const;
207 void set_def_loc(
loc_t def_loc) { def_loc_ = def_loc; }
210 void set_name_ptr(
const CIName* p)
218 template<
typename T>
219 friend class CINamedStorage;
225 using CITypeMangle = std::string;
227 using CIDecl = std::string;
232 class CKStructElement;
285 virtual std::size_t hash()
const = 0;
297 virtual bool is_void()
const {
return false; }
298 virtual bool is_bool()
const {
return false; }
299 virtual bool is_char()
const {
return false; }
300 virtual bool is_int()
const {
return false; }
301 virtual bool is_enum()
const {
return false; }
345 virtual CITypeMangle mangle()
const = 0;
346 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor =
"")
const = 0;
351 inline bool operator==(
const CKTypeRefPack& a,
const CKTypeRefPack& b)
353 return compute_equal(a.type, b.type, a.is_const, b.is_const);
365 : irt_(CKGetVoidType(Context))
367 virtual std::size_t hash()
const override {
return 0; }
369 virtual bool is_void()
const override {
return true; }
370 virtual CITypeMangle mangle()
const override {
return "V"; }
371 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
382 : irt_(CKGetInt1Type(Context))
384 virtual std::size_t hash()
const override {
return 1; }
386 virtual bool is_bool()
const override {
return true; }
388 virtual CITypeMangle mangle()
const override {
return "B"; }
389 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
403 : irt_(CKGetInt8Type(Context))
405 virtual std::size_t hash()
const override {
return 8; }
407 virtual bool is_char()
const override {
return true; }
409 virtual CITypeMangle mangle()
const override {
return "X"; }
410 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
424 : irt_(CKGetInt32Type(Context))
426 virtual std::size_t hash()
const override {
return 32; }
428 virtual bool is_int()
const override {
return true; }
430 virtual CITypeMangle mangle()
const override {
return "I"; }
431 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
442 : points_to_(
nullptr,
false), irt_(
nullptr)
446 : points_to_(points_to), irt_(CKGetPtrType(points_to.
type->
get_ir()->getContext()))
449 virtual std::size_t hash()
const override {
return compute_hash(points_to_); }
451 bool operator==(
const CKPtrType& b)
const
453 return compute_equal(points_to_, b.points_to_);
456 virtual bool is_pointer()
const override {
return true; }
459 virtual CITypeMangle mangle()
const override {
return (points_to_.
is_const ?
"pc" :
"p") + points_to_.
type->mangle(); }
460 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
472 : element_type_(
nullptr), size_(
nullptr), irt_(
nullptr)
475 : element_type_(element_type), size_(size), irt_(CKGetArrayType(element_type->
get_ir(), size))
478 virtual std::size_t hash()
const override {
return compute_hash(element_type_, size_->getValue()); }
482 return compute_equal(element_type_, b.element_type_, size_->getValue(), b.size_->getValue());
485 virtual bool is_array()
const override {
return true; }
489 virtual CITypeMangle mangle()
const override {
return "a" + std::to_string(size_->getValue().getZExtValue()) + element_type_->mangle(); }
490 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
503 :
CINamePtr(0), pack_(
nullptr,
false), idx_(0)
506 :
CINamePtr(def_loc), pack_(pack), idx_(idx)
518 using CKStructElementObs =
const CKStructElement*;
542 :
CINamePtr(0), decl_loc_(0), defined_(
false), irt_(
nullptr)
545 :
CINamePtr(0), decl_loc_(decl_loc), defined_(
false), irt_(CKCreateStructType(Context, n))
549 virtual std::size_t hash()
const override {
return std::hash<CIName>{}(
get_name()); }
551 virtual bool is_struct()
const override {
return true; }
564 virtual CITypeMangle mangle()
const override {
return "S" +
get_name() +
'$'; }
565 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
566 void dump(CIOStream& os,
const std::string& indent)
const;
569 using element_storage_type = CINamedStorage< CKStructElement>;
572 element_storage_type elements_;
573 std::vector< CKStructElementObs> elements_ordered_;
592 :
CINamePtr(0), decl_loc_(0), defined_(
false), base_type_(
nullptr)
595 :
CINamePtr(0), decl_loc_(decl_loc), defined_(
false), base_type_(base_type)
599 virtual std::size_t hash()
const override {
return std::hash<CIName>{}(
get_name()); }
600 virtual bool is_enum()
const override {
return true; }
607 virtual CITypeMangle mangle()
const override {
return "E" +
get_name() +
'$'; }
608 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
609 virtual CKIRTypeObs
get_ir()
const override {
return base_type_->
get_ir(); }
610 void dump(CIOStream& os,
const std::string& indent)
const;
627 : ret_type_(
nullptr), variadic_(
false), irt_(
nullptr)
633 virtual std::size_t hash()
const override;
637 virtual bool is_function()
const override {
return true; }
643 virtual CITypeMangle mangle()
const override;
644 virtual CIDecl declaration(
bool is_const,
const CIDecl& dtor)
const override;
691 class CKTypeTable : CIImmovable {
694 : voit_(Context), boot_(Context), chrt_(Context), intt_(Context)
700 CKPtrTypeObs get_pointer_type(
const CKTypeRefPack& pack) {
return ptrts_.emplace(pack); }
703 void dump(CIOStream& os)
const;
709 CIHashedStorage< CKPtrType> ptrts_;
710 CIHashedStorage< CKArrayType> arrts_;
711 CIHashedStorage< CKFunctionType> fncts_;
729 virtual bool is_var()
const {
return false; }
765 :
CINamePtr(0), type_pack_(
nullptr,
false)
768 :
CINamePtr(def_loc), type_pack_(type_pack)
779 void dump(CIOStream& os)
const;
800 virtual bool is_constant()
const override {
return true; }
810 std::string declaration()
const;
813 CKTypeRefPack type_pack_;
814 CKIRConstantIntObs value_;
825 virtual bool is_var()
const override {
return true; }
830 void dump(CIOStream& os,
const std::string& indent)
const;
841 :
CKVar(type_pack, def_loc), address_(address)
874 using CKLocalTableOwner = std::unique_ptr< CKLocalTable>;
875 using CKLocalTableObs = CKLocalTable*;
877 class CKAbstractScope : CIImmovable {
879 virtual ~CKAbstractScope() {}
880 virtual CKStructTypeObs find_struct_type(
const CIName& n) = 0;
881 virtual CKEnumTypeObs find_enum_type(
const CIName& n) = 0;
882 virtual CKTypedefConstObs find_typedef(
const CIName& n)
const = 0;
883 virtual CKNamedObs find(
const CIName& n) = 0;
884 virtual CKLocalTableObs get_local();
887 using CKAbstractScopeObs = CKAbstractScope*;
898 :
CKAbstractNamed(def_loc), type_(type), irf_(CKCreateFunction(type->get_function_ir(), irname, M))
900 virtual bool is_function()
const override {
return true; }
903 bool is_defined()
const {
return !!loctab_; }
911 void dump(CIOStream& os)
const;
917 CKLocalTableOwner loctab_;
921 class CKUniversalTable :
public CKAbstractScope {
925 return strts_.try_emplace(n, Context, n, decl_loc);
927 CKStructTypeObs find_struct_type_here(
const CIName& n) {
return strts_.find(n); }
928 CKEnumTypeObs declare_enum_type_here(
const CIName& n, CKTypeObs base_type, loc_t decl_loc)
930 return enmts_.try_emplace(n, base_type, decl_loc);
932 CKEnumTypeObs find_enum_type_here(
const CIName& n) {
return enmts_.find(n); }
933 CKTypedefConstObs declare_typedef(
const CIName& name,
const CKTypeRefPack& type_pack, loc_t def_loc);
934 CKConstantConstObs declare_constant(
const CIName& name, CKTypeObs type, CKIRConstantIntObs value, loc_t def_loc);
936 CKNamedObs find_constant_here(
const CIName& n);
937 bool conflicting_tag_enum(
const std::string& name);
938 bool conflicting_tag_struct(
const std::string& name);
939 bool find_idf_here_universal(
const CIName& n);
940 void dump_universal(CIOStream& os,
const std::string& indent)
const;
942 CINamedStorage< CKStructType> strts_;
943 CINamedStorage< CKEnumType> enmts_;
944 CINamedStorage< CKTypedef> typedefs_;
945 CINamedStorage< CKConstant> constants_;
957 class CKGlobalTable :
public CKUniversalTable {
965 return declare_struct_type_here(n, Context, decl_loc);
967 virtual CKStructTypeObs find_struct_type(
const CIName& n)
override {
return find_struct_type_here(n); }
970 return declare_enum_type_here(n, base_type, decl_loc);
972 virtual CKEnumTypeObs find_enum_type(
const CIName& n)
override {
return find_enum_type_here(n); }
976 CKFunctionConstObs find_function(
const CIName& n)
const;
980 bool conflicting_idf(
const CIName& n);
983 void dump(CIOStream& os)
const;
985 CINamedStorage< CKFunction> fncs_;
986 CINamedStorage< CKGlobalVar> vars_;
995 :
CKVar(type_pack, def_loc), address_(address), is_arg_(is_arg)
999 bool is_arg()
const {
return is_arg_; }
1009 class CKLocalTable :
public CKUniversalTable {
1011 CKLocalTable(CKAbstractScopeObs parent)
1012 : parent_scope_(parent)
1015 CKStructTypeObs declare_struct_type(
const CIName& n, CKIRContextRef Context, loc_t decl_loc);
1016 virtual CKStructTypeObs find_struct_type(
const CIName& n)
override;
1017 CKEnumTypeObs declare_enum_type(
const CIName& n, CKTypeObs base_type, loc_t decl_loc);
1018 virtual CKEnumTypeObs find_enum_type(
const CIName& n)
override;
1020 void varsFromArgs(CKIRBuilderRef builder, CKFunctionObs f,
const CKFunctionFormalPackArray& formal_packs);
1022 CKLocalVarObs varDefine(CKIRBuilderRef builder,
const CIName& name,
const CKTypeRefPack& type_pack, loc_t def_loc);
1024 virtual CKTypedefConstObs find_typedef(
const CIName& n)
const override;
1025 virtual CKNamedObs find(
const CIName& n)
override;
1026 CKNamedObs find_here(
const CIName& n);
1027 bool conflicting_idf(
const CIName& n);
1029 void dump(CIOStream& os,
const std::string & indent)
const;
1031 virtual CKLocalTableObs get_local()
override;
1033 CKLocalTableObs create_block();
1034 CKLocalTableObs parent_block()
const;
1037 CKAbstractScopeObs parent_scope_;
1038 CINamedStorage< CKLocalVar> vars_;
1039 std::vector< CKLocalTableOwner> block_scopes_;
1046 using CKTypeTableObs = CKTypeTable*;
1047 using CKGlobalTableObs = CKGlobalTable*;
1048 using CKGlobalTableConstObs =
const CKGlobalTable*;
1051 CKTables(CKIREnvironmentObs irenv);
1058 CKTypeTableObs typetable()
1063 CKGlobalTableObs globtable()
1068 CKGlobalTableConstObs globtable()
const
1073 void dump_tables(std::ostream& os)
const;
1075 void dump_ir_module(std::ostream& os)
const;
1077 std::error_code write_bitcode_module(
const std::string& fname)
const;
1079 CKIRDataLayoutObs data_layout()
const
1081 return data_layout_;
1085 void declare_library();
1087 CKIREnvironmentObs irenv_;
1089 CKIRDataLayoutObs data_layout_;
1091 CKTypeTable typetable_;
1092 CKGlobalTable globtable_;
1095 using CKTablesObs = CKTables*;
1218 return llvm::Type::getInt64Ty(builder_.getContext());
1228 return CKGetInt8Constant(builder_.getContext(), v);
1234 return CKGetInt32Constant(builder_.getContext(), v);
1244 if (!current_function_ir_)
1246 return CKCreateBasicBlock(name, current_function_ir_);
1266 return CKGetInt32Constant(builder_.getContext(), CKGetTypeSize(data_layout_, type->
get_ir()));
1271 CKIRDataLayoutObs data_layout()
const
1273 return data_layout_;
1276 bool conflicting_idf(
const std::string& name);
1277 bool conflicting_idf_function(
const std::string& name, CKFunctionTypeObs type);
1278 bool conflicting_tag_enum(
const std::string& name);
1279 bool conflicting_tag_struct(
const std::string& name);
1282 CKTypeTableObs typetable_;
1283 CKGlobalTableObs globtable_;
1284 CKIRModuleObs module_;
1285 CKLocalTableObs loctable_;
1286 std::unique_ptr<CKLocalTable> dummy_loctable_;
1288 CKFunctionObs current_function_;
1289 CKIRFunctionObs current_function_ir_;
1290 CKIRBuilder alloca_builder_;
1291 CKIRBuilder builder_;
1292 CKIRBasicBlockObs start_bb_;
1293 CKIRDataLayoutObs data_layout_;
1300 inline std::size_t std::hash<cecko::CKTypeObs>::operator()(
const cecko::CKTypeObs& a)
const
1302 return cecko::compute_hash(a->hash());
1305 inline std::size_t std::hash<cecko::CKTypeRefPack>::operator()(
const cecko::CKTypeRefPack& a)
const
llvm::BasicBlock * CKIRBasicBlockObs
Definition: ckir.hpp:97
llvm::Type * CKIRTypeObs
Definition: ckir.hpp:80
llvm::ConstantInt * CKIRConstantIntObs
Definition: ckir.hpp:91
llvm::AllocaInst * CKIRAllocaInstObs
Definition: ckir.hpp:99
llvm::Module * CKIRModuleObs
Definition: ckir.hpp:93
llvm::LLVMContext & CKIRContextRef
Definition: ckir.hpp:78
llvm::Function * CKIRFunctionObs
Definition: ckir.hpp:95
llvm::Constant * CKIRConstantObs
Definition: ckir.hpp:90
llvm::FunctionType * CKIRFunctionTypeObs
Definition: ckir.hpp:82
llvm::APInt CKIRAPInt
Definition: ckir.hpp:76
CKIRBuilder * CKIRBuilderObs
Definition: ckir.hpp:103
llvm::StructType * CKIRStructTypeObs
Definition: ckir.hpp:81
llvm::Value * CKIRValueObs
Definition: ckir.hpp:86
CKIRBuilder & CKIRBuilderRef
Definition: ckir.hpp:102
std::vector< CKFunctionFormalPack > CKFunctionFormalPackArray
Temporary array of additional function argument descriptors (CKFunctionFormalPack)
Definition: cktables.hpp:891
const CKConstant * CKConstantConstObs
Pointer to an enumeration constant descriptor (CKConstant)
Definition: cktables.hpp:580
CKEnumType * CKEnumTypeObs
Enumeration type descriptor (CKEnumType)
Definition: cktables.hpp:686
const CKTypedef * CKTypedefConstObs
Typedef descriptor (CKTypedef)
Definition: cktables.hpp:786
const CIAbstractType * CKTypeObs
Pointer to a type descriptor (CIAbstractType)
Definition: cktables.hpp:29
unsigned loc_t
Line number in the compiled source file.
Definition: cktables.hpp:24
std::vector< CKConstantConstObs > CKConstantObsVector
Temporary vector of enumeration constant descriptors (CKConstantConstObs)
Definition: cktables.hpp:585
std::vector< CKStructItem > CKStructItemArray
A temporary array of struct element descriptors (CKStructItem)
Definition: cktables.hpp:535
std::optional< CIName > CINameOpt
Optional (function argument) name.
Definition: cktables.hpp:855
std::vector< CKTypeObs > CKTypeObsArray
Array of (function argument) type descriptors (CKTypeObs)
Definition: cktables.hpp:620
CKAbstractNamed * CKNamedObs
Pointer to a named-object (constant, variable, or function) descriptor (CKAbstractNamed)
Definition: cktables.hpp:756
std::string CIName
Identifier as represented in the attribute of a IDF/TYPEIDF token.
Definition: cktables.hpp:138
Abstract type descriptor.
Definition: cktables.hpp:281
virtual bool is_bool() const
Built-in "_Bool" type.
Definition: cktables.hpp:298
virtual bool is_struct() const
Struct type.
Definition: cktables.hpp:305
virtual bool is_char() const
Built-in "char" type.
Definition: cktables.hpp:299
virtual CKStructElementSafeObs find_struct_element(const CIName &) const
Find a struct type element by name.
Definition: cktables.hpp:341
virtual CKTypeSafeObs get_array_element_type() const
The element type of an array.
Definition: cktables.hpp:332
virtual bool is_pointer() const
Pointer type.
Definition: cktables.hpp:304
virtual CKTypeSafeObs get_function_arg_type(std::size_t ix) const
The selected argument type of a function type.
Definition: cktables.hpp:321
virtual bool is_void() const
Built-in "void" type.
Definition: cktables.hpp:297
virtual CKTypeRefSafePack get_pointer_points_to() const
The (optionally const) type a pointer type points to.
Definition: cktables.hpp:312
virtual bool is_array() const
Array type.
Definition: cktables.hpp:302
virtual CKIRTypeObs get_ir() const =0
Get LLVM type descriptor.
virtual std::size_t get_function_arg_count() const
The number of arguments of a function type.
Definition: cktables.hpp:323
virtual bool is_function() const
Function type.
Definition: cktables.hpp:303
virtual bool is_function_variadic() const
Check whether a function type is variadic.
Definition: cktables.hpp:325
virtual bool is_enum() const
Enumeration type.
Definition: cktables.hpp:301
virtual CKTypeSafeObs get_function_return_type() const
The return type of a function type.
Definition: cktables.hpp:319
virtual CKIRConstantIntObs get_array_size() const
The size of an array.
Definition: cktables.hpp:334
virtual CKIRConstantObs get_null_value() const
Get LLVM null value.
virtual bool is_int() const
Built-in "int" type.
Definition: cktables.hpp:300
The common base for all named objects.
Definition: cktables.hpp:191
const CIName & get_name() const
The name of the object.
Definition: cktables.hpp:200
Abstract named-object (constant, variable, or function) descriptor.
Definition: cktables.hpp:716
virtual bool is_var() const
Global or local variable.
Definition: cktables.hpp:729
virtual bool is_function() const
Function.
Definition: cktables.hpp:731
virtual CKTypeSafeObs get_type() const =0
Type of the named object.
virtual CKIRValueObs get_ir() const
The address of a variable, the value of a constant.
Definition: cktables.hpp:749
virtual bool is_constant() const
Enumeration constant.
Definition: cktables.hpp:733
virtual CKIRFunctionObs get_function_ir() const
The address of a function.
Definition: cktables.hpp:751
virtual bool is_const() const
Optional "const" flag on a variable.
Definition: cktables.hpp:742
Array type descriptor.
Definition: cktables.hpp:468
The built-in "_Bool" type.
Definition: cktables.hpp:378
The built-in "char" type.
Definition: cktables.hpp:396
Enumeration constant descriptor.
Definition: cktables.hpp:791
CKIRConstantIntObs get_constant_value() const
LLVM value of the enumeration constant.
Definition: cktables.hpp:807
Enumeration type descriptor.
Definition: cktables.hpp:588
bool is_defined() const
Check whether the type is already defined.
Definition: cktables.hpp:604
Function type descriptor.
Definition: cktables.hpp:623
Function descriptor.
Definition: cktables.hpp:894
Global variable descriptor.
Definition: cktables.hpp:837
The built-in "int" type.
Definition: cktables.hpp:417
Local variable descriptor.
Definition: cktables.hpp:991
Pointer type descriptor.
Definition: cktables.hpp:438
Struct element descriptor.
Definition: cktables.hpp:499
const CKTypeRefPack & get_type_pack() const
The (optionally const) type of a struct element.
Definition: cktables.hpp:510
unsigned int get_idx() const
LLVM index of a struct element.
Definition: cktables.hpp:512
Struct type descriptor.
Definition: cktables.hpp:538
bool is_defined() const
Check whether the struct type is already defined.
Definition: cktables.hpp:555
Typedef descriptor.
Definition: cktables.hpp:761
CKTypeRefSafePack get_type_pack() const
The type and the optional "const" represented by the typedef.
Definition: cktables.hpp:776
Common base of variable descriptors.
Definition: cktables.hpp:818
virtual bool is_const() const override
Optional "const" flag on a variable.
Definition: cktables.hpp:827
virtual bool is_var() const override
Global or local variable.
Definition: cktables.hpp:825
virtual CKTypeSafeObs get_type() const override
Type of the named object.
Definition: cktables.hpp:826
The built-in "void" type.
Definition: cktables.hpp:358
Semantic layer of compiler context.
Definition: cktables.hpp:1101
CKNamedSafeObs find(const CIName &n)
Find a named (constant, variable, or function) object.
void exit_function()
Signalize exiting of the compound statement of the definition of a function.
CKPtrTypeSafeObs get_pointer_type(const CKTypeRefPack &pack)
A pointer type descriptor.
Definition: cktables.hpp:1138
CKCharTypeSafeObs get_char_type() const
The built-in "char" type descriptor.
Definition: cktables.hpp:1129
CKTypedefConstSafeObs define_typedef(const CIName &name, const CKTypeRefPack &type_pack, loc_t loc)
Define a typedef.
CKIRBasicBlockObs create_basic_block(const std::string &name)
Create a new basic block in the current function.
Definition: cktables.hpp:1242
CKEnumTypeSafeObs declare_enum_type(const CIName &n, loc_t loc)
Reference or declare an enum type.
CKTypedefConstSafeObs find_typedef(const CIName &n) const
Find a typedef.
CKTypeSafeObs current_function_return_type()
The return type of the current function.
CKFunctionTypeSafeObs get_function_type(CKTypeObs ret_type, CKTypeObsArray arg_types, bool variadic=false)
A function type descriptor.
CKBoolTypeSafeObs get_bool_type() const
The built-in "_Bool" type descriptor.
Definition: cktables.hpp:1127
CKIntTypeSafeObs get_int_type() const
The built-in "int" type descriptor.
Definition: cktables.hpp:1131
CKStructTypeSafeObs declare_struct_type(const CIName &n, loc_t loc)
Reference or declare a struct type.
CKEnumTypeSafeObs define_enum_type_open(const CIName &n, loc_t loc)
Signalize entering the definition of the enum type named n.
CKIRBuilderObs builder()
The active builder for the currently open basic block (or inactive)
Definition: cktables.hpp:1254
CKIRConstantIntObs get_int8_constant(std::int_fast32_t v)
LLVM constant of type "char".
Definition: cktables.hpp:1226
CKIRTypeObs get_ir_int64()
LLVM representation of C-types "int64_t" and "uint64_t".
Definition: cktables.hpp:1216
CKArrayTypeSafeObs get_array_type(CKTypeObs element_type, CKIRConstantIntObs size)
An array type descriptor.
void define_enum_type_close(CKEnumTypeObs type, CKConstantObsVector items)
Signalize exiting the definition of the enum type type.
void define_var(const CIName &name, const CKTypeRefPack &type_pack, loc_t loc)
Define a global or local variable.
void enter_function(CKFunctionObs f, CKFunctionFormalPackArray pack, loc_t loc)
Signalize entering of the compound statement of the definition of the function f.
CKFunctionSafeObs declare_function(const CIName &n, CKTypeObs type, loc_t loc)
Declare a function (with or without body)
CKConstantConstSafeObs define_constant(const CIName &name, CKIRConstantIntObs value, loc_t loc)
Define an enumeration constant.
CKVoidTypeSafeObs get_void_type() const
The built-in "void" type descriptor.
Definition: cktables.hpp:1125
void define_struct_type_close(CKStructTypeObs type, const CKStructItemArray &items)
Signalize exiting the definition of the struct type type.
void exit_block()
Signalize exiting of a compound statement other than a function definition.
CKStructTypeSafeObs define_struct_type_open(const CIName &n, loc_t loc)
Signalize entering the definition of the struct type named n.
bool is_typedef(const CIName &n) const
Check whether the name is a typedef (for the lexer)
CKIRConstantIntObs get_int32_constant(std::int_fast32_t v)
LLVM constant of type "int".
Definition: cktables.hpp:1232
CKIRConstantIntObs get_type_size(CKTypeObs type) const
Size of a type in bytes.
Definition: cktables.hpp:1264
void enter_block()
Signalize entering of a compound statement other than a function definition.
Temporary struct element descriptor.
Definition: cktables.hpp:521
CKTypeRefPack pack
The (optionally const) type of a struct element.
Definition: cktables.hpp:527
CKStructItem(const CKTypeRefPack &p, CIName nm, loc_t l)
Construct from arguments.
Definition: cktables.hpp:523
loc_t loc
Definition line number.
Definition: cktables.hpp:531
CIName name
Name of a struct element.
Definition: cktables.hpp:529
Type descriptor with optional "const" flag.
Definition: cktables.hpp:240
bool is_const
Indicates the presence of the const flag.
Definition: cktables.hpp:252
CKTypeRefPack(CKTypeObs t, bool is_c)
Construct from the arguments.
Definition: cktables.hpp:248
CKTypeRefPack()
Construct as null.
Definition: cktables.hpp:243
CKTypeObs type
The type.
Definition: cktables.hpp:251
Type descriptor with optional "const" flag.
Definition: cktables.hpp:256
CKTypeRefSafePack(const CKTypeRefPack &tp)
Convert from unsafe pack.
Definition: cktables.hpp:268
CKTypeRefSafePack(CKTypeObs t, bool is_c)
Construct from the arguments.
Definition: cktables.hpp:264
bool is_const
Indicates the presence of the const flag.
Definition: cktables.hpp:277
CKTypeRefSafePack()
Construct as null.
Definition: cktables.hpp:259
CKTypeSafeObs type
The type.
Definition: cktables.hpp:276