From e2e05060417e4fe55148d167015d35a0aac2c6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Mon, 16 May 2022 01:02:34 +0200 Subject: [PATCH] Added support for @componentHeader --- comdel/domain/comdel_generator.cpp | 10 +++++++--- comdel/domain/library.cpp | 7 +++++-- comdel/domain/library.h | 4 +++- comdel/domain/schemacreator.cpp | 6 +++++- comdel/domain/schemacreator.h | 1 + comdel/parser/astnode.h | 1 + comdel/parser/comdelparser.cpp | 3 +++ comdel/parser/token.h | 1 + comdel/parser/tokenstype.cpp | 1 + examples/simplified FRISC model/frisc_library.csl | 2 ++ 10 files changed, 29 insertions(+), 7 deletions(-) diff --git a/comdel/domain/comdel_generator.cpp b/comdel/domain/comdel_generator.cpp index 232611c..fabf606 100644 --- a/comdel/domain/comdel_generator.cpp +++ b/comdel/domain/comdel_generator.cpp @@ -63,11 +63,11 @@ std::set createImports(Schema *schema); std::map generateWires(Schema *schema, ostream &ostream); - void generateSubComponents(Schema *schema, map &wires, ostream &buffer); +void generateSubComponents(Schema *schema, map &wires, ostream &buffer); - void generateDisplay(Schema *schema, ostream &buffer); +void generateDisplay(Schema *schema, ostream &buffer); - void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer) { +void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer) { buffer << library.getHeader() << std::endl; std::set imports = createImports(schema); @@ -80,6 +80,10 @@ std::map generateWires(Schema *schema, ostream &ostream); buffer << "component System" << std::endl << "{" << std::endl; + if(library.getComponentHeader().has_value()) { + buffer << library.getComponentHeader().value() << endl; + } + auto wires = generateWires(schema, buffer); generateSubComponents(schema, wires, buffer); diff --git a/comdel/domain/library.cpp b/comdel/domain/library.cpp index 2b2a771..295070e 100644 --- a/comdel/domain/library.cpp +++ b/comdel/domain/library.cpp @@ -2,9 +2,9 @@ namespace domain { -Library::Library(string name, string libraryInfo, string header, string componentDirectory, +Library::Library(string name, string libraryInfo, string header, string componentDirectory, std::optional componentHeader, vector addressSpaces, vector components, vector buses, vector connections, map messages) - : name(name), libraryInfo(libraryInfo), header(header), componentDirectory(componentDirectory), addressSpaces(addressSpaces), + : name(name), libraryInfo(libraryInfo), header(header), componentDirectory(componentDirectory), componentHeader(componentHeader), addressSpaces(addressSpaces), components(components), buses(buses), connections(connections), messages(messages) {} @@ -20,6 +20,9 @@ std::string Library::getHeader() { std::string Library::getComponentDirectory() { return componentDirectory; } +std::optional Library::getComponentHeader() { + return componentHeader; +} std::vector Library::getAddressSpaces() { return addressSpaces; diff --git a/comdel/domain/library.h b/comdel/domain/library.h index 3234bf1..984cc63 100644 --- a/comdel/domain/library.h +++ b/comdel/domain/library.h @@ -21,6 +21,7 @@ class Library std::string libraryInfo; std::string header; std::string componentDirectory; + std::optional componentHeader; std::vector addressSpaces; std::vector components; @@ -30,13 +31,14 @@ class Library std::map messages; public: - Library(string name, string libraryInfo, string header, string componentDirectory, + Library(string name, string libraryInfo, string header, string componentDirectory, std::optional componentHeader, vector addressSpaces, vector components, vector buses, vector connection, map messages); std::string getName(); std::string getLibraryInfo(); std::string getHeader(); std::string getComponentDirectory(); + std::optional getComponentHeader(); std::vector getAddressSpaces(); std::vector getComponents(); diff --git a/comdel/domain/schemacreator.cpp b/comdel/domain/schemacreator.cpp index 79ce064..a52b7a1 100644 --- a/comdel/domain/schemacreator.cpp +++ b/comdel/domain/schemacreator.cpp @@ -128,6 +128,10 @@ std::optional SchemaCreator::loadLibrary(LibraryNode node) name = node.name->asString(); } + if(node.componentHeader.has_value()) { + componentHeader = node.componentHeader->asString(); + } + if(!node.componentDirectory) { errors.emplace_back(node.span, "missing @componentDirectory"); return nullopt; @@ -173,7 +177,7 @@ std::optional SchemaCreator::loadLibrary(LibraryNode node) } } - return Library(name, libraryInfo, header, componentDirectory, addressSpaces, components, buses, connections, messages); + return Library(name, libraryInfo, header, componentDirectory, componentHeader, addressSpaces, components, buses, connections, messages); } std::optional SchemaCreator::loadBus(BusNode node) diff --git a/comdel/domain/schemacreator.h b/comdel/domain/schemacreator.h index 9479b4b..5c66650 100644 --- a/comdel/domain/schemacreator.h +++ b/comdel/domain/schemacreator.h @@ -53,6 +53,7 @@ class SchemaCreator std::string libraryInfo; std::string header; std::string componentDirectory; + std::optional componentHeader = nullopt; std::vector addressSpaces; std::vector components; std::vector buses; diff --git a/comdel/parser/astnode.h b/comdel/parser/astnode.h index 83e3222..b0c8df8 100644 --- a/comdel/parser/astnode.h +++ b/comdel/parser/astnode.h @@ -294,6 +294,7 @@ struct LibraryNode: public AstNode std::optional libraryInfo; std::optional header; std::optional componentDirectory; + std::optional componentHeader; std::vector addressSpaces; diff --git a/comdel/parser/comdelparser.cpp b/comdel/parser/comdelparser.cpp index c75d5d5..1fb9ad0 100644 --- a/comdel/parser/comdelparser.cpp +++ b/comdel/parser/comdelparser.cpp @@ -243,6 +243,9 @@ std::optional ComdelParser::parse() } else if(check(TokenType::KW_HEADER)) { bump(); ASSIGN_OR_SET_ERR(library.header, parseString()); + } else if(check(TokenType::KW_COMPONENT_HEADER)) { + bump(); + ASSIGN_OR_SET_ERR(library.componentHeader, parseString()); } else if(check(TokenType::KW_DIRECTORY)) { bump(); ASSIGN_OR_SET_ERR(library.componentDirectory, parseString()); diff --git a/comdel/parser/token.h b/comdel/parser/token.h index 29ab5f9..e52838e 100644 --- a/comdel/parser/token.h +++ b/comdel/parser/token.h @@ -72,6 +72,7 @@ enum class TokenType { KW_NAME, KW_INFO, KW_HEADER, + KW_COMPONENT_HEADER, KW_DIRECTORY, KW_LIBRARY, KW_ADDRESS, diff --git a/comdel/parser/tokenstype.cpp b/comdel/parser/tokenstype.cpp index 5bbfad1..517b89e 100644 --- a/comdel/parser/tokenstype.cpp +++ b/comdel/parser/tokenstype.cpp @@ -83,6 +83,7 @@ TokenTables::TokenTables() { add( TokenType::KW_NAME, "@name", TOKENIZABLE | KEYWORD_NAME), add( TokenType::KW_INFO, "@info", TOKENIZABLE | KEYWORD_NAME), add( TokenType::KW_HEADER, "@header", TOKENIZABLE | KEYWORD_NAME), + add( TokenType::KW_COMPONENT_HEADER, "@componentHeader", TOKENIZABLE | KEYWORD_NAME), add( TokenType::KW_DIRECTORY, "@directory", TOKENIZABLE | KEYWORD_NAME), add( TokenType::KW_LIBRARY, "@library", TOKENIZABLE | KEYWORD_NAME), add( TokenType::KW_ADDRESS, "@address", TOKENIZABLE | KEYWORD_NAME), diff --git a/examples/simplified FRISC model/frisc_library.csl b/examples/simplified FRISC model/frisc_library.csl index afdd202..7d15539 100644 --- a/examples/simplified FRISC model/frisc_library.csl +++ b/examples/simplified FRISC model/frisc_library.csl @@ -1,6 +1,8 @@ @name "Jednostavni FRISC" @info "Ova biblioteka omogućuje kreiranje sustava s procesorom FRISC s pojednostavljenim načinom spajanja bez potrebe da se spajaju pojedine linije sabirnice." @directory "libraries\frisc\vjezba1" +@header "// Version 0.0.1" +@componentHeader " clock 100MHz;" @address glavniAS(0,0xFFFFFFFF) @address pomocniAS(0xFFFF0000,0xFFFFFFFF)