chigraph  master
Systems programming language written for beginners in LLVM
LangModule.hpp
Go to the documentation of this file.
1 
4 #ifndef CHI_LANG_MODULE_HPP
5 #define CHI_LANG_MODULE_HPP
6 
7 #pragma once
8 
9 #include "chi/ChiModule.hpp"
10 #include "chi/Fwd.hpp"
11 
12 #include <unordered_map>
13 
14 namespace chi {
19  LangModule(Context& ctx);
20 
22  ~LangModule();
23 
24  Result nodeTypeFromName(boost::string_view name, const nlohmann::json& jsonData,
25  std::unique_ptr<NodeType>* toFill) override;
26 
27  DataType typeFromName(boost::string_view name) override;
28 
29  std::vector<std::string> nodeTypeNames() const override {
30  std::vector<std::string> ret;
31  ret.reserve(nodes.size());
32 
33  std::transform(nodes.begin(), nodes.end(), std::back_inserter(ret),
34  [](auto pair) { return pair.first; });
35 
36  return ret;
37  }
38 
39  std::vector<std::string> typeNames() const override {
40  return {"i32", "i1", "float", "i8*"}; // TODO: do i need more?
41  }
42 
43  Result addForwardDeclarations(llvm::Module& module) const override;
44 
45  Result generateModule(llvm::Module& /*module*/) override;
46 
47 private:
48  std::unordered_map<std::string,
49  std::function<std::unique_ptr<NodeType>(const nlohmann::json&, Result&)>>
50  nodes;
51  std::unordered_map<std::string, llvm::DIType*> mDebugTypes;
52 };
53 } // namespace chi
54 
55 #endif // CHI_LANG_MODULE_HPP
Result nodeTypeFromName(boost::string_view name, const nlohmann::json &jsonData, std::unique_ptr< NodeType > *toFill) override
Create a node type that is in the module from the name and json.
Definition: LangModule.cpp:847
Forward declares all the chigraph data types.
The module that provides built-in operations like literals, math operations, etc. ...
Definition: LangModule.hpp:16
std::vector< std::string > nodeTypeNames() const override
Get the possible node type names.
Definition: LangModule.hpp:29
~LangModule()
Destructor.
Definition: LangModule.cpp:863
std::vector< std::string > typeNames() const override
Get the possible DataType names.
Definition: LangModule.hpp:39
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Definition: ChiModule.hpp:24
Result addForwardDeclarations(llvm::Module &module) const override
Adds forward declartions for the functions in this module.
Definition: LangModule.cpp:910
DataType typeFromName(boost::string_view name) override
Get a DataType from the name.
Definition: LangModule.cpp:871
Result generateModule(llvm::Module &) override
Generate a llvm::Module from the module.
Definition: LangModule.cpp:912
Defines the ChiModule class.
The namespace where chigraph lives.
LangModule(Context &ctx)
Default constructor, usually called from Context::loadModule("lang")
Definition: LangModule.cpp:529
A type of data Loose wrapper around llvm::Type*, except it knows which ChiModule it&#39;s in and it embed...
Definition: DataType.hpp:17
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72