diff --git a/Makefile b/Makefile index 5698fd42..dd13d7b4 100644 --- a/Makefile +++ b/Makefile @@ -194,9 +194,9 @@ YACC=bison -d -v -t ########################################################################### -CXX_SRC=ast.cpp builtins.cpp cbackend.cpp ctx.cpp decl.cpp expr.cpp func.cpp test_class_of.cpp \ +CXX_SRC=ast.cpp builtins.cpp cbackend.cpp ctx.cpp decl.cpp expr.cpp func.cpp \ ispc.cpp llvmutil.cpp main.cpp module.cpp opt.cpp stmt.cpp sym.cpp \ - type.cpp util.cpp + type.cpp util.cpp test_class_of.cpp HEADERS=ast.h builtins.h ctx.h decl.h expr.h func.h ispc.h llvmutil.h module.h \ opt.h stmt.h sym.h type.h util.h TARGETS=avx2-i64x4 avx11-i64x4 avx1-i64x4 avx1 avx1-x2 avx11 avx11-x2 avx2 avx2-x2 \ @@ -261,9 +261,11 @@ doxygen: ispc: print_llvm_src dirs $(OBJS) @echo Creating ispc executable - @$(CXX) $(OPT) $(LDFLAGS) -o $@ $(OBJS) $(ISPC_LIBS) + @$(CXX) $(OPT) $(LDFLAGS) -o $@ $(filter-out objs/test_class_of.o, $(OBJS)) $(ISPC_LIBS) + +tcof: print_llvm_src dirs $(OBJS) @echo Creating test_class_of executable - @$(CXX) $(OPT) $(LDFLAGS) -o tcexe $(OBJS) $(ISPC_LIBS) + @$(CXX) $(OPT) $(LDFLAGS) -o tcof $(filter-out objs/main.o, $(OBJS)) $(ISPC_LIBS) # Use clang as a default compiler, instead of gcc # This is default now. diff --git a/ast.h b/ast.h index e4a5d73f..20442b8d 100644 --- a/ast.h +++ b/ast.h @@ -79,8 +79,51 @@ public: /** An enumeration for keeping track of the concrete subclass of Value that is actually instantiated.*/ enum ASTNodeTy { - ExprID, - StmtID + /* For classes inherited from Expr */ + AddressOfExprID, + AssignExprID, + BinaryExprID, + ConstExprID, + DerefExprID, + PtrDerefExprID, + RefDerefExprID, + ExprListID, + FunctionCallExprID, + FunctionSymbolExprID, + IndexExprID, + StructMemberExprID, + VectorMemberExprID, + NewExprID, + NullPointerExprID, + ReferenceExprID, + SelectExprID, + SizeOfExprID, + SymbolExprID, + SyncExprID, + TypeCastExprID, + UnaryExprID, + /* For classes inherited from Stmt */ + AssertStmtID, + BreakStmtID, + CaseStmtID, + ContinueStmtID, + DeclStmtID, + DefaultStmtID, + DeleteStmtID, + DoStmtID, + ExprStmtID, + ForeachActiveStmtID, + ForeachStmtID, + ForeachUniqueStmtID, + ForStmtID, + GotoStmtID, + IfStmtID, + LabeledStmtID, + PrintStmtID, + ReturnStmtID, + StmtListID, + SwitchStmtID, + UnmaskedStmtID }; /** Return an ID for the concrete type of this object. This is used to @@ -93,6 +136,9 @@ public: static inline bool classof(ASTNode const*) { return true; } }; + + + class AST { public: /** Add the AST for a function described by the given declaration diff --git a/expr.h b/expr.h index 89b987f5..5c053f0d 100644 --- a/expr.h +++ b/expr.h @@ -227,8 +227,8 @@ public: */ class ExprList : public Expr { public: - ExprList(SourcePos p) : Expr(p) { } - ExprList(Expr *e, SourcePos p) : Expr(p) { exprs.push_back(e); } + ExprList(SourcePos p) : Expr(p, ExprListID) { } + ExprList(Expr *e, SourcePos p) : Expr(p, ExprListID) { exprs.push_back(e); } llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; @@ -658,7 +658,7 @@ private: proceeding). */ class SyncExpr : public Expr { public: - SyncExpr(SourcePos p) : Expr(p) { } + SyncExpr(SourcePos p) : Expr(p, SyncExprID) { } llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; @@ -672,7 +672,7 @@ public: /** @brief An expression that represents a NULL pointer. */ class NullPointerExpr : public Expr { public: - NullPointerExpr(SourcePos p) : Expr(p) { } + NullPointerExpr(SourcePos p) : Expr(p, NullPointerExprID) { } llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; diff --git a/module.cpp b/module.cpp index d54ff6c8..4c64392f 100644 --- a/module.cpp +++ b/module.cpp @@ -1905,8 +1905,7 @@ std::string emitOffloadParamStruct(const std::string ¶mStructName, if (!orgParamType->IsConstType()) { Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n"); } - const ReferenceType *refType - = llvm::dyn_cast(orgParamType); + const ReferenceType *refType = static_cast(orgParamType); paramType = refType->GetReferenceTarget()->GetAsNonConstType(); } else { paramType = orgParamType->GetAsNonConstType(); @@ -2024,8 +2023,7 @@ Module::writeDevStub(const char *fn) if (!orgParamType->IsConstType()) { Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n"); } - const ReferenceType *refType - = llvm::dyn_cast(orgParamType); + const ReferenceType *refType = static_cast(orgParamType); paramType = refType->GetReferenceTarget()->GetAsNonConstType(); } else { paramType = orgParamType->GetAsNonConstType(); diff --git a/stmt.cpp b/stmt.cpp index 224646e4..b96dd55c 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -82,7 +82,7 @@ Stmt::Optimize() { // ExprStmt ExprStmt::ExprStmt(Expr *e, SourcePos p) - : Stmt(p) { + : Stmt(p, ExprStmtID) { expr = e; } @@ -126,7 +126,7 @@ ExprStmt::EstimateCost() const { // DeclStmt DeclStmt::DeclStmt(const std::vector &v, SourcePos p) - : Stmt(p), vars(v) { + : Stmt(p, DeclStmtID), vars(v) { } @@ -523,7 +523,7 @@ DeclStmt::EstimateCost() const { // IfStmt IfStmt::IfStmt(Expr *t, Stmt *ts, Stmt *fs, bool checkCoherence, SourcePos p) - : Stmt(p), test(t), trueStmts(ts), falseStmts(fs), + : Stmt(p, IfStmtID), test(t), trueStmts(ts), falseStmts(fs), doAllCheck(checkCoherence && !g->opt.disableCoherentControlFlow) { } @@ -1017,7 +1017,7 @@ lHasVaryingBreakOrContinue(Stmt *stmt) { DoStmt::DoStmt(Expr *t, Stmt *s, bool cc, SourcePos p) - : Stmt(p), testExpr(t), bodyStmts(s), + : Stmt(p, DoStmtID), testExpr(t), bodyStmts(s), doCoherentCheck(cc && !g->opt.disableCoherentControlFlow) { } @@ -1193,7 +1193,7 @@ DoStmt::Print(int indent) const { // ForStmt ForStmt::ForStmt(Stmt *i, Expr *t, Stmt *s, Stmt *st, bool cc, SourcePos p) - : Stmt(p), init(i), test(t), step(s), stmts(st), + : Stmt(p, ForStmtID), init(i), test(t), step(s), stmts(st), doCoherentCheck(cc && !g->opt.disableCoherentControlFlow) { } @@ -1387,7 +1387,7 @@ ForStmt::Print(int indent) const { // BreakStmt BreakStmt::BreakStmt(SourcePos p) - : Stmt(p) { + : Stmt(p, BreakStmtID) { } @@ -1425,7 +1425,7 @@ BreakStmt::Print(int indent) const { // ContinueStmt ContinueStmt::ContinueStmt(SourcePos p) - : Stmt(p) { + : Stmt(p, ContinueStmtID) { } @@ -1466,7 +1466,7 @@ ForeachStmt::ForeachStmt(const std::vector &lvs, const std::vector &se, const std::vector &ee, Stmt *s, bool t, SourcePos pos) - : Stmt(pos), dimVariables(lvs), startExprs(se), endExprs(ee), isTiled(t), + : Stmt(pos, ForeachStmtID), dimVariables(lvs), startExprs(se), endExprs(ee), isTiled(t), stmts(s) { } @@ -2223,7 +2223,7 @@ ForeachStmt::Print(int indent) const { // ForeachActiveStmt ForeachActiveStmt::ForeachActiveStmt(Symbol *s, Stmt *st, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, ForeachActiveStmtID) { sym = s; stmts = st; } @@ -2410,7 +2410,7 @@ ForeachActiveStmt::EstimateCost() const { ForeachUniqueStmt::ForeachUniqueStmt(const char *iterName, Expr *e, Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, ForeachUniqueStmtID) { sym = m->symbolTable->LookupVariable(iterName); expr = e; stmts = s; @@ -2678,7 +2678,7 @@ lCheckMask(Stmt *stmts) { CaseStmt::CaseStmt(int v, Stmt *s, SourcePos pos) - : Stmt(pos), value(v) { + : Stmt(pos, CaseStmtID), value(v) { stmts = s; } @@ -2716,7 +2716,7 @@ CaseStmt::EstimateCost() const { // DefaultStmt DefaultStmt::DefaultStmt(Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, DefaultStmtID) { stmts = s; } @@ -2754,7 +2754,7 @@ DefaultStmt::EstimateCost() const { // SwitchStmt SwitchStmt::SwitchStmt(Expr *e, Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, SwitchStmtID) { expr = e; stmts = s; } @@ -2954,7 +2954,7 @@ SwitchStmt::EstimateCost() const { // UnmaskedStmt UnmaskedStmt::UnmaskedStmt(Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, UnmaskedStmtID) { stmts = s; } @@ -3008,7 +3008,7 @@ UnmaskedStmt::EstimateCost() const { // ReturnStmt ReturnStmt::ReturnStmt(Expr *e, SourcePos p) - : Stmt(p), expr(e) { + : Stmt(p, ReturnStmtID), expr(e) { } @@ -3075,7 +3075,7 @@ ReturnStmt::Print(int indent) const { // GotoStmt GotoStmt::GotoStmt(const char *l, SourcePos gotoPos, SourcePos ip) - : Stmt(gotoPos) { + : Stmt(gotoPos, GotoStmtID) { label = l; identifierPos = ip; } @@ -3151,7 +3151,7 @@ GotoStmt::EstimateCost() const { // LabeledStmt LabeledStmt::LabeledStmt(const char *n, Stmt *s, SourcePos p) - : Stmt(p) { + : Stmt(p, LabeledStmtID) { name = n; stmt = s; } @@ -3253,7 +3253,7 @@ StmtList::Print(int indent) const { // PrintStmt PrintStmt::PrintStmt(const std::string &f, Expr *v, SourcePos p) - : Stmt(p), format(f), values(v) { + : Stmt(p, PrintStmtID), format(f), values(v) { } /* Because the pointers to values that are passed to __do_print() are all @@ -3463,7 +3463,7 @@ PrintStmt::EstimateCost() const { // AssertStmt AssertStmt::AssertStmt(const std::string &msg, Expr *e, SourcePos p) - : Stmt(p), message(msg), expr(e) { + : Stmt(p, AssertStmtID), message(msg), expr(e) { } @@ -3542,7 +3542,7 @@ AssertStmt::EstimateCost() const { // DeleteStmt DeleteStmt::DeleteStmt(Expr *e, SourcePos p) - : Stmt(p) { + : Stmt(p, DeleteStmtID) { expr = e; } diff --git a/stmt.h b/stmt.h index fb34c801..ba5a29b6 100644 --- a/stmt.h +++ b/stmt.h @@ -48,7 +48,7 @@ */ class Stmt : public ASTNode { public: - Stmt(SourcePos p) : ASTNode(p) { } + Stmt(SourcePos p, unsigned scid) : ASTNode(p, scid) { } /** Emit LLVM IR for the statement, using the FunctionEmitContext to create the necessary instructions. @@ -411,7 +411,7 @@ public: */ class StmtList : public Stmt { public: - StmtList(SourcePos p) : Stmt(p) { } + StmtList(SourcePos p) : Stmt(p, StmtListID) { } void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const;