diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1f514a6f4..5f9ef567b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -283,7 +283,7 @@ jobs: - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 with: - version: v1.21.0 + version: v1.21.2 args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.run/spice.run.xml b/.run/spice.run.xml index 1cd636519..87b6b05a1 100644 --- a/.run/spice.run.xml +++ b/.run/spice.run.xml @@ -1,5 +1,5 @@ - + diff --git a/Dockerfile b/Dockerfile index 8c30b321c..0896147da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ENV TERM="xterm-256color" ENV SPICE_DOCKERIZED=1 RUN apk update && apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main --no-cache \ - build-base ncurses-dev libc6-compat gcompat zstd-dev clang lld && rm -rf /var/cache/apk/* + build-base ncurses-dev libc6-compat gcompat zstd-dev gcc clang lld && rm -rf /var/cache/apk/* RUN ln -sf /usr/lib/libncursesw.so.6 /usr/lib/libtinfo.so.6 COPY std/ /usr/lib/spice/std/ diff --git a/docs/docs/language/casts.md b/docs/docs/language/casts.md index 182a783ec..03fc3e451 100644 --- a/docs/docs/language/casts.md +++ b/docs/docs/language/casts.md @@ -10,7 +10,8 @@ destination type. Casting an int to the short data type: ```spice -short shortVar = (short) 12; +int intVar = 12; +short shortVar = (short) intVar; ``` Example for casting for a function call: diff --git a/src-bootstrap/CliInterface.spice b/src-bootstrap/CliInterface.spice index 0d5dcfbc1..997305b38 100644 --- a/src-bootstrap/CliInterface.spice +++ b/src-bootstrap/CliInterface.spice @@ -45,7 +45,7 @@ public type CliInterface struct { public bool shouldExecute = false } -public p CliInterface.createInterface() { +public p CliInterface.create() { this.cliParser = CliParser("Spice", "Spice programming language"); this.cliParser.setFooter("(c) Marc Auberer 2021-2023"); diff --git a/src-bootstrap/CompilerPass.spice b/src-bootstrap/CompilerPass.spice new file mode 100644 index 000000000..3cbc82aa6 --- /dev/null +++ b/src-bootstrap/CompilerPass.spice @@ -0,0 +1,20 @@ +import "global/GlobalResourceManager"; + +type ICompilerPass interface { + p changeToScope(Scope*, const ScopeType&); + p changeToScope(const String&, const ScopeType&); + p changeToParentScope(ScopeType); +} + +type CompilerPass struct : ICompilerPass { + GlobalResourceManager& globalResourceManager + const CliOptions& cliOptions + SourceFile* sourceFile + Scope* rootScope + unsigned long manIdx = 0 + Scope* currentScope +} + +p CompilerPass.ctor(GlobalResourceManager& resourceManager, SourceFile* sourceFile) { + +} \ No newline at end of file diff --git a/src-bootstrap/analyzer/analyzer.spice b/src-bootstrap/analyzer/analyzer.spice deleted file mode 100644 index c1496b6e8..000000000 --- a/src-bootstrap/analyzer/analyzer.spice +++ /dev/null @@ -1,5 +0,0 @@ -// Imports - -public type Analyzer struct { - -} \ No newline at end of file diff --git a/src-bootstrap/ast/ASTBuilder.spice b/src-bootstrap/ast/ASTBuilder.spice new file mode 100644 index 000000000..e72e03060 --- /dev/null +++ b/src-bootstrap/ast/ASTBuilder.spice @@ -0,0 +1,14 @@ +import "../CompilerPass"; +import "../SourceFile"; +import "SpiceVisitor"; + +type ASTBuilder struct : ICompilerPass, SpiceVisitor { + CompilerPass compilerPass + const FilePath& filePath + Stack parentStack +} + +p ASTBuilder.ctor(GlobalResourceManager& resourceManager, SourceFile* sourceFile = nil) { + this.compilerPass = CompilerPass(resourceManager, sourceFile); + this.resourceManager = resourceManager; +} \ No newline at end of file diff --git a/src-bootstrap/ast/AbstractAstVisitor.spice b/src-bootstrap/ast/AbstractAstVisitor.spice index d9ff9e19d..46adbb37d 100644 --- a/src-bootstrap/ast/AbstractAstVisitor.spice +++ b/src-bootstrap/ast/AbstractAstVisitor.spice @@ -1,6 +1,6 @@ import "std/type/any"; -public type AbstractAstVisitor interface { +public type IAbstractAstVisitor interface { f visitEntry(EntryNode*); f visitMainFctDef(EntryNode*); f visitFctDef(EntryNode*); diff --git a/src-bootstrap/ast/AstNodes.spice b/src-bootstrap/ast/AstNodes.spice index 235303d90..e527f40bd 100644 --- a/src-bootstrap/ast/AstNodes.spice +++ b/src-bootstrap/ast/AstNodes.spice @@ -1,12 +1,11 @@ // Std imports -import "std/type/Any" as any; -import "std/data/Vector" as vec; -import "std/type/long" as longTy; +import "std/type/Any"; +import "std/data/Vector"; // Own imports -import "AbstractAstVisitor" as vis; -import "../util/CodeLoc" as codeclLoc; -import "../symbol/SymbolType" as st; +import "AbstractAstVisitor"; +import "../util/CodeLoc"; +import "../symbol/SymbolType"; /** * Saves a constant value for an AST node to realize features like array-out-of-bounds checks @@ -18,45 +17,490 @@ public type CompileTimeValue struct { long longValue byte byteValue char charValue - char *stringValue + string stringValue bool boolValue } public type Visitable interface { - f accept(vis::AbstractAstVisitor*); + f accept(IAbstractAstVisitor*); } -// =========================================================== AstNode =========================================================== +// =========================================================== ASTNode =========================================================== -public type AstNode struct : Visitable { +public type ASTNode struct : IVisitable { AstNode* parent - vec::Vector children - const cl::CodeLoc codeLoc + Vector children + const CodeLoc codeLoc string errorMessage - unsigned long manIdx - vec::Vector symbolTypes + Vector symbolTypes CompileTimeValue compileTimeValue string compileTimeStringValue - bool hasDirectCompileTimeValue + bool hasDirectCompileTimeValue = false + bool unreachable = false + Vector> opFct // Operator overloading functions } -p AstNode.ctor(AstNode *parent, cl::CodeLoc codeLoc) { +p AstNode.ctor(AstNode *parent, CodeLoc codeLoc) { this.parent = parent; this.codeLoc = codeLoc; - this.manIdx = longTy::MAX_VALUE; - this.hasDirectCompileTimeValue = false; } -public f AstNode.accept(vis::AbstractAstVisitor* _) { +public f AstNode.accept(AbstractAstVisitor* _) { assert false; // Please override at child level } // ========================================================== EntryNode ========================================================== -public type AstEntryNode struct : Visitable { - AstNode astNode +public type ASTEntryNode struct : ASTNode { + +} + +// ======================================================== MainFctDefNode ======================================================= + +public type ASTMainFctDefNode struct : ASTNode { + +} + +// ========================================================= FctNameNode ========================================================= + +public type ASTFctNameNode struct : ASTNode { + +} + +// ========================================================== FctDefNode ========================================================= + +public type ASTFctDefNode struct : ASTNode { + +} + +// ========================================================== ProcDefNode ======================================================== + +public type ASTProcDefNode struct : ASTNode { + +} + +// ========================================================= StructDefNode ======================================================= + +public type ASTStructDefNode struct : ASTNode { + +} + +// ======================================================== InterfaceDefNode ===================================================== + +public type ASTInterfaceDefNode struct : ASTNode { + +} + +// ========================================================== EnumDefNode ======================================================== + +public type ASTEnumDefNode struct : ASTNode { + +} + +// ======================================================= GenericTypeDefNode ==================================================== + +public type ASTGenericTypeDefNode struct : ASTNode { + +} + +// ========================================================== AliasDefNode ======================================================= + +public type ASTAliasDefNode struct : ASTNode { + +} + +// ======================================================== GlobalVarDefNode ===================================================== + +public type ASTGlobalVarDefNode struct : ASTNode { + +} + +// ========================================================== ExtDeclNode ======================================================== + +public type ASTExtDeclNode struct : ASTNode { + +} + +// ========================================================== UnsafeBlockNode ======================================================== + +public type ASTUnsafeBlockNode struct : ASTNode { + +} + +// ========================================================== ForLoopNode ======================================================== + +public type ASTForLoopNode struct : ASTNode { + +} + +// ======================================================== ForeachLoopNode ====================================================== + +public type ASTForeachLoopNode struct : ASTNode { + +} + +// ========================================================= WhileLoopNode ======================================================= + +public type ASTWhileLoopNode struct : ASTNode { + +} + +// ======================================================== DoWhileLoopNode ====================================================== + +public type ASTDoWhileLoopNode struct : ASTNode { + +} + +// ========================================================== IfStmtNode ======================================================== + +public type ASTIfStmtNode struct : ASTNode { + +} + +// ========================================================== ElseStmtNode ======================================================= + +public type ASTElseStmtNode struct : ASTNode { + +} + +// ===================================================== AnonymousBlockStmtNode ================================================== + +public type ASTAnonymousBlockStmtNode struct : ASTNode { + +} + +// ========================================================== StmtLstNode ======================================================== + +public type ASTStmtLstNode struct : ASTNode { + +} + +// ========================================================== TypeLstNode ======================================================== + +public type ASTTypeLstNode struct : ASTNode { + +} + +// ======================================================== TypeAltsLstNode ====================================================== + +public type ASTTypeAltsLstNode struct : ASTNode { + +} + +// ========================================================== ParamLstNode ======================================================= + +public type ASTParamLstNode struct : ASTNode { + +} + +// =========================================================== ArgLstNode ======================================================== + +public type ASTArgLstNode struct : ASTNode { + +} + +// ======================================================== EnumItemLstNode ====================================================== + +public type ASTEnumItemLstNode struct : ASTNode { + +} + +// ========================================================== EnumItemNode ======================================================= + +public type ASTEnumItemNode struct : ASTNode { + +} + +// ========================================================== FieldLstNode ======================================================= + +public type ASTFieldLstNode struct : ASTNode { + +} + +// =========================================================== FieldNode ========================================================= + +public type ASTFieldNode struct : ASTNode { + +} + +// ========================================================= SignatureNode ======================================================= + +public type ASTSignatureNode struct : ASTNode { + +} + +// ============================================================ StmtNode ========================================================= + +public type ASTStmtNode struct : ASTNode { + +} + +// ========================================================== DeclStmtNode ======================================================= + +public type ASTDeclStmtNode struct : ASTNode { + +} + +// ======================================================== SpecifierLstNode ===================================================== + +public type ASTSpecifierLstNode struct : ASTNode { + +} + +// ========================================================= SpecifierNode ======================================================= + +public type ASTSpecifierNode struct : ASTNode { + +} + +// ========================================================== ModAttrNode ======================================================== + +public type ASTModAttrNode struct : ASTNode { + +} + +// ========================================================== FctAttrNode ======================================================== + +public type ASTFctAttrNode struct : ASTNode { + +} + +// ========================================================== AttrLstNode ======================================================== + +public type ASTAttrLstNode struct : ASTNode { + +} + +// ============================================================ AttrNode ========================================================= + +public type ASTAttrNode struct : ASTNode { + } -public p AstEntryNode.ctor() { +// ========================================================= ImportStmtNode ====================================================== + +public type ASTImportStmtNode struct : ASTNode { + +} + +// ========================================================= ReturnStmtNode ====================================================== + +public type ASTReturnStmtNode struct : ASTNode { + +} + +// ========================================================= BreakStmtNode ======================================================= + +public type ASTBreakStmtNode struct : ASTNode { + +} + +// ======================================================== ContinueStmtNode ===================================================== + +public type ASTContinueStmtNode struct : ASTNode { + +} + +// ========================================================= AssertStmtNode ====================================================== + +public type ASTAssertStmtNode struct : ASTNode { + +} + +// ========================================================= PrintfCallNode ======================================================= + +public type ASTPrintfCallNode struct : ASTNode { + +} + +// ========================================================= SizeofCallNode ====================================================== + +public type ASTSizeofCallNode struct : ASTNode { + +} + +// ======================================================== AlignofCallNode ====================================================== + +public type ASTAlignofCallNode struct : ASTNode { + +} + +// ========================================================== LenCallNode ======================================================== + +public type ASTLenCallNode struct : ASTNode { + +} + +// ========================================================= PanicCallNode ======================================================= + +public type ASTPanicCallNode struct : ASTNode { + +} + +// ========================================================= AssignExprNode ======================================================= + +public type ASTAssignExprNode struct : ASTNode { + +} + +// ======================================================== TernaryExprNode ====================================================== + +public type ASTTernaryExprNode struct : ASTNode { + +} + +// ======================================================= LogicalOrExprNode ===================================================== + +public type ASTLogicalOrExprNode struct : ASTNode { + +} + +// ======================================================= LogicalAndExprNode ==================================================== + +public type ASTLogicalAndExprNode struct : ASTNode { + +} + +// ======================================================= BitwiseOrExprNode ===================================================== + +public type ASTBitwiseOrExprNode struct : ASTNode { + +} + +// ======================================================= BitwiseXorExprNode ==================================================== + +public type ASTBitwiseXorExprNode struct : ASTNode { + +} + +// ======================================================= BitwiseAndExprNode ==================================================== + +public type ASTBitwiseAndExprNode struct : ASTNode { + +} + +// ======================================================== EqualityExprNode ===================================================== + +public type ASTEqualityExprNode struct : ASTNode { + +} + +// ======================================================= RelationalExprNode ==================================================== + +public type ASTRelationalExprNode struct : ASTNode { + +} + +// ========================================================= ShiftExprNode ======================================================= + +public type ASTShiftExprNode struct : ASTNode { + +} + +// ======================================================== AdditiveExprNode ===================================================== + +public type ASTAdditiveExprNode struct : ASTNode { + +} + +// ===================================================== MultiplicativeExprNode ================================================== + +public type ASTMultiplicativeExprNode struct : ASTNode { + +} + +// ========================================================== CastExprNode ======================================================= + +public type ASTCastExprNode struct : ASTNode { + +} + +// ====================================================== PrefixUnaryExprNode ==================================================== + +public type ASTPrefixUnaryExprNode struct : ASTNode { + +} + +// ====================================================== PostfixUnaryExprNode =================================================== + +public type ASTPostfixUnaryExprNode struct : ASTNode { + +} + +// ========================================================= AtomicExprNode ====================================================== + +public type ASTAtomicExprNode struct : ASTNode { + +} + +// =========================================================== ValueNode ========================================================= + +public type ASTValueNode struct : ASTNode { + +} + +// ======================================================= PrimitiveValueNode ==================================================== + +public type ASTPrimitiveValueNode struct : ASTNode { + +} + +// ========================================================== FctCallNode ======================================================== + +public type ASTFctCallNode struct : ASTNode { + +} + +// ==================================================== ArrayInitializationNode ================================================== + +public type ASTArrayInitializationNode struct : ASTNode { + +} + +// ==================================================== StructInstantiationNode ================================================== + +public type ASTStructInstantiationNode struct : ASTNode { + +} + +// ========================================================= LambdaFuncNode ====================================================== + +public type ASTLambdaFuncNode struct : ASTNode { + +} + +// ========================================================= LambdaProcNode ====================================================== + +public type ASTLambdaProcNode struct : ASTNode { + +} + +// ========================================================= LambdaExprNode ======================================================= + +public type ASTLambdaExprNode struct : ASTNode { + +} + +// ========================================================== DataTypeNode ======================================================= + +public type ASTDataTypeNode struct : ASTNode { + +} + +// ======================================================== BaseDataTypeNode ===================================================== + +public type ASTBaseDataTypeNode struct : ASTNode { + +} + +// ======================================================= CustomDataTypeNode ==================================================== + +public type ASTCustomDataTypeNode struct : ASTNode { + +} + +// ====================================================== FunctionDataTypeNode =================================================== + +public type ASTFunctionDataTypeNode struct : ASTNode { } \ No newline at end of file diff --git a/src-bootstrap/main.spice b/src-bootstrap/main.spice index 79af8c155..c2cfc3126 100644 --- a/src-bootstrap/main.spice +++ b/src-bootstrap/main.spice @@ -45,7 +45,7 @@ f compileProject(const CliOptions& cliOptions) { f main(int argc, string[] argv) { // Initialize command line parser CliInterface cli; - cli.createInterface(); + cli.create(); const int exitCode = cli.parse(argc, argv); if exitCode != EXIT_SUCCESS { return exitCode; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b1348837..952d620e8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,9 +15,9 @@ set(SOURCES global/CacheManager.h global/RuntimeModuleManager.cpp global/RuntimeModuleManager.h - # CLI - cli/CLIInterface.cpp - cli/CLIInterface.h + # Driver + driver/Driver.cpp + driver/Driver.h # CST visualizer visualizer/CSTVisualizer.cpp visualizer/CSTVisualizer.h diff --git a/src/Spice.g4 b/src/Spice.g4 index 1b043e69a..3b336ea82 100644 --- a/src/Spice.g4 +++ b/src/Spice.g4 @@ -17,7 +17,7 @@ globalVarDef: dataType TYPE_IDENTIFIER (ASSIGN constant)? SEMICOLON; extDecl: fctAttr? EXT (F LESS dataType GREATER | P) (IDENTIFIER | TYPE_IDENTIFIER) LPAREN (typeLst ELLIPSIS?)? RPAREN SEMICOLON; // Control structures -unsafeBlockDef: UNSAFE LBRACE stmtLst RBRACE; +unsafeBlock: UNSAFE LBRACE stmtLst RBRACE; forLoop: FOR (forHead | LPAREN forHead RPAREN) LBRACE stmtLst RBRACE; forHead: declStmt SEMICOLON assignExpr SEMICOLON assignExpr; foreachLoop: FOREACH (foreachHead | LPAREN foreachHead RPAREN) LBRACE stmtLst RBRACE; @@ -29,7 +29,7 @@ elseStmt: ELSE ifStmt | ELSE LBRACE stmtLst RBRACE; anonymousBlockStmt: LBRACE stmtLst RBRACE; // Statements, declarations, definitions and lists -stmtLst: (stmt | forLoop | foreachLoop | whileLoop | doWhileLoop | ifStmt | assertStmt | unsafeBlockDef | anonymousBlockStmt)*; +stmtLst: (stmt | forLoop | foreachLoop | whileLoop | doWhileLoop | ifStmt | assertStmt | unsafeBlock | anonymousBlockStmt)*; typeLst: dataType (COMMA dataType)*; typeAltsLst: dataType (BITWISE_OR dataType)*; paramLst: declStmt (COMMA declStmt)*; diff --git a/src/ast/ASTBuilder.cpp b/src/ast/ASTBuilder.cpp index 3cc49bb55..b31256a6f 100644 --- a/src/ast/ASTBuilder.cpp +++ b/src/ast/ASTBuilder.cpp @@ -48,8 +48,8 @@ std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) { visitChildren(ctx); // Retrieve information from the function name - fctDefNode->fctName = fctDefNode->getChild(); - fctDefNode->isMethod = fctDefNode->fctName->nameFragments.size() > 1; + fctDefNode->name = fctDefNode->getChild(); + fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1; // Tell the return type that it is one fctDefNode->returnType()->isReturnType = true; @@ -68,8 +68,8 @@ std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) { visitChildren(ctx); // Retrieve information from the procedure name - procDefNode->procName = procDefNode->getChild(); - procDefNode->isMethod = procDefNode->procName->nameFragments.size() > 1; + procDefNode->name = procDefNode->getChild(); + procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1; return concludeNode(ctx, procDefNode); } @@ -194,8 +194,8 @@ std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) { return concludeNode(ctx, extDeclNode); } -std::any ASTBuilder::visitUnsafeBlockDef(SpiceParser::UnsafeBlockDefContext *ctx) { - auto unsafeBlockDefNode = createNode(ctx); +std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) { + auto unsafeBlockDefNode = createNode(ctx); // Visit children visitChildren(ctx); diff --git a/src/ast/ASTBuilder.h b/src/ast/ASTBuilder.h index 67818347e..7f86f6a44 100644 --- a/src/ast/ASTBuilder.h +++ b/src/ast/ASTBuilder.h @@ -43,7 +43,7 @@ class ASTBuilder : private CompilerPass, public SpiceVisitor { std::any visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) override; std::any visitEnumDef(SpiceParser::EnumDefContext *ctx) override; std::any visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) override; - std::any visitUnsafeBlockDef(SpiceParser::UnsafeBlockDefContext *ctx) override; + std::any visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) override; std::any visitForLoop(SpiceParser::ForLoopContext *ctx) override; std::any visitForHead(SpiceParser::ForHeadContext *ctx) override; std::any visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) override; diff --git a/src/ast/ASTNodes.cpp b/src/ast/ASTNodes.cpp index a58bb2523..311c8a70c 100644 --- a/src/ast/ASTNodes.cpp +++ b/src/ast/ASTNodes.cpp @@ -10,11 +10,7 @@ bool MainFctDefNode::returnsOnAllControlPaths(bool *overrideUnreachable) const { return body()->returnsOnAllControlPaths(overrideUnreachable); } -bool FctDefNode::returnsOnAllControlPaths(bool *overrideUnreachable) const { - return body()->returnsOnAllControlPaths(overrideUnreachable); -} - -bool ProcDefNode::returnsOnAllControlPaths(bool *overrideUnreachable) const { +bool FctDefBaseNode::returnsOnAllControlPaths(bool *overrideUnreachable) const { return body()->returnsOnAllControlPaths(overrideUnreachable); } diff --git a/src/ast/ASTNodes.h b/src/ast/ASTNodes.h index 5b943f639..3362debdb 100644 --- a/src/ast/ASTNodes.h +++ b/src/ast/ASTNodes.h @@ -258,80 +258,72 @@ class FctNameNode : public ASTNode { OverloadedOperator overloadedOperator = OP_NONE; }; -// ========================================================== FctDefNode ========================================================= +// ======================================================== FctDefBaseNode ======================================================= -class FctDefNode : public ASTNode { +class FctDefBaseNode : public ASTNode { public: // Constructors using ASTNode::ASTNode; - // Visitor methods - std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitFctDef(this); } - std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitFctDef(this); } - // Public get methods [[nodiscard]] FctAttrNode *attrs() const { return getChild(); } [[nodiscard]] SpecifierLstNode *specifierLst() const { return getChild(); } - [[nodiscard]] DataTypeNode *returnType() const { return getChild(); } [[nodiscard]] TypeLstNode *templateTypeLst() const { return getChild(); } [[nodiscard]] ParamLstNode *paramLst() const { return getChild(); } [[nodiscard]] StmtLstNode *body() const { return getChild(); } // Other methods - [[nodiscard]] std::string getScopeId() const { return "fct:" + codeLoc.toString(); } - [[nodiscard]] std::string getSymbolTableEntryName() const { return Function::getSymbolTableEntryName(fctName->name, codeLoc); } - [[nodiscard]] bool returnsOnAllControlPaths(bool *overrideUnreachable) const override; - std::vector *getFctManifestations(const std::string &_) override { return &fctManifestations; } + [[nodiscard]] std::string getSymbolTableEntryName() const { return Function::getSymbolTableEntryName(name->name, codeLoc); } + std::vector *getFctManifestations(const std::string &_) override { return &manifestations; } [[nodiscard]] bool isFctOrProcDef() const override { return true; } + [[nodiscard]] bool returnsOnAllControlPaths(bool *overrideUnreachable) const override; // Public members - FctNameNode *fctName; + FctNameNode *name; bool isMethod = false; bool hasTemplateTypes = false; bool hasParams = false; SymbolTableEntry *entry = nullptr; - TypeSpecifiers functionSpecifiers = TypeSpecifiers::of(TY_FUNCTION); + TypeSpecifiers specifiers = TypeSpecifiers::of(TY_FUNCTION); Scope *structScope = nullptr; - Scope *fctScope = nullptr; - std::vector fctManifestations; + Scope *scope = nullptr; + std::vector manifestations; +}; + +// ========================================================== FctDefNode ========================================================= + +class FctDefNode : public FctDefBaseNode { +public: + // Constructors + using FctDefBaseNode::FctDefBaseNode; + + // Visitor methods + std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitFctDef(this); } + std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitFctDef(this); } + + // Public get methods + [[nodiscard]] DataTypeNode *returnType() const { return getChild(); } + + // Other methods + [[nodiscard]] std::string getScopeId() const { return "fct:" + codeLoc.toString(); } }; // ========================================================== ProcDefNode ======================================================== -class ProcDefNode : public ASTNode { +class ProcDefNode : public FctDefBaseNode { public: // Constructors - using ASTNode::ASTNode; + using FctDefBaseNode::FctDefBaseNode; // Visitor methods std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitProcDef(this); } std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitProcDef(this); } - // Public get methods - [[nodiscard]] FctAttrNode *attrs() const { return getChild(); } - [[nodiscard]] SpecifierLstNode *specifierLst() const { return getChild(); } - [[nodiscard]] TypeLstNode *templateTypeLst() const { return getChild(); } - [[nodiscard]] ParamLstNode *paramLst() const { return getChild(); } - [[nodiscard]] StmtLstNode *body() const { return getChild(); } - // Other methods [[nodiscard]] std::string getScopeId() const { return "proc:" + codeLoc.toString(); } - [[nodiscard]] std::string getSymbolTableEntryName() const { return Function::getSymbolTableEntryName(procName->name, codeLoc); } - bool returnsOnAllControlPaths(bool *overrideUnreachable) const override; - std::vector *getFctManifestations(const std::string &_) override { return &procManifestations; } - [[nodiscard]] bool isFctOrProcDef() const override { return true; } // Public members - FctNameNode *procName; - bool isMethod = false; - bool hasTemplateTypes = false; - bool hasParams = false; bool isCtor = false; - SymbolTableEntry *entry = nullptr; - TypeSpecifiers procedureSpecifiers = TypeSpecifiers::of(TY_PROCEDURE); - Scope *structScope = nullptr; - Scope *procScope = nullptr; - std::vector procManifestations; }; // ========================================================= StructDefNode ======================================================= @@ -513,15 +505,15 @@ class ExtDeclNode : public ASTNode { std::vector extFunctionManifestations; }; -// ====================================================== UnsafeBlockDefNode ===================================================== +// ======================================================== UnsafeBlockNode ====================================================== -class UnsafeBlockDefNode : public ASTNode { +class UnsafeBlockNode : public ASTNode { public: // Constructors using ASTNode::ASTNode; // Visitor methods - std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitUnsafeBlockDef(this); } + std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitUnsafeBlock(this); } std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitUnsafeBlockDef(this); } // Public get methods @@ -684,7 +676,7 @@ class ElseStmtNode : public ASTNode { Scope *elseBodyScope = nullptr; }; -// ========================================================== ScopeNode ========================================================== +// ==================================================== AnonymousBlockStmtNode =================================================== class AnonymousBlockStmtNode : public ASTNode { public: @@ -1807,85 +1799,75 @@ class StructInstantiationNode : public ASTNode { std::vector instantiatedStructs; }; -// ====================================================== LambdaFuncNode ========================================================= +// ====================================================== LambdaBaseNode ========================================================= -class LambdaFuncNode : public ASTNode { +class LambdaBaseNode : public ASTNode { public: // Constructors using ASTNode::ASTNode; - // Visit methods - std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitLambdaFunc(this); } - std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitLambdaFunc(this); } - // Public get methods [[nodiscard]] ParamLstNode *paramLst() const { return getChild(); } - [[nodiscard]] DataTypeNode *returnType() const { return getChild(); } - [[nodiscard]] StmtLstNode *body() const { return getChild(); } // Other methods [[nodiscard]] std::string getScopeId() const { return "lambda:" + codeLoc.toString(); } [[nodiscard]] bool hasCompileTimeValue() const override { return false; } - [[nodiscard]] bool returnsOnAllControlPaths(bool *overrideUnreachable) const override; - void customItemsInitialization(size_t manifestationCount) override { lambdaFunction.resize(manifestationCount); } + void customItemsInitialization(size_t manifestationCount) override { manifestations.resize(manifestationCount); } // Public members bool hasParams = false; Scope *bodyScope = nullptr; - std::vector lambdaFunction; + std::vector manifestations; }; -// ====================================================== LambdaProcNode ========================================================= +// ====================================================== LambdaFuncNode ========================================================= -class LambdaProcNode : public ASTNode { +class LambdaFuncNode : public LambdaBaseNode { public: // Constructors - using ASTNode::ASTNode; + using LambdaBaseNode::LambdaBaseNode; + + // Public get methods + [[nodiscard]] StmtLstNode *body() const { return getChild(); } + [[nodiscard]] bool returnsOnAllControlPaths(bool *overrideUnreachable) const override; // Visit methods - std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitLambdaProc(this); } - std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitLambdaProc(this); } + std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitLambdaFunc(this); } + std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitLambdaFunc(this); } // Public get methods - [[nodiscard]] ParamLstNode *paramLst() const { return getChild(); } - [[nodiscard]] StmtLstNode *body() const { return getChild(); } + [[nodiscard]] DataTypeNode *returnType() const { return getChild(); } +}; - // Other methods - [[nodiscard]] std::string getScopeId() const { return "lambda:" + codeLoc.toString(); } - [[nodiscard]] bool hasCompileTimeValue() const override { return false; } +// ====================================================== LambdaProcNode ========================================================= + +class LambdaProcNode : public LambdaBaseNode { +public: + // Constructors + using LambdaBaseNode::LambdaBaseNode; + + // Public get methods + [[nodiscard]] StmtLstNode *body() const { return getChild(); } [[nodiscard]] bool returnsOnAllControlPaths(bool *overrideUnreachable) const override; - void customItemsInitialization(size_t manifestationCount) override { lambdaProcedure.resize(manifestationCount); } - // Public members - bool hasParams = false; - Scope *bodyScope = nullptr; - std::vector lambdaProcedure; + // Visit methods + std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitLambdaProc(this); } + std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitLambdaProc(this); } }; // ====================================================== LambdaExprNode ========================================================= -class LambdaExprNode : public ASTNode { +class LambdaExprNode : public LambdaBaseNode { public: // Constructors - using ASTNode::ASTNode; + using LambdaBaseNode::LambdaBaseNode; // Visit methods std::any accept(AbstractASTVisitor *visitor) override { return visitor->visitLambdaExpr(this); } std::any accept(ParallelizableASTVisitor *visitor) const override { return visitor->visitLambdaExpr(this); } // Public get methods - [[nodiscard]] ParamLstNode *paramLst() const { return getChild(); } [[nodiscard]] AssignExprNode *lambdaExpr() const { return getChild(); } - - // Other methods - [[nodiscard]] std::string getScopeId() const { return "lambda:" + codeLoc.toString(); } - [[nodiscard]] bool hasCompileTimeValue() const override { return false; } - void customItemsInitialization(size_t manifestationCount) override { lambdaFunction.resize(manifestationCount); } - - // Public members - bool hasParams = false; - Scope *bodyScope = nullptr; - std::vector lambdaFunction; }; // ======================================================= DataTypeNode ========================================================== diff --git a/src/ast/ASTVisitor.cpp b/src/ast/ASTVisitor.cpp index 82ff4fc00..234187307 100644 --- a/src/ast/ASTVisitor.cpp +++ b/src/ast/ASTVisitor.cpp @@ -30,7 +30,7 @@ std::any ASTVisitor::visitGlobalVarDef(GlobalVarDefNode *node) { return visitChi std::any ASTVisitor::visitExtDecl(ExtDeclNode *node) { return visitChildren(node); } -std::any ASTVisitor::visitUnsafeBlockDef(UnsafeBlockDefNode *node) { return visitChildren(node); } +std::any ASTVisitor::visitUnsafeBlock(UnsafeBlockNode *node) { return visitChildren(node); } std::any ASTVisitor::visitForLoop(ForLoopNode *node) { return visitChildren(node); } diff --git a/src/ast/ASTVisitor.h b/src/ast/ASTVisitor.h index 8af212037..e8e3e1ac5 100644 --- a/src/ast/ASTVisitor.h +++ b/src/ast/ASTVisitor.h @@ -21,7 +21,7 @@ class ASTVisitor : public AbstractASTVisitor { std::any visitAliasDef(AliasDefNode *node) override; std::any visitGlobalVarDef(GlobalVarDefNode *node) override; std::any visitExtDecl(ExtDeclNode *node) override; - std::any visitUnsafeBlockDef(UnsafeBlockDefNode *node) override; + std::any visitUnsafeBlock(UnsafeBlockNode *node) override; std::any visitForLoop(ForLoopNode *node) override; std::any visitForeachLoop(ForeachLoopNode *node) override; std::any visitWhileLoop(WhileLoopNode *node) override; diff --git a/src/ast/AbstractASTVisitor.h b/src/ast/AbstractASTVisitor.h index 22cfe1bef..f7945e252 100644 --- a/src/ast/AbstractASTVisitor.h +++ b/src/ast/AbstractASTVisitor.h @@ -20,7 +20,7 @@ class GenericTypeDefNode; class AliasDefNode; class GlobalVarDefNode; class ExtDeclNode; -class UnsafeBlockDefNode; +class UnsafeBlockNode; class ForLoopNode; class ForeachLoopNode; class WhileLoopNode; @@ -104,7 +104,7 @@ class AbstractASTVisitor { virtual std::any visitAliasDef(AliasDefNode *node) = 0; virtual std::any visitGlobalVarDef(GlobalVarDefNode *node) = 0; virtual std::any visitExtDecl(ExtDeclNode *node) = 0; - virtual std::any visitUnsafeBlockDef(UnsafeBlockDefNode *node) = 0; + virtual std::any visitUnsafeBlock(UnsafeBlockNode *node) = 0; virtual std::any visitForLoop(ForLoopNode *node) = 0; virtual std::any visitForeachLoop(ForeachLoopNode *node) = 0; virtual std::any visitWhileLoop(WhileLoopNode *node) = 0; diff --git a/src/ast/ParallelizableASTVisitor.cpp b/src/ast/ParallelizableASTVisitor.cpp index b32b2d639..d8385fed4 100644 --- a/src/ast/ParallelizableASTVisitor.cpp +++ b/src/ast/ParallelizableASTVisitor.cpp @@ -41,7 +41,7 @@ std::any ParallelizableASTVisitor::visitGlobalVarDef(const GlobalVarDefNode *nod std::any ParallelizableASTVisitor::visitExtDecl(const ExtDeclNode *node) { return visitChildren(node); } -std::any ParallelizableASTVisitor::visitUnsafeBlockDef(const UnsafeBlockDefNode *node) { return visitChildren(node); } +std::any ParallelizableASTVisitor::visitUnsafeBlockDef(const UnsafeBlockNode *node) { return visitChildren(node); } std::any ParallelizableASTVisitor::visitForLoop(const ForLoopNode *node) { return visitChildren(node); } diff --git a/src/ast/ParallelizableASTVisitor.h b/src/ast/ParallelizableASTVisitor.h index 66510f494..4a1d56c24 100644 --- a/src/ast/ParallelizableASTVisitor.h +++ b/src/ast/ParallelizableASTVisitor.h @@ -20,7 +20,7 @@ class GenericTypeDefNode; class AliasDefNode; class GlobalVarDefNode; class ExtDeclNode; -class UnsafeBlockDefNode; +class UnsafeBlockNode; class ForLoopNode; class ForeachLoopNode; class WhileLoopNode; @@ -104,7 +104,7 @@ class ParallelizableASTVisitor { virtual std::any visitAliasDef(const AliasDefNode *node); virtual std::any visitGlobalVarDef(const GlobalVarDefNode *node); virtual std::any visitExtDecl(const ExtDeclNode *node); - virtual std::any visitUnsafeBlockDef(const UnsafeBlockDefNode *node); + virtual std::any visitUnsafeBlockDef(const UnsafeBlockNode *node); virtual std::any visitForLoop(const ForLoopNode *node); virtual std::any visitForeachLoop(const ForeachLoopNode *node); virtual std::any visitWhileLoop(const WhileLoopNode *node); diff --git a/src/astoptimizer/ASTOptimizer.cpp b/src/astoptimizer/ASTOptimizer.cpp index 9b0be5280..6b77c8301 100644 --- a/src/astoptimizer/ASTOptimizer.cpp +++ b/src/astoptimizer/ASTOptimizer.cpp @@ -6,7 +6,7 @@ namespace spice::compiler { -std::any ASTOptimizer::visitUnsafeBlockDef(UnsafeBlockDefNode *node) { +std::any ASTOptimizer::visitUnsafeBlock(UnsafeBlockNode *node) { // Optimize all children first visitChildren(node); diff --git a/src/astoptimizer/ASTOptimizer.h b/src/astoptimizer/ASTOptimizer.h index 8cb7c81ea..528772bb6 100644 --- a/src/astoptimizer/ASTOptimizer.h +++ b/src/astoptimizer/ASTOptimizer.h @@ -22,7 +22,7 @@ class ASTOptimizer : private CompilerPass, public ASTVisitor { ASTOptimizer(GlobalResourceManager &resourceManager, SourceFile *sourceFile) : CompilerPass(resourceManager, sourceFile) {} // Public methods - std::any visitUnsafeBlockDef(UnsafeBlockDefNode *node) override; + std::any visitUnsafeBlock(UnsafeBlockNode *node) override; std::any visitForLoop(ForLoopNode *node) override; std::any visitForeachLoop(ForeachLoopNode *node) override; std::any visitWhileLoop(WhileLoopNode *node) override; diff --git a/src/cli/CLIInterface.cpp b/src/driver/Driver.cpp similarity index 96% rename from src/cli/CLIInterface.cpp rename to src/driver/Driver.cpp index 0d6f9057f..e4b526a31 100644 --- a/src/cli/CLIInterface.cpp +++ b/src/driver/Driver.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2021-2023 ChilliBits. All rights reserved. -#include "CLIInterface.h" +#include "Driver.h" #include #include @@ -13,7 +13,7 @@ namespace spice::compiler { -void CLIInterface::createInterface() { +void Driver::init() { // Allow positional args app.positionals_at_end(); app.require_subcommand(1); @@ -100,7 +100,7 @@ void CLIInterface::createInterface() { /** * Initialize the cli options based on the input of the user */ -void CLIInterface::enrich() { +void Driver::enrich() { // Propagate llvm args to llvm if (!cliOptions.llvmArgs.empty()) { const std::vector result = CommonUtil::split("llvm " + cliOptions.llvmArgs); @@ -137,7 +137,7 @@ void CLIInterface::enrich() { /** * Executes the built executable */ -void CLIInterface::runBinary() const { +void Driver::runBinary() const { // Print status message if (cliOptions.printDebugOutput) std::cout << "Running executable ...\n\n"; @@ -153,7 +153,7 @@ void CLIInterface::runBinary() const { /** * Add build subcommand to cli interface */ -void CLIInterface::addBuildSubcommand() { +void Driver::addBuildSubcommand() { // Create sub-command itself CLI::App *subCmd = app.add_subcommand("build", "Builds your Spice program and emits an executable"); subCmd->alias("b"); @@ -192,7 +192,7 @@ void CLIInterface::addBuildSubcommand() { /** * Add run subcommand to cli interface */ -void CLIInterface::addRunSubcommand() { +void Driver::addRunSubcommand() { // Create sub-command itself CLI::App *subCmd = app.add_subcommand("run", "Builds your Spice program and runs it immediately"); subCmd->alias("r"); @@ -212,7 +212,7 @@ void CLIInterface::addRunSubcommand() { /** * Add install subcommand to cli interface */ -void CLIInterface::addInstallSubcommand() { +void Driver::addInstallSubcommand() { // Create sub-command itself CLI::App *subCmd = app.add_subcommand("install", "Builds your Spice program and installs it to a directory in the PATH variable"); @@ -230,7 +230,7 @@ void CLIInterface::addInstallSubcommand() { /** * Add uninstall subcommand to cli interface */ -void CLIInterface::addUninstallSubcommand() { +void Driver::addUninstallSubcommand() { // Create sub-command itself CLI::App *subCmd = app.add_subcommand("uninstall", "Builds your Spice program and runs it immediately"); subCmd->alias("u"); @@ -246,7 +246,7 @@ void CLIInterface::addUninstallSubcommand() { ->required(); } -void CLIInterface::addCompileSubcommandOptions(CLI::App *subCmd) { +void Driver::addCompileSubcommandOptions(CLI::App *subCmd) { const std::function buildModeCallback = [&](const CLI::results_t &results) { std::string inputString = results.front(); std::transform(inputString.begin(), inputString.end(), inputString.begin(), ::tolower); @@ -314,7 +314,7 @@ void CLIInterface::addCompileSubcommandOptions(CLI::App *subCmd) { /** * Ensure that the compiler is not running in a Docker container */ -void CLIInterface::ensureNotDockerized() { +void Driver::ensureNotDockerized() { const char *envValue = std::getenv(ENV_VAR_DOCKERIZED); if (envValue != nullptr && std::strcmp(envValue, "true") == 0) throw CliError(FEATURE_NOT_SUPPORTED_WHEN_DOCKERIZED, @@ -328,7 +328,7 @@ void CLIInterface::ensureNotDockerized() { * @param argv Argument vector * @return Return code */ -int CLIInterface::parse(int argc, char **argv) { +int Driver::parse(int argc, char **argv) { try { app.parse(argc, argv); return EXIT_SUCCESS; diff --git a/src/cli/CLIInterface.h b/src/driver/Driver.h similarity index 95% rename from src/cli/CLIInterface.h rename to src/driver/Driver.h index 5e15ed15b..8d85ae8dc 100644 --- a/src/cli/CLIInterface.h +++ b/src/driver/Driver.h @@ -69,15 +69,16 @@ struct CliOptions { }; /** - * Helper class to setup the cli interface and command line parser + * Helper class to setup the driver and command line parser */ -class CLIInterface { +class Driver { public: // Constructors - explicit CLIInterface() = default; + explicit Driver() = default; + Driver(const Driver &) = delete; // Public methods - void createInterface(); + void init(); int parse(int argc, char **argv); void enrich(); void runBinary() const; diff --git a/src/global/GlobalResourceManager.cpp b/src/global/GlobalResourceManager.cpp index ffd9f1a32..68d482d22 100644 --- a/src/global/GlobalResourceManager.cpp +++ b/src/global/GlobalResourceManager.cpp @@ -31,6 +31,8 @@ GlobalResourceManager::GlobalResourceManager(const CliOptions &cliOptions) // Create target machine for LLVM llvm::TargetOptions opt; + opt.MCOptions.AsmVerbose = true; + opt.MCOptions.PreserveAsmComments = true; std::string cpuName = "generic"; std::stringstream featureString; if (cliOptions.isNativeTarget && cliOptions.useCPUFeatures) { diff --git a/src/irgenerator/GenControlStructures.cpp b/src/irgenerator/GenControlStructures.cpp index d75313d0d..6f73b991f 100644 --- a/src/irgenerator/GenControlStructures.cpp +++ b/src/irgenerator/GenControlStructures.cpp @@ -9,7 +9,7 @@ namespace spice::compiler { -std::any IRGenerator::visitUnsafeBlockDef(const UnsafeBlockDefNode *node) { +std::any IRGenerator::visitUnsafeBlockDef(const UnsafeBlockNode *node) { diGenerator.setSourceLocation(node); // Change scope diff --git a/src/irgenerator/GenTopLevelDefinitions.cpp b/src/irgenerator/GenTopLevelDefinitions.cpp index 8219c8318..106ba6351 100644 --- a/src/irgenerator/GenTopLevelDefinitions.cpp +++ b/src/irgenerator/GenTopLevelDefinitions.cpp @@ -128,7 +128,7 @@ std::any IRGenerator::visitMainFctDef(const MainFctDefNode *node) { std::any IRGenerator::visitFctDef(const FctDefNode *node) { // Loop through manifestations manIdx = 0; // Reset the symbolTypeIndex - for (const Function *manifestation : node->fctManifestations) { + for (const Function *manifestation : node->manifestations) { assert(manifestation->entry != nullptr); // Check if the manifestation is substantiated or not public and not used by anybody @@ -294,7 +294,7 @@ std::any IRGenerator::visitFctDef(const FctDefNode *node) { std::any IRGenerator::visitProcDef(const ProcDefNode *node) { // Loop through manifestations manIdx = 0; // Reset the symbolTypeIndex - for (const Function *manifestation : node->procManifestations) { + for (const Function *manifestation : node->manifestations) { assert(manifestation->entry != nullptr); // Check if the manifestation is substantiated or not public and not used by anybody diff --git a/src/irgenerator/GenValues.cpp b/src/irgenerator/GenValues.cpp index abe4a8948..d37e24f03 100644 --- a/src/irgenerator/GenValues.cpp +++ b/src/irgenerator/GenValues.cpp @@ -371,7 +371,7 @@ std::any IRGenerator::visitStructInstantiation(const StructInstantiationNode *no } std::any IRGenerator::visitLambdaFunc(const LambdaFuncNode *node) { - Function spiceFunc = node->lambdaFunction.at(manIdx); + Function spiceFunc = node->manifestations.at(manIdx); ParamInfoList paramInfoList; std::vector paramTypes; @@ -543,7 +543,7 @@ std::any IRGenerator::visitLambdaFunc(const LambdaFuncNode *node) { } std::any IRGenerator::visitLambdaProc(const LambdaProcNode *node) { - Function spiceFunc = node->lambdaProcedure.at(manIdx); + Function spiceFunc = node->manifestations.at(manIdx); ParamInfoList paramInfoList; std::vector paramTypes; @@ -702,7 +702,7 @@ std::any IRGenerator::visitLambdaProc(const LambdaProcNode *node) { } std::any IRGenerator::visitLambdaExpr(const LambdaExprNode *node) { - const Function &spiceFunc = node->lambdaFunction.at(manIdx); + const Function &spiceFunc = node->manifestations.at(manIdx); ParamInfoList paramInfoList; std::vector paramTypes; diff --git a/src/irgenerator/IRGenerator.h b/src/irgenerator/IRGenerator.h index 36f6caf5a..8572f542d 100644 --- a/src/irgenerator/IRGenerator.h +++ b/src/irgenerator/IRGenerator.h @@ -50,7 +50,7 @@ class IRGenerator : private CompilerPass, public ParallelizableASTVisitor { std::any visitGlobalVarDef(const GlobalVarDefNode *node) override; std::any visitExtDecl(const ExtDeclNode *node) override; // Control structures - std::any visitUnsafeBlockDef(const UnsafeBlockDefNode *node) override; + std::any visitUnsafeBlockDef(const UnsafeBlockNode *node) override; std::any visitForLoop(const ForLoopNode *node) override; std::any visitForeachLoop(const ForeachLoopNode *node) override; std::any visitWhileLoop(const WhileLoopNode *node) override; diff --git a/src/iroptimizer/IROptimizer.cpp b/src/iroptimizer/IROptimizer.cpp index 63dfd7e90..204a5b47e 100644 --- a/src/iroptimizer/IROptimizer.cpp +++ b/src/iroptimizer/IROptimizer.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include namespace spice::compiler { diff --git a/src/linker/ExternalLinkerInterface.h b/src/linker/ExternalLinkerInterface.h index 3888e3820..f658f48ea 100644 --- a/src/linker/ExternalLinkerInterface.h +++ b/src/linker/ExternalLinkerInterface.h @@ -2,10 +2,11 @@ #pragma once +#include #include #include -#include +#include namespace spice::compiler { diff --git a/src/main.cpp b/src/main.cpp index 94e545d33..cc659d13f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2021-2023 ChilliBits. All rights reserved. #include -#include +#include #include #include #include @@ -59,25 +59,25 @@ bool compileProject(CliOptions &cliOptions) { */ int main(int argc, char **argv) { // Initialize command line parser - CLIInterface cli; - cli.createInterface(); + Driver driver; + driver.init(); try { - if (const int exitCode = cli.parse(argc, argv); exitCode != EXIT_SUCCESS) + if (const int exitCode = driver.parse(argc, argv); exitCode != EXIT_SUCCESS) return exitCode; // Cancel here if we do not have to compile - if (!cli.shouldCompile) + if (!driver.shouldCompile) return EXIT_SUCCESS; - cli.enrich(); // Prepare the cli options + driver.enrich(); // Prepare the cli options // Kick off the compilation process - if (!compileProject(cli.cliOptions)) + if (!compileProject(driver.cliOptions)) return EXIT_FAILURE; // Execute - if (cli.cliOptions.execute) - cli.runBinary(); + if (driver.cliOptions.execute) + driver.runBinary(); return EXIT_SUCCESS; } catch (CliError &e) { diff --git a/src/symboltablebuilder/SymbolTableBuilder.cpp b/src/symboltablebuilder/SymbolTableBuilder.cpp index e8ae9c72d..d56252663 100644 --- a/src/symboltablebuilder/SymbolTableBuilder.cpp +++ b/src/symboltablebuilder/SymbolTableBuilder.cpp @@ -61,11 +61,11 @@ std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) { if (SpecifierLstNode *specifierLst = node->specifierLst(); specifierLst) { for (const SpecifierNode *specifier : specifierLst->specifiers()) { if (specifier->type == SpecifierNode::TY_INLINE) - node->functionSpecifiers.isInline = true; + node->specifiers.isInline = true; else if (specifier->type == SpecifierNode::TY_PUBLIC) - node->functionSpecifiers.isPublic = true; + node->specifiers.isPublic = true; else if (specifier->type == SpecifierNode::TY_CONST) - node->functionSpecifiers.isConst = true; + node->specifiers.isConst = true; else throw SemanticError(specifier, SPECIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this specifier on a function definition"); } @@ -73,13 +73,13 @@ std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) { // Change to struct scope if this function is a method if (node->isMethod) { - node->structScope = currentScope = currentScope->getChildScope(STRUCT_SCOPE_PREFIX + node->fctName->structName); + node->structScope = currentScope = currentScope->getChildScope(STRUCT_SCOPE_PREFIX + node->name->structName); if (!currentScope) - throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->fctName->structName + "' could not be found"); + throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found"); } // Create scope for the function - node->fctScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); + node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); // Create symbol for 'this' variable @@ -97,16 +97,16 @@ std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) { visit(node->body()); // Leave function body scope - currentScope = node->fctScope->parent; + currentScope = node->scope->parent; // Insert symbol for function into the symbol table node->entry = currentScope->insert(node->getSymbolTableEntryName(), node); // Add to external name registry // if a function has overloads, they both refer to the same entry in the registry. So we only register the name once - const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->fctName->fqName); + const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) - sourceFile->addNameRegistryEntry(node->fctName->fqName, node->entry, currentScope, /*keepNewOnCollision=*/true); + sourceFile->addNameRegistryEntry(node->name->fqName, node->entry, currentScope, /*keepNewOnCollision=*/true); // Leave the struct scope if (node->isMethod) @@ -120,11 +120,11 @@ std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) { if (SpecifierLstNode *specifierLst = node->specifierLst(); specifierLst) { for (const SpecifierNode *specifier : specifierLst->specifiers()) { if (specifier->type == SpecifierNode::TY_INLINE) - node->procedureSpecifiers.isInline = true; + node->specifiers.isInline = true; else if (specifier->type == SpecifierNode::TY_PUBLIC) - node->procedureSpecifiers.isPublic = true; + node->specifiers.isPublic = true; else if (specifier->type == SpecifierNode::TY_CONST) - node->procedureSpecifiers.isConst = true; + node->specifiers.isConst = true; else throw SemanticError(specifier, SPECIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this specifier on a procedure definition"); } @@ -132,15 +132,15 @@ std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) { // Change to struct scope if this procedure is a method if (node->isMethod) { - node->structScope = currentScope = currentScope->getChildScope(STRUCT_SCOPE_PREFIX + node->procName->structName); + node->structScope = currentScope = currentScope->getChildScope(STRUCT_SCOPE_PREFIX + node->name->structName); if (!currentScope) - throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->procName->structName + "' could not be found"); + throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found"); } // Create scope for the procedure - node->procScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); + node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); - currentScope->isDtorScope = node->isMethod && node->procName->name == DTOR_FUNCTION_NAME; + currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME; // Create symbol for 'this' variable if (node->isMethod) @@ -154,23 +154,23 @@ std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) { visit(node->body()); // Leave procedure body scope - currentScope = node->procScope->parent; + currentScope = node->scope->parent; // Insert symbol for procedure into the symbol table node->entry = currentScope->insert(node->getSymbolTableEntryName(), node); // Add to external name registry // if a procedure has overloads, they both refer to the same entry in the registry. So we only register the name once - const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->procName->fqName); + const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) - sourceFile->addNameRegistryEntry(node->procName->fqName, node->entry, currentScope, /*keepNewOnCollision=*/true); + sourceFile->addNameRegistryEntry(node->name->fqName, node->entry, currentScope, /*keepNewOnCollision=*/true); // Leave the struct scope if (node->isMethod) currentScope = node->structScope->parent; // Check if this is a constructor - node->isCtor = node->procName->nameFragments.back() == CTOR_FUNCTION_NAME; + node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME; return nullptr; } @@ -331,7 +331,7 @@ std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) { return nullptr; } -std::any SymbolTableBuilder::visitUnsafeBlockDef(UnsafeBlockDefNode *node) { +std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) { // Create scope for the unsafe block body node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body()->codeLoc); diff --git a/src/symboltablebuilder/SymbolTableBuilder.h b/src/symboltablebuilder/SymbolTableBuilder.h index b8d2957f2..02cb9e590 100644 --- a/src/symboltablebuilder/SymbolTableBuilder.h +++ b/src/symboltablebuilder/SymbolTableBuilder.h @@ -40,7 +40,7 @@ class SymbolTableBuilder : private CompilerPass, public ASTVisitor { std::any visitAliasDef(AliasDefNode *node) override; std::any visitGlobalVarDef(GlobalVarDefNode *node) override; std::any visitExtDecl(ExtDeclNode *node) override; - std::any visitUnsafeBlockDef(UnsafeBlockDefNode *node) override; + std::any visitUnsafeBlock(UnsafeBlockNode *node) override; std::any visitForLoop(ForLoopNode *node) override; std::any visitForeachLoop(ForeachLoopNode *node) override; std::any visitWhileLoop(WhileLoopNode *node) override; diff --git a/src/typechecker/TypeChecker.cpp b/src/typechecker/TypeChecker.cpp index 973684b1f..2139c4d59 100644 --- a/src/typechecker/TypeChecker.cpp +++ b/src/typechecker/TypeChecker.cpp @@ -104,7 +104,7 @@ std::any TypeChecker::visitExtDecl(ExtDeclNode *node) { return nullptr; } -std::any TypeChecker::visitUnsafeBlockDef(UnsafeBlockDefNode *node) { +std::any TypeChecker::visitUnsafeBlock(UnsafeBlockNode *node) { // Change to unsafe block body scope ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::UNSAFE_BODY); @@ -1280,7 +1280,7 @@ std::any TypeChecker::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { break; } default: - throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE; + throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE } if (lhsType.is(TY_INVALID)) { @@ -1975,9 +1975,9 @@ std::any TypeChecker::visitLambdaFunc(LambdaFuncNode *node) { // Create function object const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); - node->lambdaFunction.at(manIdx) = Function(fctName, nullptr, SymbolType(TY_DYN), returnType, paramList, {}, node); - node->lambdaFunction.at(manIdx).bodyScope = bodyScope; - node->lambdaFunction.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); + node->manifestations.at(manIdx) = Function(fctName, nullptr, SymbolType(TY_DYN), returnType, paramList, {}, node); + node->manifestations.at(manIdx).bodyScope = bodyScope; + node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; } @@ -2015,9 +2015,9 @@ std::any TypeChecker::visitLambdaProc(LambdaProcNode *node) { // Create function object const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); - node->lambdaProcedure.at(manIdx) = Function(fctName, nullptr, SymbolType(TY_DYN), SymbolType(TY_DYN), paramList, {}, node); - node->lambdaProcedure.at(manIdx).bodyScope = bodyScope; - node->lambdaProcedure.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); + node->manifestations.at(manIdx) = Function(fctName, nullptr, SymbolType(TY_DYN), SymbolType(TY_DYN), paramList, {}, node); + node->manifestations.at(manIdx).bodyScope = bodyScope; + node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; } @@ -2061,9 +2061,9 @@ std::any TypeChecker::visitLambdaExpr(LambdaExprNode *node) { // Create function object const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); - node->lambdaFunction.at(manIdx) = Function(fctName, nullptr, SymbolType(TY_DYN), returnType, paramList, {}, node); - node->lambdaFunction.at(manIdx).bodyScope = bodyScope; - node->lambdaFunction.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); + node->manifestations.at(manIdx) = Function(fctName, nullptr, SymbolType(TY_DYN), returnType, paramList, {}, node); + node->manifestations.at(manIdx).bodyScope = bodyScope; + node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; } diff --git a/src/typechecker/TypeChecker.h b/src/typechecker/TypeChecker.h index 632e99481..f8f3c151c 100644 --- a/src/typechecker/TypeChecker.h +++ b/src/typechecker/TypeChecker.h @@ -58,7 +58,7 @@ class TypeChecker : private CompilerPass, public ASTVisitor { std::any visitGlobalVarDefPrepare(GlobalVarDefNode *node); std::any visitExtDecl(ExtDeclNode *node) override; std::any visitExtDeclPrepare(ExtDeclNode *node); - std::any visitUnsafeBlockDef(UnsafeBlockDefNode *node) override; + std::any visitUnsafeBlock(UnsafeBlockNode *node) override; std::any visitForLoop(ForLoopNode *node) override; std::any visitForeachLoop(ForeachLoopNode *node) override; std::any visitWhileLoop(WhileLoopNode *node) override; diff --git a/src/typechecker/TypeCheckerCheck.cpp b/src/typechecker/TypeCheckerCheck.cpp index 2db4ee129..bb8a9aa25 100644 --- a/src/typechecker/TypeCheckerCheck.cpp +++ b/src/typechecker/TypeCheckerCheck.cpp @@ -29,11 +29,11 @@ std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) { } std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { - node->resizeToNumberOfManifestations(node->fctManifestations.size()); + node->resizeToNumberOfManifestations(node->manifestations.size()); manIdx = 0; // Reset the manifestation index // Get all manifestations for this function definition - for (Function *manifestation : node->fctManifestations) { + for (Function *manifestation : node->manifestations) { // Skip non-substantiated or already checked functions if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { manIdx++; // Increase the manifestation index @@ -42,7 +42,7 @@ std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { // Change scope to concrete struct specialization scope if (node->isMethod) { - const auto structSignature = Struct::getSignature(node->fctName->structName, manifestation->thisType.getTemplateTypes()); + const auto structSignature = Struct::getSignature(node->name->structName, manifestation->thisType.getTemplateTypes()); changeToScope(STRUCT_SCOPE_PREFIX + structSignature, ScopeType::STRUCT); } @@ -85,11 +85,11 @@ std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { } std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { - node->resizeToNumberOfManifestations(node->procManifestations.size()); + node->resizeToNumberOfManifestations(node->manifestations.size()); manIdx = 0; // Reset the manifestation index // Get all manifestations for this procedure definition - for (auto &manifestation : node->procManifestations) { + for (auto &manifestation : node->manifestations) { // Skip non-substantiated or already checked procedures if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { manIdx++; // Increase the manifestation index @@ -98,7 +98,7 @@ std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { // Change scope to concrete struct specialization scope if (node->isMethod) { - const auto structSignature = Struct::getSignature(node->procName->structName, manifestation->thisType.getTemplateTypes()); + const auto structSignature = Struct::getSignature(node->name->structName, manifestation->thisType.getTemplateTypes()); changeToScope(STRUCT_SCOPE_PREFIX + structSignature, ScopeType::STRUCT); } diff --git a/src/typechecker/TypeCheckerPrepare.cpp b/src/typechecker/TypeCheckerPrepare.cpp index 3fe9e4a43..0975b6421 100644 --- a/src/typechecker/TypeCheckerPrepare.cpp +++ b/src/typechecker/TypeCheckerPrepare.cpp @@ -50,7 +50,7 @@ std::any TypeChecker::visitMainFctDefPrepare(MainFctDefNode *node) { std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) { // Check if name is dtor - if (node->fctName->name == DTOR_FUNCTION_NAME) + if (node->name->name == DTOR_FUNCTION_NAME) SOFT_ERROR_BOOL(node, DTOR_MUST_BE_PROCEDURE, "Destructors are not allowed to be of type function") // Check if all control paths in the function return @@ -58,7 +58,7 @@ std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) { SOFT_ERROR_BOOL(node, MISSING_RETURN_STMT, "Not all control paths of this function have a return statement") // Change to function scope - currentScope = node->fctScope; + currentScope = node->scope; assert(currentScope->type == ScopeType::FUNC_PROC_BODY); // Retrieve function template types @@ -73,7 +73,7 @@ std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) { if (!templateType.is(TY_GENERIC)) throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types"); // Convert generic symbol type to generic type - GenericType *genericType = node->fctScope->lookupGenericType(templateType.getSubType()); + GenericType *genericType = node->scope->lookupGenericType(templateType.getSubType()); assert(genericType != nullptr); usedGenericTypes.push_back(*genericType); } @@ -84,7 +84,7 @@ std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) { SymbolType thisPtrType = thisType; if (node->isMethod) { Scope *structParentScope = node->structScope->parent; - SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->fctName->structName); + SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName); assert(structEntry != nullptr); // Set struct to used structEntry->used = true; @@ -137,12 +137,12 @@ std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) { "Generic return type not included in the template type list of the function") // Leave function body scope - currentScope = node->fctScope->parent; + currentScope = node->scope->parent; assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT); // Prepare type of function SymbolType functionType(TY_FUNCTION); - functionType.specifiers = node->functionSpecifiers; + functionType.specifiers = node->specifiers; functionType.setFunctionReturnType(returnType); functionType.setFunctionParamTypes(paramTypes); @@ -152,23 +152,23 @@ std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) { functionEntry->updateType(functionType, false); // Build function object - Function spiceFunc(node->fctName->name, functionEntry, thisType, returnType, paramList, usedGenericTypes, node); - spiceFunc.bodyScope = node->fctScope; - FunctionManager::insertFunction(currentScope, spiceFunc, &node->fctManifestations); + Function spiceFunc(node->name->name, functionEntry, thisType, returnType, paramList, usedGenericTypes, node); + spiceFunc.bodyScope = node->scope; + FunctionManager::insertFunction(currentScope, spiceFunc, &node->manifestations); // Check function attributes if (node->attrs()) { if (AttrNode *attr = node->attrs()->attrLst()->getAttrByName(AttrNode::ATTR_CORE_COMPILER_MANGLE); attr != nullptr) - node->fctManifestations.front()->mangleFunctionName = attr->value()->compileTimeValue.boolValue; + node->manifestations.front()->mangleFunctionName = attr->value()->compileTimeValue.boolValue; if (AttrNode *attr = node->attrs()->attrLst()->getAttrByName(AttrNode::ATTR_CORE_COMPILER_MANGLED_NAME); attr != nullptr) - node->fctManifestations.front()->predefinedMangledName = attr->value()->compileTimeValue.stringValue; + node->manifestations.front()->predefinedMangledName = attr->value()->compileTimeValue.stringValue; } // Rename / duplicate the original child scope to reflect the substantiated versions of the function - currentScope->renameChildScope(node->getScopeId(), node->fctManifestations.front()->getSignature(false)); - for (size_t i = 1; i < node->fctManifestations.size(); i++) - currentScope->copyChildScope(node->fctManifestations.front()->getSignature(false), - node->fctManifestations.at(i)->getSignature(false)); + currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getSignature(false)); + for (size_t i = 1; i < node->manifestations.size(); i++) + currentScope->copyChildScope(node->manifestations.front()->getSignature(false), + node->manifestations.at(i)->getSignature(false)); // Change to the root scope currentScope = rootScope; @@ -182,11 +182,11 @@ std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) { node->returnsOnAllControlPaths(nullptr); // Check if dtor and has params - if (node->hasParams && node->procName->name == DTOR_FUNCTION_NAME) + if (node->hasParams && node->name->name == DTOR_FUNCTION_NAME) throw SemanticError(node, DTOR_WITH_PARAMS, "It is not allowed to specify parameters for destructors"); // Change to procedure scope - currentScope = node->procScope; + currentScope = node->scope; assert(currentScope->type == ScopeType::FUNC_PROC_BODY); // Retrieve procedure template types @@ -201,7 +201,7 @@ std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) { if (!templateType.is(TY_GENERIC)) throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types"); // Convert generic symbol type to generic type - GenericType *genericType = node->procScope->lookupGenericType(templateType.getSubType()); + GenericType *genericType = node->scope->lookupGenericType(templateType.getSubType()); assert(genericType != nullptr); usedGenericTypes.push_back(*genericType); } @@ -212,7 +212,7 @@ std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) { SymbolType thisPtrType = thisType; if (node->isMethod) { Scope *structParentScope = node->structScope->parent; - SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->procName->structName); + SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName); assert(structEntry != nullptr); // Set struct to used structEntry->used = true; @@ -256,12 +256,12 @@ std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) { SOFT_ERROR_BOOL(node->templateTypeLst(), GENERIC_TYPE_NOT_USED, "Generic type was not used by the function parameters") // Leave procedure body scope - currentScope = node->procScope->parent; + currentScope = node->scope->parent; assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT); // Prepare type of procedure SymbolType procedureType(TY_PROCEDURE); - procedureType.specifiers = node->procedureSpecifiers; + procedureType.specifiers = node->specifiers; procedureType.setFunctionParamTypes(paramTypes); // Update type of procedure entry @@ -270,23 +270,23 @@ std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) { procedureEntry->updateType(procedureType, false); // Build procedure object - Function spiceProc(node->procName->name, procedureEntry, thisType, SymbolType(TY_DYN), paramList, usedGenericTypes, node); - spiceProc.bodyScope = node->procScope; - FunctionManager::insertFunction(currentScope, spiceProc, &node->procManifestations); + Function spiceProc(node->name->name, procedureEntry, thisType, SymbolType(TY_DYN), paramList, usedGenericTypes, node); + spiceProc.bodyScope = node->scope; + FunctionManager::insertFunction(currentScope, spiceProc, &node->manifestations); // Check procedure attributes if (node->attrs()) { if (AttrNode *attr = node->attrs()->attrLst()->getAttrByName(AttrNode::ATTR_CORE_COMPILER_MANGLE); attr != nullptr) - node->procManifestations.front()->mangleFunctionName = attr->value()->compileTimeValue.boolValue; + node->manifestations.front()->mangleFunctionName = attr->value()->compileTimeValue.boolValue; if (AttrNode *attr = node->attrs()->attrLst()->getAttrByName(AttrNode::ATTR_CORE_COMPILER_MANGLED_NAME); attr != nullptr) - node->procManifestations.front()->predefinedMangledName = attr->value()->compileTimeValue.stringValue; + node->manifestations.front()->predefinedMangledName = attr->value()->compileTimeValue.stringValue; } // Rename / duplicate the original child scope to reflect the substantiated versions of the procedure - currentScope->renameChildScope(node->getScopeId(), node->procManifestations.front()->getSignature(false)); - for (size_t i = 1; i < node->procManifestations.size(); i++) - currentScope->copyChildScope(node->procManifestations.front()->getSignature(false), - node->procManifestations.at(i)->getSignature(false)); + currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getSignature(false)); + for (size_t i = 1; i < node->manifestations.size(); i++) + currentScope->copyChildScope(node->manifestations.front()->getSignature(false), + node->manifestations.at(i)->getSignature(false)); // Change to the root scope currentScope = rootScope; diff --git a/src/util/FileUtil.cpp b/src/util/FileUtil.cpp index 1fc2b9a6f..def6ce56b 100644 --- a/src/util/FileUtil.cpp +++ b/src/util/FileUtil.cpp @@ -18,9 +18,11 @@ namespace spice::compiler { * @param fileContent String to write into the file */ void FileUtil::writeToFile(const std::filesystem::path &filePath, const std::string &fileContent) { - std::ofstream file; - file.open(filePath); + std::ofstream file(filePath); + if (!file) + throw CompilerError(IO_ERROR, "Failed to open file: " + filePath.string()); file << fileContent; + file.flush(); file.close(); } @@ -31,10 +33,12 @@ void FileUtil::writeToFile(const std::filesystem::path &filePath, const std::str * @return File contents as a string */ std::string FileUtil::getFileContent(const std::filesystem::path &filePath) { - std::ifstream inputFileStream; - inputFileStream.open(filePath); - std::ostringstream stringStream; - stringStream << inputFileStream.rdbuf(); + std::ifstream file(filePath); + if (!file) + throw CompilerError(IO_ERROR, "Failed to open file: " + filePath.string()); + std::stringstream stringStream; + stringStream << file.rdbuf(); + file.close(); return stringStream.str(); } diff --git a/src/visualizer/ASTVisualizer.h b/src/visualizer/ASTVisualizer.h index 870f1b617..a4fa4dfc4 100644 --- a/src/visualizer/ASTVisualizer.h +++ b/src/visualizer/ASTVisualizer.h @@ -36,7 +36,7 @@ class ASTVisualizer : private CompilerPass, public AbstractASTVisitor { std::any visitAliasDef(AliasDefNode *ctx) override { return buildNode(ctx); } std::any visitGlobalVarDef(GlobalVarDefNode *ctx) override { return buildNode(ctx); } std::any visitExtDecl(ExtDeclNode *ctx) override { return buildNode(ctx); } - std::any visitUnsafeBlockDef(UnsafeBlockDefNode *ctx) override { return buildNode(ctx); } + std::any visitUnsafeBlock(UnsafeBlockNode *ctx) override { return buildNode(ctx); } std::any visitForLoop(ForLoopNode *ctx) override { return buildNode(ctx); } std::any visitForeachLoop(ForeachLoopNode *ctx) override { return buildNode(ctx); } std::any visitWhileLoop(WhileLoopNode *ctx) override { return buildNode(ctx); } diff --git a/src/visualizer/CSTVisualizer.h b/src/visualizer/CSTVisualizer.h index 38de02f26..2992ef2c7 100644 --- a/src/visualizer/CSTVisualizer.h +++ b/src/visualizer/CSTVisualizer.h @@ -37,7 +37,7 @@ class CSTVisualizer : private CompilerPass, public SpiceVisitor { std::any visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) override { return buildRule(ctx); } std::any visitEnumDef(SpiceParser::EnumDefContext *ctx) override { return buildRule(ctx); } std::any visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) override { return buildRule(ctx); } - std::any visitUnsafeBlockDef(SpiceParser::UnsafeBlockDefContext *ctx) override { return buildRule(ctx); } + std::any visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) override { return buildRule(ctx); } std::any visitForLoop(SpiceParser::ForLoopContext *ctx) override { return buildRule(ctx); } std::any visitForHead(SpiceParser::ForHeadContext *ctx) override { return buildRule(ctx); } std::any visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) override { return buildRule(ctx); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 447c8cdd9..d7c349f7c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,9 +3,11 @@ antlr_target(Spice ${CMAKE_CURRENT_SOURCE_DIR}/../src/Spice.g4 VISITOR) set(SOURCES main.cpp + driver/Driver.cpp + driver/Driver.h TestRunner.cpp util/TestUtil.cpp - util/TestUtil.h cli/CLIInterface.cpp cli/CLIInterface.h) + util/TestUtil.h) add_executable(spicetest ${SOURCES} ${ANTLR_Spice_CXX_OUTPUTS}) diff --git a/test/TestRunner.cpp b/test/TestRunner.cpp index 898ce1f3f..d37015016 100644 --- a/test/TestRunner.cpp +++ b/test/TestRunner.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include diff --git a/test/cli/CLIInterface.cpp b/test/driver/Driver.cpp similarity index 84% rename from test/cli/CLIInterface.cpp rename to test/driver/Driver.cpp index 6b7a53e8f..617b2fe56 100644 --- a/test/cli/CLIInterface.cpp +++ b/test/driver/Driver.cpp @@ -1,10 +1,10 @@ // Copyright (c) 2021-2023 ChilliBits. All rights reserved. -#include "CLIInterface.h" +#include "Driver.h" // GCOV_EXCL_START -void CLIInterface::createInterface() { +void Driver::createInterface() { // Allow positional args app.positionals_at_end(); app.require_subcommand(0); @@ -18,7 +18,7 @@ void CLIInterface::createInterface() { app.set_version_flag("--version,-v", versionString); } -void CLIInterface::addOptions(bool &updateRefs, bool &runBenchmarks, bool &enableLeakDetection, bool &skipNonGitHubTests) { +void Driver::addOptions(bool &updateRefs, bool &runBenchmarks, bool &enableLeakDetection, bool &skipNonGitHubTests) { // --update-refs app.add_flag("--update-refs,-u", updateRefs, "Update test reference files"); // --run-benchmarks @@ -36,7 +36,7 @@ void CLIInterface::addOptions(bool &updateRefs, bool &runBenchmarks, bool &enabl * @param argv Argument vector * @return Return code */ -int CLIInterface::parse(int argc, char **argv) { +int Driver::parse(int argc, char **argv) { try { app.parse(argc, argv); } catch (const CLI::ParseError &parseError) { diff --git a/test/cli/CLIInterface.h b/test/driver/Driver.h similarity index 90% rename from test/cli/CLIInterface.h rename to test/driver/Driver.h index 1fe8529cf..cb2eb57f4 100644 --- a/test/cli/CLIInterface.h +++ b/test/driver/Driver.h @@ -9,10 +9,10 @@ /** * Helper class to setup the cli interface and command line parser */ -class CLIInterface { +class Driver { public: // Constructors - explicit CLIInterface() = default; + explicit Driver() = default; // Public methods void createInterface(); diff --git a/test/main.cpp b/test/main.cpp index e4433862f..40775311e 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2021-2023 ChilliBits. All rights reserved. -#include "cli/CLIInterface.h" +#include "driver/Driver.h" #include @@ -21,11 +21,11 @@ bool skipNonGitHubTests = false; int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); // Initialize command line parser - CLIInterface cli; - cli.createInterface(); - cli.addOptions(updateRefs, runBenchmarks, enableLeakDetection, skipNonGitHubTests); + Driver driver; + driver.createInterface(); + driver.addOptions(updateRefs, runBenchmarks, enableLeakDetection, skipNonGitHubTests); // Parse command line args - cli.parse(argc, argv); + driver.parse(argc, argv); // Run tests return RUN_ALL_TESTS(); } diff --git a/test/test-files/benchmark/success-ackermann/assembly.asm b/test/test-files/benchmark/success-ackermann/assembly.asm index d9f8bf426..161388764 100644 --- a/test/test-files/benchmark/success-ackermann/assembly.asm +++ b/test/test-files/benchmark/success-ackermann/assembly.asm @@ -10,43 +10,49 @@ .scl 3; .type 32; .endef - .p2align 4, 0x90 -.L_Z3ackii: + .p2align 4, 0x90 # -- Begin function _Z3ackii +.L_Z3ackii: # @_Z3ackii +# %bb.0: pushq %rsi subq $32, %rsp movl %edx, %eax testl %ecx, %ecx je .LBB0_5 +# %bb.1: movl %ecx, %esi jmp .LBB0_2 .p2align 4, 0x90 -.LBB0_3: +.LBB0_3: # in Loop: Header=BB0_2 Depth=1 movl $1, %eax decl %esi je .LBB0_5 -.LBB0_2: +.LBB0_2: # %if.exit.L2 + # =>This Inner Loop Header: Depth=1 testl %eax, %eax je .LBB0_3 +# %bb.6: # %if.exit.L3 + # in Loop: Header=BB0_2 Depth=1 decl %eax movl %esi, %ecx movl %eax, %edx callq .L_Z3ackii decl %esi jne .LBB0_2 -.LBB0_5: +.LBB0_5: # %if.then.L2 incl %eax addq $32, %rsp popq %rsi retq - + # -- End function .def main; .scl 2; .type 32; .endef - .globl main + .globl main # -- Begin function main .p2align 4, 0x90 -main: +main: # @main .seh_proc main +# %bb.0: pushq %rbp .seh_pushreg %rbp subq $32, %rsp @@ -68,8 +74,8 @@ main: popq %rbp retq .seh_endproc - + # -- End function .section .rdata,"dr" -.Lprintf.str.0: +.Lprintf.str.0: # @printf.str.0 .asciz "Ackermann of base m=%d and n=%d: %d" diff --git a/test/test-files/benchmark/success-faculty/assembly.asm b/test/test-files/benchmark/success-faculty/assembly.asm index c58b2a395..415832ebc 100644 --- a/test/test-files/benchmark/success-faculty/assembly.asm +++ b/test/test-files/benchmark/success-faculty/assembly.asm @@ -11,36 +11,39 @@ .type 32; .endef .section .rdata,"dr" - .p2align 4, 0x0 + .p2align 4, 0x0 # -- Begin function _Z7facultyi .LCPI0_0: - .long 0 - .long 4294967295 - .long 4294967294 - .long 4294967293 + .long 0 # 0x0 + .long 4294967295 # 0xffffffff + .long 4294967294 # 0xfffffffe + .long 4294967293 # 0xfffffffd .LCPI0_1: - .long 1 - .long 1 - .long 1 - .long 1 + .long 1 # 0x1 + .long 1 # 0x1 + .long 1 # 0x1 + .long 1 # 0x1 .LCPI0_2: - .long 4294967292 - .long 4294967292 - .long 4294967292 - .long 4294967292 + .long 4294967292 # 0xfffffffc + .long 4294967292 # 0xfffffffc + .long 4294967292 # 0xfffffffc + .long 4294967292 # 0xfffffffc .LCPI0_3: - .long 4294967288 - .long 4294967288 - .long 4294967288 - .long 4294967288 + .long 4294967288 # 0xfffffff8 + .long 4294967288 # 0xfffffff8 + .long 4294967288 # 0xfffffff8 + .long 4294967288 # 0xfffffff8 .text .p2align 4, 0x90 -.L_Z7facultyi: +.L_Z7facultyi: # @_Z7facultyi +# %bb.0: subq $40, %rsp - movdqa %xmm7, 16(%rsp) - movdqa %xmm6, (%rsp) + movdqa %xmm7, 16(%rsp) # 16-byte Spill + movdqa %xmm6, (%rsp) # 16-byte Spill + # kill: def $ecx killed $ecx def $rcx movl $1, %eax cmpl $2, %ecx jl .LBB0_6 +# %bb.1: # %if.exit.L2.preheader xorl %eax, %eax movl %ecx, %edx subl $2, %edx @@ -48,76 +51,81 @@ movl $1, %eax cmpl $7, %edx jb .LBB0_5 +# %bb.2: # %vector.ph incl %edx movl %edx, %r8d andl $-8, %r8d movd %ecx, %xmm0 subl %r8d, %ecx - pshufd $0, %xmm0, %xmm0 + pshufd $0, %xmm0, %xmm0 # xmm0 = xmm0[0,0,0,0] paddd .LCPI0_0(%rip), %xmm0 movl %r8d, %eax negl %eax - movdqa .LCPI0_1(%rip), %xmm1 - movdqa .LCPI0_2(%rip), %xmm3 - movdqa .LCPI0_3(%rip), %xmm4 + movdqa .LCPI0_1(%rip), %xmm1 # xmm1 = [1,1,1,1] + movdqa .LCPI0_2(%rip), %xmm3 # xmm3 = [4294967292,4294967292,4294967292,4294967292] + movdqa .LCPI0_3(%rip), %xmm4 # xmm4 = [4294967288,4294967288,4294967288,4294967288] movdqa %xmm1, %xmm2 .p2align 4, 0x90 -.LBB0_3: +.LBB0_3: # %vector.body + # =>This Inner Loop Header: Depth=1 movdqa %xmm0, %xmm5 paddd %xmm3, %xmm5 movdqa %xmm0, %xmm6 pmuludq %xmm1, %xmm6 - pshufd $245, %xmm1, %xmm1 - pshufd $232, %xmm6, %xmm6 - pshufd $245, %xmm0, %xmm7 + pshufd $245, %xmm1, %xmm1 # xmm1 = xmm1[1,1,3,3] + pshufd $232, %xmm6, %xmm6 # xmm6 = xmm6[0,2,2,3] + pshufd $245, %xmm0, %xmm7 # xmm7 = xmm0[1,1,3,3] pmuludq %xmm1, %xmm7 - pshufd $232, %xmm7, %xmm7 + pshufd $232, %xmm7, %xmm7 # xmm7 = xmm7[0,2,2,3] movdqa %xmm6, %xmm1 - punpckldq %xmm7, %xmm1 - pshufd $245, %xmm5, %xmm6 + punpckldq %xmm7, %xmm1 # xmm1 = xmm1[0],xmm7[0],xmm1[1],xmm7[1] + pshufd $245, %xmm5, %xmm6 # xmm6 = xmm5[1,1,3,3] pmuludq %xmm2, %xmm5 - pshufd $245, %xmm2, %xmm2 - pshufd $232, %xmm5, %xmm5 + pshufd $245, %xmm2, %xmm2 # xmm2 = xmm2[1,1,3,3] + pshufd $232, %xmm5, %xmm5 # xmm5 = xmm5[0,2,2,3] pmuludq %xmm6, %xmm2 - pshufd $232, %xmm2, %xmm6 + pshufd $232, %xmm2, %xmm6 # xmm6 = xmm2[0,2,2,3] movdqa %xmm5, %xmm2 - punpckldq %xmm6, %xmm2 + punpckldq %xmm6, %xmm2 # xmm2 = xmm2[0],xmm6[0],xmm2[1],xmm6[1] paddd %xmm4, %xmm0 addl $8, %eax jne .LBB0_3 - pshufd $245, %xmm1, %xmm0 - pshufd $245, %xmm2, %xmm3 +# %bb.4: # %middle.block + pshufd $245, %xmm1, %xmm0 # xmm0 = xmm1[1,1,3,3] + pshufd $245, %xmm2, %xmm3 # xmm3 = xmm2[1,1,3,3] pmuludq %xmm0, %xmm3 pmuludq %xmm1, %xmm2 - pshufd $238, %xmm2, %xmm0 + pshufd $238, %xmm2, %xmm0 # xmm0 = xmm2[2,3,2,3] pmuludq %xmm2, %xmm0 - pshufd $170, %xmm3, %xmm1 + pshufd $170, %xmm3, %xmm1 # xmm1 = xmm3[2,2,2,2] pmuludq %xmm3, %xmm1 pmuludq %xmm0, %xmm1 movd %xmm1, %eax cmpl %r8d, %edx je .LBB0_6 .p2align 4, 0x90 -.LBB0_5: +.LBB0_5: # %if.exit.L2 + # =>This Inner Loop Header: Depth=1 imull %ecx, %eax leal -1(%rcx), %edx cmpl $3, %ecx movl %edx, %ecx jae .LBB0_5 -.LBB0_6: - movaps (%rsp), %xmm6 - movaps 16(%rsp), %xmm7 +.LBB0_6: # %common.ret + movaps (%rsp), %xmm6 # 16-byte Reload + movaps 16(%rsp), %xmm7 # 16-byte Reload addq $40, %rsp retq - + # -- End function .def main; .scl 2; .type 32; .endef - .globl main + .globl main # -- Begin function main .p2align 4, 0x90 -main: +main: # @main .seh_proc main +# %bb.0: pushq %rbp .seh_pushreg %rbp subq $32, %rsp @@ -137,8 +145,8 @@ main: popq %rbp retq .seh_endproc - + # -- End function .section .rdata,"dr" -.Lprintf.str.0: +.Lprintf.str.0: # @printf.str.0 .asciz "Faculty of %d is: %d" diff --git a/test/test-files/benchmark/success-fibonacci-threaded/assembly.asm b/test/test-files/benchmark/success-fibonacci-threaded/assembly.asm index 136d493ab..3aa4df9a6 100644 --- a/test/test-files/benchmark/success-fibonacci-threaded/assembly.asm +++ b/test/test-files/benchmark/success-fibonacci-threaded/assembly.asm @@ -10,19 +10,22 @@ .scl 3; .type 32; .endef - .p2align 4, 0x90 -.L_Z3fibi: + .p2align 4, 0x90 # -- Begin function _Z3fibi +.L_Z3fibi: # @_Z3fibi +# %bb.0: pushq %rsi pushq %rdi subq $40, %rsp movl $1, %esi cmpl $3, %ecx jl .LBB0_4 +# %bb.1: # %if.exit.L4.preheader movl %ecx, %edi decl %edi xorl %esi, %esi .p2align 4, 0x90 -.LBB0_2: +.LBB0_2: # %if.exit.L4 + # =>This Inner Loop Header: Depth=1 movl %edi, %ecx callq .L_Z3fibi addl %eax, %esi @@ -31,22 +34,24 @@ cmpl $5, %edi movl %eax, %edi jae .LBB0_2 +# %bb.3: # %common.ret.loopexit incl %esi -.LBB0_4: +.LBB0_4: # %common.ret movl %esi, %eax addq $40, %rsp popq %rdi popq %rsi retq - + # -- End function .def main; .scl 2; .type 32; .endef - .globl main + .globl main # -- Begin function main .p2align 4, 0x90 -main: +main: # @main .seh_proc main +# %bb.0: # %for.body.L11 pushq %rbp .seh_pushreg %rbp pushq %r15 @@ -208,13 +213,14 @@ main: popq %rbp retq .seh_endproc - + # -- End function .def .L_Z15lambda.L12C29.0v; .scl 3; .type 32; .endef - .p2align 4, 0x90 -.L_Z15lambda.L12C29.0v: + .p2align 4, 0x90 # -- Begin function _Z15lambda.L12C29.0v +.L_Z15lambda.L12C29.0v: # @_Z15lambda.L12C29.0v +# %bb.0: subq $40, %rsp movl $30, %ecx callq .L_Z3fibi @@ -223,14 +229,14 @@ main: callq printf addq $40, %rsp retq - + # -- End function .section .rdata,"dr" -.Lprintf.str.0: +.Lprintf.str.0: # @printf.str.0 .asciz "Thread returned with result: %d\n" -.Lprintf.str.2: +.Lprintf.str.2: # @printf.str.2 .asciz "Program finished" -.Lstr: +.Lstr: # @str .asciz "Started all threads. Waiting for results ..." diff --git a/test/test-files/benchmark/success-fibonacci-threaded/parse-tree.dot b/test/test-files/benchmark/success-fibonacci-threaded/parse-tree.dot index 335750130..635216b81 100644 --- a/test/test-files/benchmark/success-fibonacci-threaded/parse-tree.dot +++ b/test/test-files/benchmark/success-fibonacci-threaded/parse-tree.dot @@ -782,92 +782,92 @@ digraph { L13C12_dataType -> L13C12_baseDataType; L13C12 [color="lightblue",label="TYPE_INT: int"]; L13C12_baseDataType -> L13C12 - L13C16 [color="lightblue",label="IDENTIFIER: result"]; + L13C16 [color="lightblue",label="IDENTIFIER: res"]; L13C12_declStmt -> L13C16 - L13C23 [color="lightblue",label="ASSIGN: ="]; - L13C12_declStmt -> L13C23 - L13C25_assignExpr [color="lightgreen",label="assignExpr"]; - L13C12_declStmt -> L13C25_assignExpr; - L13C25_ternaryExpr [color="lightgreen",label="ternaryExpr"]; - L13C25_assignExpr -> L13C25_ternaryExpr; - L13C25_logicalOrExpr [color="lightgreen",label="logicalOrExpr"]; - L13C25_ternaryExpr -> L13C25_logicalOrExpr; - L13C25_logicalAndExpr [color="lightgreen",label="logicalAndExpr"]; - L13C25_logicalOrExpr -> L13C25_logicalAndExpr; - L13C25_bitwiseOrExpr [color="lightgreen",label="bitwiseOrExpr"]; - L13C25_logicalAndExpr -> L13C25_bitwiseOrExpr; - L13C25_bitwiseXorExpr [color="lightgreen",label="bitwiseXorExpr"]; - L13C25_bitwiseOrExpr -> L13C25_bitwiseXorExpr; - L13C25_bitwiseAndExpr [color="lightgreen",label="bitwiseAndExpr"]; - L13C25_bitwiseXorExpr -> L13C25_bitwiseAndExpr; - L13C25_equalityExpr [color="lightgreen",label="equalityExpr"]; - L13C25_bitwiseAndExpr -> L13C25_equalityExpr; - L13C25_relationalExpr [color="lightgreen",label="relationalExpr"]; - L13C25_equalityExpr -> L13C25_relationalExpr; - L13C25_shiftExpr [color="lightgreen",label="shiftExpr"]; - L13C25_relationalExpr -> L13C25_shiftExpr; - L13C25_additiveExpr [color="lightgreen",label="additiveExpr"]; - L13C25_shiftExpr -> L13C25_additiveExpr; - L13C25_multiplicativeExpr [color="lightgreen",label="multiplicativeExpr"]; - L13C25_additiveExpr -> L13C25_multiplicativeExpr; - L13C25_castExpr [color="lightgreen",label="castExpr"]; - L13C25_multiplicativeExpr -> L13C25_castExpr; - L13C25_prefixUnaryExpr [color="lightgreen",label="prefixUnaryExpr"]; - L13C25_castExpr -> L13C25_prefixUnaryExpr; - L13C25_postfixUnaryExpr [color="lightgreen",label="postfixUnaryExpr"]; - L13C25_prefixUnaryExpr -> L13C25_postfixUnaryExpr; - L13C25_atomicExpr [color="lightgreen",label="atomicExpr"]; - L13C25_postfixUnaryExpr -> L13C25_atomicExpr; - L13C25_value [color="lightgreen",label="value"]; - L13C25_atomicExpr -> L13C25_value; - L13C25_fctCall [color="lightgreen",label="fctCall"]; - L13C25_value -> L13C25_fctCall; - L13C25 [color="lightblue",label="IDENTIFIER: fib"]; - L13C25_fctCall -> L13C25 - L13C28 [color="lightblue",label="LPAREN: ("]; - L13C25_fctCall -> L13C28 - L13C29_argLst [color="lightgreen",label="argLst"]; - L13C25_fctCall -> L13C29_argLst; - L13C29_assignExpr [color="lightgreen",label="assignExpr"]; - L13C29_argLst -> L13C29_assignExpr; - L13C29_ternaryExpr [color="lightgreen",label="ternaryExpr"]; - L13C29_assignExpr -> L13C29_ternaryExpr; - L13C29_logicalOrExpr [color="lightgreen",label="logicalOrExpr"]; - L13C29_ternaryExpr -> L13C29_logicalOrExpr; - L13C29_logicalAndExpr [color="lightgreen",label="logicalAndExpr"]; - L13C29_logicalOrExpr -> L13C29_logicalAndExpr; - L13C29_bitwiseOrExpr [color="lightgreen",label="bitwiseOrExpr"]; - L13C29_logicalAndExpr -> L13C29_bitwiseOrExpr; - L13C29_bitwiseXorExpr [color="lightgreen",label="bitwiseXorExpr"]; - L13C29_bitwiseOrExpr -> L13C29_bitwiseXorExpr; - L13C29_bitwiseAndExpr [color="lightgreen",label="bitwiseAndExpr"]; - L13C29_bitwiseXorExpr -> L13C29_bitwiseAndExpr; - L13C29_equalityExpr [color="lightgreen",label="equalityExpr"]; - L13C29_bitwiseAndExpr -> L13C29_equalityExpr; - L13C29_relationalExpr [color="lightgreen",label="relationalExpr"]; - L13C29_equalityExpr -> L13C29_relationalExpr; - L13C29_shiftExpr [color="lightgreen",label="shiftExpr"]; - L13C29_relationalExpr -> L13C29_shiftExpr; - L13C29_additiveExpr [color="lightgreen",label="additiveExpr"]; - L13C29_shiftExpr -> L13C29_additiveExpr; - L13C29_multiplicativeExpr [color="lightgreen",label="multiplicativeExpr"]; - L13C29_additiveExpr -> L13C29_multiplicativeExpr; - L13C29_castExpr [color="lightgreen",label="castExpr"]; - L13C29_multiplicativeExpr -> L13C29_castExpr; - L13C29_prefixUnaryExpr [color="lightgreen",label="prefixUnaryExpr"]; - L13C29_castExpr -> L13C29_prefixUnaryExpr; - L13C29_postfixUnaryExpr [color="lightgreen",label="postfixUnaryExpr"]; - L13C29_prefixUnaryExpr -> L13C29_postfixUnaryExpr; - L13C29_atomicExpr [color="lightgreen",label="atomicExpr"]; - L13C29_postfixUnaryExpr -> L13C29_atomicExpr; - L13C29_constant [color="lightgreen",label="constant"]; - L13C29_atomicExpr -> L13C29_constant; - L13C29 [color="lightblue",label="INT_LIT: 30"]; - L13C29_constant -> L13C29 - L13C31 [color="lightblue",label="RPAREN: )"]; - L13C25_fctCall -> L13C31 - L13C32 [color="lightblue",label="SEMICOLON: ;"]; - L13C12_stmt -> L13C32 + L13C20 [color="lightblue",label="ASSIGN: ="]; + L13C12_declStmt -> L13C20 + L13C22_assignExpr [color="lightgreen",label="assignExpr"]; + L13C12_declStmt -> L13C22_assignExpr; + L13C22_ternaryExpr [color="lightgreen",label="ternaryExpr"]; + L13C22_assignExpr -> L13C22_ternaryExpr; + L13C22_logicalOrExpr [color="lightgreen",label="logicalOrExpr"]; + L13C22_ternaryExpr -> L13C22_logicalOrExpr; + L13C22_logicalAndExpr [color="lightgreen",label="logicalAndExpr"]; + L13C22_logicalOrExpr -> L13C22_logicalAndExpr; + L13C22_bitwiseOrExpr [color="lightgreen",label="bitwiseOrExpr"]; + L13C22_logicalAndExpr -> L13C22_bitwiseOrExpr; + L13C22_bitwiseXorExpr [color="lightgreen",label="bitwiseXorExpr"]; + L13C22_bitwiseOrExpr -> L13C22_bitwiseXorExpr; + L13C22_bitwiseAndExpr [color="lightgreen",label="bitwiseAndExpr"]; + L13C22_bitwiseXorExpr -> L13C22_bitwiseAndExpr; + L13C22_equalityExpr [color="lightgreen",label="equalityExpr"]; + L13C22_bitwiseAndExpr -> L13C22_equalityExpr; + L13C22_relationalExpr [color="lightgreen",label="relationalExpr"]; + L13C22_equalityExpr -> L13C22_relationalExpr; + L13C22_shiftExpr [color="lightgreen",label="shiftExpr"]; + L13C22_relationalExpr -> L13C22_shiftExpr; + L13C22_additiveExpr [color="lightgreen",label="additiveExpr"]; + L13C22_shiftExpr -> L13C22_additiveExpr; + L13C22_multiplicativeExpr [color="lightgreen",label="multiplicativeExpr"]; + L13C22_additiveExpr -> L13C22_multiplicativeExpr; + L13C22_castExpr [color="lightgreen",label="castExpr"]; + L13C22_multiplicativeExpr -> L13C22_castExpr; + L13C22_prefixUnaryExpr [color="lightgreen",label="prefixUnaryExpr"]; + L13C22_castExpr -> L13C22_prefixUnaryExpr; + L13C22_postfixUnaryExpr [color="lightgreen",label="postfixUnaryExpr"]; + L13C22_prefixUnaryExpr -> L13C22_postfixUnaryExpr; + L13C22_atomicExpr [color="lightgreen",label="atomicExpr"]; + L13C22_postfixUnaryExpr -> L13C22_atomicExpr; + L13C22_value [color="lightgreen",label="value"]; + L13C22_atomicExpr -> L13C22_value; + L13C22_fctCall [color="lightgreen",label="fctCall"]; + L13C22_value -> L13C22_fctCall; + L13C22 [color="lightblue",label="IDENTIFIER: fib"]; + L13C22_fctCall -> L13C22 + L13C25 [color="lightblue",label="LPAREN: ("]; + L13C22_fctCall -> L13C25 + L13C26_argLst [color="lightgreen",label="argLst"]; + L13C22_fctCall -> L13C26_argLst; + L13C26_assignExpr [color="lightgreen",label="assignExpr"]; + L13C26_argLst -> L13C26_assignExpr; + L13C26_ternaryExpr [color="lightgreen",label="ternaryExpr"]; + L13C26_assignExpr -> L13C26_ternaryExpr; + L13C26_logicalOrExpr [color="lightgreen",label="logicalOrExpr"]; + L13C26_ternaryExpr -> L13C26_logicalOrExpr; + L13C26_logicalAndExpr [color="lightgreen",label="logicalAndExpr"]; + L13C26_logicalOrExpr -> L13C26_logicalAndExpr; + L13C26_bitwiseOrExpr [color="lightgreen",label="bitwiseOrExpr"]; + L13C26_logicalAndExpr -> L13C26_bitwiseOrExpr; + L13C26_bitwiseXorExpr [color="lightgreen",label="bitwiseXorExpr"]; + L13C26_bitwiseOrExpr -> L13C26_bitwiseXorExpr; + L13C26_bitwiseAndExpr [color="lightgreen",label="bitwiseAndExpr"]; + L13C26_bitwiseXorExpr -> L13C26_bitwiseAndExpr; + L13C26_equalityExpr [color="lightgreen",label="equalityExpr"]; + L13C26_bitwiseAndExpr -> L13C26_equalityExpr; + L13C26_relationalExpr [color="lightgreen",label="relationalExpr"]; + L13C26_equalityExpr -> L13C26_relationalExpr; + L13C26_shiftExpr [color="lightgreen",label="shiftExpr"]; + L13C26_relationalExpr -> L13C26_shiftExpr; + L13C26_additiveExpr [color="lightgreen",label="additiveExpr"]; + L13C26_shiftExpr -> L13C26_additiveExpr; + L13C26_multiplicativeExpr [color="lightgreen",label="multiplicativeExpr"]; + L13C26_additiveExpr -> L13C26_multiplicativeExpr; + L13C26_castExpr [color="lightgreen",label="castExpr"]; + L13C26_multiplicativeExpr -> L13C26_castExpr; + L13C26_prefixUnaryExpr [color="lightgreen",label="prefixUnaryExpr"]; + L13C26_castExpr -> L13C26_prefixUnaryExpr; + L13C26_postfixUnaryExpr [color="lightgreen",label="postfixUnaryExpr"]; + L13C26_prefixUnaryExpr -> L13C26_postfixUnaryExpr; + L13C26_atomicExpr [color="lightgreen",label="atomicExpr"]; + L13C26_postfixUnaryExpr -> L13C26_atomicExpr; + L13C26_constant [color="lightgreen",label="constant"]; + L13C26_atomicExpr -> L13C26_constant; + L13C26 [color="lightblue",label="INT_LIT: 30"]; + L13C26_constant -> L13C26 + L13C28 [color="lightblue",label="RPAREN: )"]; + L13C22_fctCall -> L13C28 + L13C29 [color="lightblue",label="SEMICOLON: ;"]; + L13C12_stmt -> L13C29 L14C12_stmt [color="lightgreen",label="stmt"]; L13C12_stmtLst -> L14C12_stmt; L14C12_assignExpr [color="lightgreen",label="assignExpr"]; @@ -946,12 +946,12 @@ digraph { L14C56_prefixUnaryExpr -> L14C56_postfixUnaryExpr; L14C56_atomicExpr [color="lightgreen",label="atomicExpr"]; L14C56_postfixUnaryExpr -> L14C56_atomicExpr; - L14C56 [color="lightblue",label="IDENTIFIER: result"]; + L14C56 [color="lightblue",label="IDENTIFIER: res"]; L14C56_atomicExpr -> L14C56 - L14C62 [color="lightblue",label="RPAREN: )"]; - L14C12_printfCall -> L14C62 - L14C63 [color="lightblue",label="SEMICOLON: ;"]; - L14C12_stmt -> L14C63 + L14C59 [color="lightblue",label="RPAREN: )"]; + L14C12_printfCall -> L14C59 + L14C60 [color="lightblue",label="SEMICOLON: ;"]; + L14C12_stmt -> L14C60 L15C8 [color="lightblue",label="RBRACE: }"]; L12C28_lambdaProc -> L15C8 L15C9 [color="lightblue",label="RPAREN: )"]; diff --git a/test/test-files/benchmark/success-fibonacci-threaded/source.spice b/test/test-files/benchmark/success-fibonacci-threaded/source.spice index 833781b54..24a3cdeb6 100644 --- a/test/test-files/benchmark/success-fibonacci-threaded/source.spice +++ b/test/test-files/benchmark/success-fibonacci-threaded/source.spice @@ -10,8 +10,8 @@ f main() { Thread[8] threads = []; for unsigned int i = 0; i < threadCount; i++ { threads[i] = Thread(p() { - int result = fib(30); - printf("Thread returned with result: %d\n", result); + int res = fib(30); + printf("Thread returned with result: %d\n", res); }); Thread& thread = threads[i]; thread.run(); diff --git a/test/test-files/benchmark/success-fibonacci-threaded/symbol-table.json b/test/test-files/benchmark/success-fibonacci-threaded/symbol-table.json index c7624b4a0..7c9fca922 100644 --- a/test/test-files/benchmark/success-fibonacci-threaded/symbol-table.json +++ b/test/test-files/benchmark/success-fibonacci-threaded/symbol-table.json @@ -73,7 +73,7 @@ "codeLoc": "L13C13", "isGlobal": false, "isVolatile": false, - "name": "result", + "name": "res", "orderIndex": 0, "state": "initialized", "type": "int" diff --git a/test/test-files/benchmark/success-fibonacci-threaded/syntax-tree.dot b/test/test-files/benchmark/success-fibonacci-threaded/syntax-tree.dot index 8e7e2f32c..961c5e284 100644 --- a/test/test-files/benchmark/success-fibonacci-threaded/syntax-tree.dot +++ b/test/test-files/benchmark/success-fibonacci-threaded/syntax-tree.dot @@ -606,78 +606,78 @@ digraph { L13C13_DeclStmtNode -> L13C13_DataTypeNode; L13C13_BaseDataTypeNode [color="lightgreen",label="BaseDataTypeNode"]; L13C13_DataTypeNode -> L13C13_BaseDataTypeNode; - L13C26_AssignExprNode [color="lightgreen",label="AssignExprNode"]; - L13C13_DeclStmtNode -> L13C26_AssignExprNode; - L13C26_TernaryExprNode [color="lightgreen",label="TernaryExprNode"]; - L13C26_AssignExprNode -> L13C26_TernaryExprNode; - L13C26_LogicalOrExprNode [color="lightgreen",label="LogicalOrExprNode"]; - L13C26_TernaryExprNode -> L13C26_LogicalOrExprNode; - L13C26_LogicalAndExprNode [color="lightgreen",label="LogicalAndExprNode"]; - L13C26_LogicalOrExprNode -> L13C26_LogicalAndExprNode; - L13C26_BitwiseOrExprNode [color="lightgreen",label="BitwiseOrExprNode"]; - L13C26_LogicalAndExprNode -> L13C26_BitwiseOrExprNode; - L13C26_BitwiseXorExprNode [color="lightgreen",label="BitwiseXorExprNode"]; - L13C26_BitwiseOrExprNode -> L13C26_BitwiseXorExprNode; - L13C26_BitwiseAndExprNode [color="lightgreen",label="BitwiseAndExprNode"]; - L13C26_BitwiseXorExprNode -> L13C26_BitwiseAndExprNode; - L13C26_EqualityExprNode [color="lightgreen",label="EqualityExprNode"]; - L13C26_BitwiseAndExprNode -> L13C26_EqualityExprNode; - L13C26_RelationalExprNode [color="lightgreen",label="RelationalExprNode"]; - L13C26_EqualityExprNode -> L13C26_RelationalExprNode; - L13C26_ShiftExprNode [color="lightgreen",label="ShiftExprNode"]; - L13C26_RelationalExprNode -> L13C26_ShiftExprNode; - L13C26_AdditiveExprNode [color="lightgreen",label="AdditiveExprNode"]; - L13C26_ShiftExprNode -> L13C26_AdditiveExprNode; - L13C26_MultiplicativeExprNode [color="lightgreen",label="MultiplicativeExprNode"]; - L13C26_AdditiveExprNode -> L13C26_MultiplicativeExprNode; - L13C26_CastExprNode [color="lightgreen",label="CastExprNode"]; - L13C26_MultiplicativeExprNode -> L13C26_CastExprNode; - L13C26_PrefixUnaryExprNode [color="lightgreen",label="PrefixUnaryExprNode"]; - L13C26_CastExprNode -> L13C26_PrefixUnaryExprNode; - L13C26_PostfixUnaryExprNode [color="lightgreen",label="PostfixUnaryExprNode"]; - L13C26_PrefixUnaryExprNode -> L13C26_PostfixUnaryExprNode; - L13C26_AtomicExprNode [color="lightgreen",label="AtomicExprNode"]; - L13C26_PostfixUnaryExprNode -> L13C26_AtomicExprNode; - L13C26_ValueNode [color="lightgreen",label="ValueNode"]; - L13C26_AtomicExprNode -> L13C26_ValueNode; - L13C26_FctCallNode [color="lightgreen",label="FctCallNode"]; - L13C26_ValueNode -> L13C26_FctCallNode; - L13C30_ArgLstNode [color="lightgreen",label="ArgLstNode"]; - L13C26_FctCallNode -> L13C30_ArgLstNode; - L13C30_AssignExprNode [color="lightgreen",label="AssignExprNode"]; - L13C30_ArgLstNode -> L13C30_AssignExprNode; - L13C30_TernaryExprNode [color="lightgreen",label="TernaryExprNode"]; - L13C30_AssignExprNode -> L13C30_TernaryExprNode; - L13C30_LogicalOrExprNode [color="lightgreen",label="LogicalOrExprNode"]; - L13C30_TernaryExprNode -> L13C30_LogicalOrExprNode; - L13C30_LogicalAndExprNode [color="lightgreen",label="LogicalAndExprNode"]; - L13C30_LogicalOrExprNode -> L13C30_LogicalAndExprNode; - L13C30_BitwiseOrExprNode [color="lightgreen",label="BitwiseOrExprNode"]; - L13C30_LogicalAndExprNode -> L13C30_BitwiseOrExprNode; - L13C30_BitwiseXorExprNode [color="lightgreen",label="BitwiseXorExprNode"]; - L13C30_BitwiseOrExprNode -> L13C30_BitwiseXorExprNode; - L13C30_BitwiseAndExprNode [color="lightgreen",label="BitwiseAndExprNode"]; - L13C30_BitwiseXorExprNode -> L13C30_BitwiseAndExprNode; - L13C30_EqualityExprNode [color="lightgreen",label="EqualityExprNode"]; - L13C30_BitwiseAndExprNode -> L13C30_EqualityExprNode; - L13C30_RelationalExprNode [color="lightgreen",label="RelationalExprNode"]; - L13C30_EqualityExprNode -> L13C30_RelationalExprNode; - L13C30_ShiftExprNode [color="lightgreen",label="ShiftExprNode"]; - L13C30_RelationalExprNode -> L13C30_ShiftExprNode; - L13C30_AdditiveExprNode [color="lightgreen",label="AdditiveExprNode"]; - L13C30_ShiftExprNode -> L13C30_AdditiveExprNode; - L13C30_MultiplicativeExprNode [color="lightgreen",label="MultiplicativeExprNode"]; - L13C30_AdditiveExprNode -> L13C30_MultiplicativeExprNode; - L13C30_CastExprNode [color="lightgreen",label="CastExprNode"]; - L13C30_MultiplicativeExprNode -> L13C30_CastExprNode; - L13C30_PrefixUnaryExprNode [color="lightgreen",label="PrefixUnaryExprNode"]; - L13C30_CastExprNode -> L13C30_PrefixUnaryExprNode; - L13C30_PostfixUnaryExprNode [color="lightgreen",label="PostfixUnaryExprNode"]; - L13C30_PrefixUnaryExprNode -> L13C30_PostfixUnaryExprNode; - L13C30_AtomicExprNode [color="lightgreen",label="AtomicExprNode"]; - L13C30_PostfixUnaryExprNode -> L13C30_AtomicExprNode; - L13C30_ConstantNode [color="lightgreen",label="ConstantNode"]; - L13C30_AtomicExprNode -> L13C30_ConstantNode; + L13C23_AssignExprNode [color="lightgreen",label="AssignExprNode"]; + L13C13_DeclStmtNode -> L13C23_AssignExprNode; + L13C23_TernaryExprNode [color="lightgreen",label="TernaryExprNode"]; + L13C23_AssignExprNode -> L13C23_TernaryExprNode; + L13C23_LogicalOrExprNode [color="lightgreen",label="LogicalOrExprNode"]; + L13C23_TernaryExprNode -> L13C23_LogicalOrExprNode; + L13C23_LogicalAndExprNode [color="lightgreen",label="LogicalAndExprNode"]; + L13C23_LogicalOrExprNode -> L13C23_LogicalAndExprNode; + L13C23_BitwiseOrExprNode [color="lightgreen",label="BitwiseOrExprNode"]; + L13C23_LogicalAndExprNode -> L13C23_BitwiseOrExprNode; + L13C23_BitwiseXorExprNode [color="lightgreen",label="BitwiseXorExprNode"]; + L13C23_BitwiseOrExprNode -> L13C23_BitwiseXorExprNode; + L13C23_BitwiseAndExprNode [color="lightgreen",label="BitwiseAndExprNode"]; + L13C23_BitwiseXorExprNode -> L13C23_BitwiseAndExprNode; + L13C23_EqualityExprNode [color="lightgreen",label="EqualityExprNode"]; + L13C23_BitwiseAndExprNode -> L13C23_EqualityExprNode; + L13C23_RelationalExprNode [color="lightgreen",label="RelationalExprNode"]; + L13C23_EqualityExprNode -> L13C23_RelationalExprNode; + L13C23_ShiftExprNode [color="lightgreen",label="ShiftExprNode"]; + L13C23_RelationalExprNode -> L13C23_ShiftExprNode; + L13C23_AdditiveExprNode [color="lightgreen",label="AdditiveExprNode"]; + L13C23_ShiftExprNode -> L13C23_AdditiveExprNode; + L13C23_MultiplicativeExprNode [color="lightgreen",label="MultiplicativeExprNode"]; + L13C23_AdditiveExprNode -> L13C23_MultiplicativeExprNode; + L13C23_CastExprNode [color="lightgreen",label="CastExprNode"]; + L13C23_MultiplicativeExprNode -> L13C23_CastExprNode; + L13C23_PrefixUnaryExprNode [color="lightgreen",label="PrefixUnaryExprNode"]; + L13C23_CastExprNode -> L13C23_PrefixUnaryExprNode; + L13C23_PostfixUnaryExprNode [color="lightgreen",label="PostfixUnaryExprNode"]; + L13C23_PrefixUnaryExprNode -> L13C23_PostfixUnaryExprNode; + L13C23_AtomicExprNode [color="lightgreen",label="AtomicExprNode"]; + L13C23_PostfixUnaryExprNode -> L13C23_AtomicExprNode; + L13C23_ValueNode [color="lightgreen",label="ValueNode"]; + L13C23_AtomicExprNode -> L13C23_ValueNode; + L13C23_FctCallNode [color="lightgreen",label="FctCallNode"]; + L13C23_ValueNode -> L13C23_FctCallNode; + L13C27_ArgLstNode [color="lightgreen",label="ArgLstNode"]; + L13C23_FctCallNode -> L13C27_ArgLstNode; + L13C27_AssignExprNode [color="lightgreen",label="AssignExprNode"]; + L13C27_ArgLstNode -> L13C27_AssignExprNode; + L13C27_TernaryExprNode [color="lightgreen",label="TernaryExprNode"]; + L13C27_AssignExprNode -> L13C27_TernaryExprNode; + L13C27_LogicalOrExprNode [color="lightgreen",label="LogicalOrExprNode"]; + L13C27_TernaryExprNode -> L13C27_LogicalOrExprNode; + L13C27_LogicalAndExprNode [color="lightgreen",label="LogicalAndExprNode"]; + L13C27_LogicalOrExprNode -> L13C27_LogicalAndExprNode; + L13C27_BitwiseOrExprNode [color="lightgreen",label="BitwiseOrExprNode"]; + L13C27_LogicalAndExprNode -> L13C27_BitwiseOrExprNode; + L13C27_BitwiseXorExprNode [color="lightgreen",label="BitwiseXorExprNode"]; + L13C27_BitwiseOrExprNode -> L13C27_BitwiseXorExprNode; + L13C27_BitwiseAndExprNode [color="lightgreen",label="BitwiseAndExprNode"]; + L13C27_BitwiseXorExprNode -> L13C27_BitwiseAndExprNode; + L13C27_EqualityExprNode [color="lightgreen",label="EqualityExprNode"]; + L13C27_BitwiseAndExprNode -> L13C27_EqualityExprNode; + L13C27_RelationalExprNode [color="lightgreen",label="RelationalExprNode"]; + L13C27_EqualityExprNode -> L13C27_RelationalExprNode; + L13C27_ShiftExprNode [color="lightgreen",label="ShiftExprNode"]; + L13C27_RelationalExprNode -> L13C27_ShiftExprNode; + L13C27_AdditiveExprNode [color="lightgreen",label="AdditiveExprNode"]; + L13C27_ShiftExprNode -> L13C27_AdditiveExprNode; + L13C27_MultiplicativeExprNode [color="lightgreen",label="MultiplicativeExprNode"]; + L13C27_AdditiveExprNode -> L13C27_MultiplicativeExprNode; + L13C27_CastExprNode [color="lightgreen",label="CastExprNode"]; + L13C27_MultiplicativeExprNode -> L13C27_CastExprNode; + L13C27_PrefixUnaryExprNode [color="lightgreen",label="PrefixUnaryExprNode"]; + L13C27_CastExprNode -> L13C27_PrefixUnaryExprNode; + L13C27_PostfixUnaryExprNode [color="lightgreen",label="PostfixUnaryExprNode"]; + L13C27_PrefixUnaryExprNode -> L13C27_PostfixUnaryExprNode; + L13C27_AtomicExprNode [color="lightgreen",label="AtomicExprNode"]; + L13C27_PostfixUnaryExprNode -> L13C27_AtomicExprNode; + L13C27_ConstantNode [color="lightgreen",label="ConstantNode"]; + L13C27_AtomicExprNode -> L13C27_ConstantNode; L14C13_StmtNode [color="lightgreen",label="StmtNode"]; L13C13_StmtLstNode -> L14C13_StmtNode; L14C13_AssignExprNode [color="lightgreen",label="AssignExprNode"]; diff --git a/test/test-files/benchmark/success-fibonacci/assembly.asm b/test/test-files/benchmark/success-fibonacci/assembly.asm index 413cf3ab6..1cfecf9f0 100644 --- a/test/test-files/benchmark/success-fibonacci/assembly.asm +++ b/test/test-files/benchmark/success-fibonacci/assembly.asm @@ -10,8 +10,9 @@ .scl 3; .type 32; .endef - .p2align 4, 0x90 -.L_Z4fiboi: + .p2align 4, 0x90 # -- Begin function _Z4fiboi +.L_Z4fiboi: # @_Z4fiboi +# %bb.0: pushq %rsi pushq %rdi subq $40, %rsp @@ -19,12 +20,14 @@ xorl %esi, %esi cmpl $2, %ecx jge .LBB0_3 +# %bb.1: movl %edi, %ecx jmp .LBB0_2 -.LBB0_3: +.LBB0_3: # %if.exit.L2.preheader xorl %esi, %esi .p2align 4, 0x90 -.LBB0_4: +.LBB0_4: # %if.exit.L2 + # =>This Inner Loop Header: Depth=1 leal -1(%rdi), %ecx callq .L_Z4fiboi leal -2(%rdi), %ecx @@ -32,22 +35,23 @@ cmpl $4, %edi movl %ecx, %edi jae .LBB0_4 -.LBB0_2: +.LBB0_2: # %common.ret addl %ecx, %esi movl %esi, %eax addq $40, %rsp popq %rdi popq %rsi retq - + # -- End function .def main; .scl 2; .type 32; .endef - .globl main + .globl main # -- Begin function main .p2align 4, 0x90 -main: +main: # @main .seh_proc main +# %bb.0: pushq %rbp .seh_pushreg %rbp subq $32, %rsp @@ -66,8 +70,8 @@ main: popq %rbp retq .seh_endproc - + # -- End function .section .rdata,"dr" -.Lprintf.str.0: +.Lprintf.str.0: # @printf.str.0 .asciz "Result: %d" diff --git a/test/test-files/benchmark/success-hello-world/assembly.asm b/test/test-files/benchmark/success-hello-world/assembly.asm index 681265b4b..87c6b077c 100644 --- a/test/test-files/benchmark/success-hello-world/assembly.asm +++ b/test/test-files/benchmark/success-hello-world/assembly.asm @@ -10,10 +10,11 @@ .scl 2; .type 32; .endef - .globl main + .globl main # -- Begin function main .p2align 4, 0x90 -main: +main: # @main .seh_proc main +# %bb.0: pushq %rbp .seh_pushreg %rbp subq $32, %rsp @@ -29,8 +30,8 @@ main: popq %rbp retq .seh_endproc - + # -- End function .section .rdata,"dr" -.Lprintf.str.0: +.Lprintf.str.0: # @printf.str.0 .asciz "Hello World!" diff --git a/test/test-files/benchmark/success-hello-world2/assembly.asm b/test/test-files/benchmark/success-hello-world2/assembly.asm index ef3ea6d7e..06e1e59f5 100644 --- a/test/test-files/benchmark/success-hello-world2/assembly.asm +++ b/test/test-files/benchmark/success-hello-world2/assembly.asm @@ -10,10 +10,11 @@ .scl 2; .type 32; .endef - .globl main + .globl main # -- Begin function main .p2align 4, 0x90 -main: +main: # @main .seh_proc main +# %bb.0: # %while.body.L5 pushq %rbp .seh_pushreg %rbp subq $32, %rsp @@ -51,4 +52,4 @@ main: popq %rbp retq .seh_endproc - + # -- End function diff --git a/test/test-files/benchmark/success-pidigits/assembly.asm b/test/test-files/benchmark/success-pidigits/assembly.asm index da7f9d396..0293ffaf2 100644 --- a/test/test-files/benchmark/success-pidigits/assembly.asm +++ b/test/test-files/benchmark/success-pidigits/assembly.asm @@ -10,10 +10,11 @@ .scl 2; .type 32; .endef - .globl main + .globl main # -- Begin function main .p2align 4, 0x90 -main: +main: # @main .seh_proc main +# %bb.0: pushq %rbp .seh_pushreg %rbp pushq %r15 @@ -45,7 +46,8 @@ main: movl $1, %edx movl $1, %r12d jmp .LBB0_1 -.LBB0_1: +.LBB0_1: # %for.body.L19 + # =>This Inner Loop Header: Depth=1 movq %rsi, %rax shlq $2, %rax movq %r13, %rcx @@ -55,8 +57,10 @@ main: imulq %r12, %rdi cmpq %rdi, %rcx jge .LBB0_5 - movq %rdx, (%rbp) - movq %r11, -8(%rbp) +# %bb.2: # %if.then.L20 + # in Loop: Header=BB0_1 Depth=1 + movq %rdx, (%rbp) # 8-byte Spill + movq %r11, -8(%rbp) # 8-byte Spill leaq .Lprintf.str.0(%rip), %rcx movq %r15, %rdx movl %r10d, %r14d @@ -64,10 +68,13 @@ main: movl %r14d, %r10d cmpl $0, %r10d jne .LBB0_4 +# %bb.3: # %if.then.L22 + # in Loop: Header=BB0_1 Depth=1 movl $46, %ecx callq putchar movl %r14d, %r10d -.LBB0_4: +.LBB0_4: # %if.exit.L22 + # in Loop: Header=BB0_1 Depth=1 addl $1, %r10d imulq $10, %rsi, %rcx movq %r13, %rax @@ -83,10 +90,11 @@ main: movq %r8, %r13 movq %rax, %r15 movq %rcx, %rsi - movq -8(%rbp), %r11 - movq (%rbp), %rdx + movq -8(%rbp), %r11 # 8-byte Reload + movq (%rbp), %rdx # 8-byte Reload jmp .LBB0_6 -.LBB0_5: +.LBB0_5: # %if.else.L20 + # in Loop: Header=BB0_1 Depth=1 movq %rsi, %rcx imulq %rdx, %rcx movq %rsi, %r8 @@ -110,10 +118,12 @@ main: movq %r8, %r13 movq %r9, %rdx movq %rcx, %rsi -.LBB0_6: +.LBB0_6: # %for.tail.L19 + # in Loop: Header=BB0_1 Depth=1 addl $1, %ebx cmpl $20, %ebx jne .LBB0_1 +# %bb.7: # %for.exit.L19 xorl %eax, %eax addq $56, %rsp popq %rbx @@ -126,8 +136,8 @@ main: popq %rbp retq .seh_endproc - + # -- End function .section .rdata,"dr" -.Lprintf.str.0: +.Lprintf.str.0: # @printf.str.0 .asciz "%d" diff --git a/test/test-files/irgenerator/debug-info/success-dbg-info-complex/ir-code.ll b/test/test-files/irgenerator/debug-info/success-dbg-info-complex/ir-code.ll index e7b7017ba..a3f59df29 100644 --- a/test/test-files/irgenerator/debug-info/success-dbg-info-complex/ir-code.ll +++ b/test/test-files/irgenerator/debug-info/success-dbg-info-complex/ir-code.ll @@ -37,8 +37,8 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: noinline nounwind optnone uwtable define dso_local i32 @main(i32 %0, ptr %1) #0 !dbg !15 { %result = alloca i32, align 4 - %argc = alloca i32, align 4 - %argv = alloca ptr, align 8 + %_argc = alloca i32, align 4 + %_argv = alloca ptr, align 8 %vi = alloca %struct.Vector, align 8 %3 = alloca i32, align 4 %4 = alloca i32, align 4 @@ -61,10 +61,10 @@ define dso_local i32 @main(i32 %0, ptr %1) #0 !dbg !15 { %14 = alloca ptr, align 8 call void @llvm.dbg.declare(metadata ptr %result, metadata !23, metadata !DIExpression()), !dbg !24 store i32 0, ptr %result, align 4, !dbg !24 - call void @llvm.dbg.declare(metadata ptr %argc, metadata !25, metadata !DIExpression()), !dbg !24 - store i32 %0, ptr %argc, align 4, !dbg !24 - call void @llvm.dbg.declare(metadata ptr %argv, metadata !26, metadata !DIExpression()), !dbg !24 - store ptr %1, ptr %argv, align 8, !dbg !24 + call void @llvm.dbg.declare(metadata ptr %_argc, metadata !25, metadata !DIExpression()), !dbg !24 + store i32 %0, ptr %_argc, align 4, !dbg !24 + call void @llvm.dbg.declare(metadata ptr %_argv, metadata !26, metadata !DIExpression()), !dbg !24 + store ptr %1, ptr %_argv, align 8, !dbg !24 call void @llvm.dbg.declare(metadata ptr %vi, metadata !27, metadata !DIExpression()), !dbg !36 call void @_ZN6VectorIiE4ctorEv(ptr %vi), !dbg !37 store i32 123, ptr %3, align 4, !dbg !38 @@ -519,8 +519,8 @@ attributes #3 = { cold noreturn nounwind } !22 = !{} !23 = !DILocalVariable(name: "result", scope: !15, file: !5, line: 6, type: !18) !24 = !DILocation(line: 6, column: 1, scope: !15) -!25 = !DILocalVariable(name: "argc", arg: 1, scope: !15, file: !5, line: 6, type: !18) -!26 = !DILocalVariable(name: "argv", arg: 2, scope: !15, file: !5, line: 6, type: !19) +!25 = !DILocalVariable(name: "_argc", arg: 1, scope: !15, file: !5, line: 6, type: !18) +!26 = !DILocalVariable(name: "_argv", arg: 2, scope: !15, file: !5, line: 6, type: !19) !27 = !DILocalVariable(name: "vi", scope: !15, file: !5, line: 8, type: !28) !28 = !DICompositeType(tag: DW_TAG_structure_type, name: "Vector", scope: !29, file: !29, line: 22, size: 192, align: 8, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !30, identifier: "struct.Vector") !29 = !DIFile(filename: "vector.spice", directory: "C:\\Users\\Marc\\Documents\\JustForFunGitHubClonesFast\\spice\\std\\data") diff --git a/test/test-files/irgenerator/debug-info/success-dbg-info-complex/source.spice b/test/test-files/irgenerator/debug-info/success-dbg-info-complex/source.spice index ffc0df266..598c8dd2f 100644 --- a/test/test-files/irgenerator/debug-info/success-dbg-info-complex/source.spice +++ b/test/test-files/irgenerator/debug-info/success-dbg-info-complex/source.spice @@ -3,7 +3,7 @@ import "std/data/vector"; import "std/iterator/vector-iterator"; import "std/data/pair"; -f main(int argc, string[] argv) { +f main(int _argc, string[] _argv) { // Create test vector to iterate over Vector vi = Vector(); vi.pushBack(123); diff --git a/test/test-files/irgenerator/function-pointers/success-indirect/ir-code.ll b/test/test-files/irgenerator/function-pointers/success-indirect/ir-code.ll index 8d7c03ee9..6891e5722 100644 --- a/test/test-files/irgenerator/function-pointers/success-indirect/ir-code.ll +++ b/test/test-files/irgenerator/function-pointers/success-indirect/ir-code.ll @@ -8,8 +8,8 @@ target triple = "x86_64-w64-windows-gnu" define private i32 @_Z4testPc(ptr %0) { %result = alloca i32, align 4 - %input = alloca ptr, align 8 - store ptr %0, ptr %input, align 8 + %_input = alloca ptr, align 8 + store ptr %0, ptr %_input, align 8 ret i32 12 } diff --git a/test/test-files/irgenerator/function-pointers/success-indirect/source.spice b/test/test-files/irgenerator/function-pointers/success-indirect/source.spice index 5ed9634de..52f122dd4 100644 --- a/test/test-files/irgenerator/function-pointers/success-indirect/source.spice +++ b/test/test-files/irgenerator/function-pointers/success-indirect/source.spice @@ -1,4 +1,4 @@ -f test(string input) { +f test(string _input) { return 12; } diff --git a/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/ir-code.ll b/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/ir-code.ll index 0e31fbcc2..2c3ec0513 100644 --- a/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/ir-code.ll +++ b/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/ir-code.ll @@ -10,8 +10,8 @@ target triple = "x86_64-w64-windows-gnu" define private i32 @_Z4testPc(ptr %0) { %result = alloca i32, align 4 - %input = alloca ptr, align 8 - store ptr %0, ptr %input, align 8 + %_input = alloca ptr, align 8 + store ptr %0, ptr %_input, align 8 ret i32 12 } diff --git a/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/source.spice b/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/source.spice index eda4f082a..30f7f191d 100644 --- a/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/source.spice +++ b/test/test-files/irgenerator/function-pointers/success-pass-by-non-value/source.spice @@ -1,4 +1,4 @@ -f test(string input) { +f test(string _input) { return 12; }