tipc
A TIP to LLVM compiler
ASTFunction.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ASTDeclNode.h"
4 #include "ASTDeclStmt.h"
5 #include "ASTNode.h"
6 #include "ASTStmt.h"
7 
11 class ASTFunction : public ASTNode {
12  std::shared_ptr<ASTDeclNode> DECL;
13  std::vector<std::shared_ptr<ASTDeclNode>> FORMALS;
14  std::vector<std::shared_ptr<ASTDeclStmt>> DECLS;
15  std::vector<std::shared_ptr<ASTStmt>> BODY;
16  bool ISPOLY;
17 
18 public:
19  std::vector<std::shared_ptr<ASTNode>> getChildren() override;
20  ASTFunction(std::shared_ptr<ASTDeclNode> DECL,
21  std::vector<std::shared_ptr<ASTDeclNode>> FORMALS,
22  const std::vector<std::shared_ptr<ASTDeclStmt>> &DECLS,
23  std::vector<std::shared_ptr<ASTStmt>> BODY, bool ISPOLY)
24  : DECL(DECL), FORMALS(FORMALS), DECLS(DECLS), BODY(BODY), ISPOLY(ISPOLY) {
25  }
26  ~ASTFunction() = default;
27  ASTDeclNode *getDecl() const { return DECL.get(); };
28  std::string getName() const { return DECL->getName(); };
29  bool isPoly() const { return ISPOLY; };
30  std::vector<ASTDeclNode *> getFormals() const;
31  std::vector<ASTDeclStmt *> getDeclarations() const;
32  std::vector<ASTStmt *> getStmts() const;
33  void accept(ASTVisitor *visitor) override;
34  llvm::Value *codegen() override;
35 
36 protected:
37  std::ostream &print(std::ostream &out) const override;
38 };
Class for declaring a name, e.g., function, parameter, variable.
Definition: ASTDeclNode.h:7
Class for defining the signature, local declarations, and a body of a function.
Definition: ASTFunction.h:11
std::vector< std::shared_ptr< ASTNode > > getChildren() override
Return all of the children for the node.
Definition: ASTFunction.cpp:47
ASTDeclNode * getDecl() const
Definition: ASTFunction.h:27
void accept(ASTVisitor *visitor) override
Visit the children of this node and apply the visitor.
Definition: ASTFunction.cpp:15
bool isPoly() const
Definition: ASTFunction.h:29
std::vector< ASTDeclStmt * > getDeclarations() const
Definition: ASTFunction.cpp:9
std::ostream & print(std::ostream &out) const override
Print an abbreviated shared string for the function.
Definition: ASTFunction.cpp:32
ASTFunction(std::shared_ptr< ASTDeclNode > DECL, std::vector< std::shared_ptr< ASTDeclNode >> FORMALS, const std::vector< std::shared_ptr< ASTDeclStmt >> &DECLS, std::vector< std::shared_ptr< ASTStmt >> BODY, bool ISPOLY)
Definition: ASTFunction.h:20
llvm::Value * codegen() override
Perform code generation and return an LLVM value the code.
Definition: CodeGenFunctions.cpp:336
std::vector< ASTStmt * > getStmts() const
Definition: ASTFunction.cpp:13
std::string getName() const
Definition: ASTFunction.h:28
~ASTFunction()=default
std::vector< ASTDeclNode * > getFormals() const
Definition: ASTFunction.cpp:5
Abstract base class for all AST nodes.
Definition: ASTNode.h:34
Base class for AST visitors.
Definition: ASTVisitor.h:23