Skip to content

Commit

Permalink
adding module support
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaylor committed May 8, 2023
1 parent 15760e3 commit e8db81b
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 99 deletions.
7 changes: 2 additions & 5 deletions backend/include/hpx/codegenvisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "symboltypes.hpp"
#include "programtree.hpp"

#include <ostream>
#include <string>
#include <unordered_map>
#include <variant>
Expand Down Expand Up @@ -72,13 +71,12 @@ struct CodegenVisitor {
ProgramTree & prgmTree,
chpl::uast::BuilderResult const& chapelBr,
std::string const& cppFilePathStr,
std::string const& chapelFilePathStr,
std::ostream & fstrm
std::string const& chapelFilePathStr
);

~CodegenVisitor() = default;

void generateApplicationHeader(std::filesystem::path const& chplpth);
void generateApplicationHeader(std::string const& chplpth, std::string const& prefix, std::fstream & os);

//template <typename Kind>
//void addSymbolEntry(char const* type);
Expand Down Expand Up @@ -110,7 +108,6 @@ struct CodegenVisitor {
std::size_t indent;
std::size_t scope;
std::string identifier;
std::ostream & fstrm_;
std::string cppFilePathStr;
std::string chplFilePathStr;
std::vector<bool> headers;
Expand Down
25 changes: 24 additions & 1 deletion backend/include/hpx/programtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ struct CoforallLoopExpression;
struct StatementList;
struct ScalarDeclarationExprExpression;

struct RecordDeclarationExpression;
struct ClassDeclarationExpression;
struct ModuleDeclarationExpression;

using Statement = std::variant<
std::monostate,
std::shared_ptr<StatementList>,
Expand All @@ -139,7 +143,10 @@ using Statement = std::variant<
std::shared_ptr<ConditionalExpression>,
std::shared_ptr<ForLoopExpression>,
std::shared_ptr<ForallLoopExpression>,
std::shared_ptr<CoforallLoopExpression>
std::shared_ptr<CoforallLoopExpression>,
std::shared_ptr<RecordDeclarationExpression>,
std::shared_ptr<ClassDeclarationExpression>,
std::shared_ptr<ModuleDeclarationExpression>
>;

struct StatementList {
Expand Down Expand Up @@ -242,6 +249,22 @@ struct CoforallLoopExpression : public ScopeExpression {
void emit(std::ostream & os) const;
};

struct RecordDeclarationExpression : public ScopeExpression {
Symbol symbol;
std::vector<Statement> statements;
std::string chplLine;

void emit(std::ostream & os) const;
};

struct ClassDeclarationExpression : public RecordDeclarationExpression {
void emit(std::ostream & os) const;
};

struct ModuleDeclarationExpression : public RecordDeclarationExpression {
void emit(std::ostream & os) const;
};

struct ProgramTree {

std::vector<Statement> statements;
Expand Down
32 changes: 24 additions & 8 deletions backend/include/hpx/symboltypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct tuple_kind;
struct kind_node_type;
struct kind_node_term_type {};
struct expr_kind {};
struct module_kind;

using kind_types = std::variant<
std::monostate,
Expand All @@ -127,6 +128,7 @@ using kind_types = std::variant<
std::shared_ptr<associative_kind>,
std::shared_ptr<tuple_kind>,
std::shared_ptr<kind_node_type>,
std::shared_ptr<module_kind>,
kind_node_term_type,
expr_kind
>;
Expand Down Expand Up @@ -161,15 +163,27 @@ struct tuple_kind {
std::vector<kind_types> kinds;
};

enum class ScopeKind : std::uint8_t {
Module = 0,
ForLoop = 1,
ForallLoop = 2,
CoforallLoop = 3,
Loop = 4,
Function = 5,
Lambda = 6,
Record = 7,
Class = 8
};

struct SymbolBase {
kind_types kind;
std::string identifier;
std::vector<uast::AstNode const*> literal;
int kindqualifier;
bool isConfig;
// std::size_t parentModule;
std::size_t scopeId;
};
// std::size_t parentModule;

struct Symbol : public SymbolBase {
};
Expand Down Expand Up @@ -204,6 +218,7 @@ struct SymbolTable {

struct SymbolTableNode {
std::size_t id;
// ScopeKind kind;
std::map<std::string, Symbol> entries;
std::vector<SymbolTableNodeImpl> children;
SymbolTableNodeImpl parent;
Expand Down Expand Up @@ -292,15 +307,16 @@ struct itrfunc_kind : public func_kind {
};

struct record_kind {
std::vector<std::string> identifiers;
std::vector<kind_types> kinds;
SymbolTable symbolTable;
std::uint64_t lutId;
std::string symbolTableSignature;
std::vector<Symbol> members;
};

struct class_kind {
std::vector<std::string> identifiers;
std::vector<kind_types> kinds;
SymbolTable symbolTable;
struct class_kind : record_kind {
std::vector<Symbol> lineage;
};

struct module_kind : funcbase_kind {
};

} /* namespace hpx */ } /* namespace visitors */ } /* namespace ast */ } /* namespace chpl */
Expand Down
Loading

0 comments on commit e8db81b

Please sign in to comment.