From edfd7fdf3732293a1436185e6adc8641762f5763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Mon, 27 Jun 2022 11:39:13 +0200 Subject: [PATCH] Generation fix --- comdel/display/dialog/attribute_dialog.cpp | 5 +- comdel/domain/bus.h | 4 +- comdel/domain/comdel_generator.cpp | 26 +++++++-- comdel/domain/component.cpp | 5 +- comdel/domain/connection.cpp | 3 +- comdel/domain/connection_instance.cpp | 3 +- comdel/domain/display.cpp | 22 ++++--- comdel/domain/library.cpp | 21 +++---- comdel/domain/schema_creator.cpp | 2 +- comdel/domain/value.cpp | 47 +++++++++++---- comdel/domain/value.h | 1 + comdel/parser/ast_nodes.h | 2 +- comdel/parser/comdel_parser.cpp | 4 +- examples/arm/arm_library.csl | 9 +-- examples/arm/minimum.comdel | 67 ---------------------- examples/arm/minimum.csch | 8 +-- 16 files changed, 108 insertions(+), 121 deletions(-) delete mode 100644 examples/arm/minimum.comdel diff --git a/comdel/display/dialog/attribute_dialog.cpp b/comdel/display/dialog/attribute_dialog.cpp index dea54ab..301a5ac 100644 --- a/comdel/display/dialog/attribute_dialog.cpp +++ b/comdel/display/dialog/attribute_dialog.cpp @@ -5,6 +5,7 @@ #include "error_dialog.h" #include "warning_dialog.h" #include "message_source.h" +#include namespace display { @@ -91,7 +92,7 @@ namespace display { value = domain::Value::fromInt(parseInt(string.toStdString())); break; default: - throw std::exception(); + throw std::runtime_error("invalid value type in text change"); } } @@ -178,4 +179,4 @@ namespace display { return errors; } -} \ No newline at end of file +} diff --git a/comdel/domain/bus.h b/comdel/domain/bus.h index 2048ba9..4ecf172 100644 --- a/comdel/domain/bus.h +++ b/comdel/domain/bus.h @@ -25,8 +25,8 @@ namespace domain { std::string name; WireType type; int width; - bool hidden; - bool hasTerminate; + bool hidden = false; + bool hasTerminate = false; Value terminateWith; public: diff --git a/comdel/domain/comdel_generator.cpp b/comdel/domain/comdel_generator.cpp index ef9fc0e..9e8f543 100644 --- a/comdel/domain/comdel_generator.cpp +++ b/comdel/domain/comdel_generator.cpp @@ -128,8 +128,18 @@ namespace domain { } void generateConnection(ConnectionInstance *connection, ostream &buffer) { - buffer << "\t\tline {x1:" << connection->start.first << "; y1:" << connection->start.second << "; " << - "x2:" << connection->end.first << "; y2:" << connection->end.second << ";}" << "\n"; + + auto x1 = connection->start.first; + auto y1 = connection->start.second; + auto x2 = connection->end.first; + auto y2 = connection->end.second; + + buffer << "\t\tpath {\n"; + buffer << "\t\t\tx:0; y:0;\n"; + buffer << "\t\t\tpoints: ("; + buffer << "(" << x1 << ", " << y1 << "),"; + buffer << "(" << (x2 - x1) << "," << (y2 - y1) << "));\n"; + buffer << "\t\t}" << std::endl; } void generateBus(BusInstance *bus, ostream &buffer) { @@ -149,9 +159,9 @@ namespace domain { for (auto &bus: schema->busInstances) { buffer << "\t//" << bus->name << std::endl; for (auto &wire: bus->bus.getWires()) { - auto name = (wire.isHidden() ? "--" : "") + wire.getName(); + auto name = wire.getName(); if (usedNames.count(name) > 0) { - name = (wire.isHidden() ? "--" : "") + bus->name + "__" + wire.getName(); + name = bus->name + "__" + wire.getName(); } usedNames.insert(name); usedMappings.insert(std::make_pair(bus->name + "." + wire.getName(), name)); @@ -182,7 +192,11 @@ namespace domain { if (wire.getWidth() != 1) { buffer << "<" << wire.getWidth() << ">"; } - buffer << " " << name << ";" << std::endl; + buffer << " " << (wire.isHidden() ? "--" : "") << name; + if(wire.hasTerminateWith()) { + buffer << " = " << wire.getTerminateWith().asInt(); + } + buffer << ";" << std::endl; } std::set createImports(Schema *schema) { @@ -400,4 +414,4 @@ namespace domain { } } -} // domain \ No newline at end of file +} // domain diff --git a/comdel/domain/component.cpp b/comdel/domain/component.cpp index 3a237a1..ea3a585 100644 --- a/comdel/domain/component.cpp +++ b/comdel/domain/component.cpp @@ -1,4 +1,5 @@ #include "component.h" +#include namespace domain { @@ -57,7 +58,7 @@ namespace domain { return p; } } - throw std::exception(); + throw std::runtime_error("no pin with name '" + pin + "'"); } bool Component::hasPin(std::string name) { @@ -79,7 +80,7 @@ namespace domain { return attr; } } - throw std::exception(); + throw std::runtime_error("no attribute with name '" + attribute + "'"); } bool Component::hasAttribute(std::string name, Value::ValueType type) { diff --git a/comdel/domain/connection.cpp b/comdel/domain/connection.cpp index b6fb517..c847616 100644 --- a/comdel/domain/connection.cpp +++ b/comdel/domain/connection.cpp @@ -1,4 +1,5 @@ #include "connection.h" +#include namespace domain { @@ -38,7 +39,7 @@ namespace domain { return attributes[i]; } } - throw std::exception(); + throw std::runtime_error("no attribute with name '" + name + "'"); } bool Connection::hasAttribute(std::string name) { diff --git a/comdel/domain/connection_instance.cpp b/comdel/domain/connection_instance.cpp index e1bd1c1..9257980 100644 --- a/comdel/domain/connection_instance.cpp +++ b/comdel/domain/connection_instance.cpp @@ -1,4 +1,5 @@ #include "connection_instance.h" +#include namespace domain { @@ -13,7 +14,7 @@ namespace domain { return attr; } } - throw std::exception(); + throw std::runtime_error("no attribute with name '" + attribute + "'"); } diff --git a/comdel/domain/display.cpp b/comdel/domain/display.cpp index 4470180..e618512 100644 --- a/comdel/domain/display.cpp +++ b/comdel/domain/display.cpp @@ -47,7 +47,9 @@ namespace domain { void ui::Rect::comdel(std::ostream &buffer, int x, int y) { buffer << "\t\trectangle {\n"; buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n"; - buffer << "\t\t\tw: " << w << "; h: " << h << ";\n"; + buffer << "\t\t\twidth: " << w << "; height: " << h << ";\n"; + buffer << "\t\t\tfill_color: " << this->config.fillColor.name().toStdString() << ";\n"; + buffer << "\t\t\tline_color: " << this->config.lineColor.name().toStdString() << ";\n"; buffer << "\t\t}\n\n"; } @@ -61,7 +63,7 @@ namespace domain { void ui::Ellipse::comdel(std::ostream &buffer, int x, int y) { buffer << "\t\tellipse {\n"; buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n"; - buffer << "\t\t\tw: " << w << "; h: " << h << ";\n"; + buffer << "\t\t\twidth: " << w << "; height: " << h << ";\n"; buffer << "\t\t}\n\n"; } @@ -73,10 +75,12 @@ namespace domain { } void ui::Line::comdel(std::ostream &buffer, int x, int y) { - buffer << "\t\tline {\n"; - buffer << "\t\t\tx1: " << (x1 + x) << "; y1: " << (y1 + y) << ";\n"; - buffer << "\t\t\tx2: " << (x2 + x) << "; y2: " << (y2 + y) << ";\n"; - buffer << "\t\t}\n\n"; + buffer << "\t\tpath {\n"; + buffer << "\t\t\tx:0; y:0;\n"; + buffer << "\t\t\tpoints: ("; + buffer << "(" << (x1 + x) << ", " << (y1 + y) << "),"; + buffer << "(" << (x2 - x1) << "," << (y2 - y1) << "));\n"; + buffer << "\t\t}" << std::endl; } void ui::Bus::render(QGraphicsItemGroup *group, int size) { @@ -104,10 +108,12 @@ namespace domain { buffer << "\t\trectangle {\n"; buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n"; if (orientation == HORIZONTAL) { - buffer << "\t\t\tw: " << size << "; h: " << h << ";\n"; + buffer << "\t\t\twidth: " << size << "; height: " << h << ";\n"; } else { - buffer << "\t\t\tw: " << w << "; h: " << size << ";\n"; + buffer << "\t\t\twidth: " << w << "; height: " << size << ";\n"; } + buffer << "\t\t\tfill_color: " << this->config.fillColor.name().toStdString() << ";\n"; + buffer << "\t\t\tline_color: " << this->config.lineColor.name().toStdString() << ";\n"; buffer << "\t\t}\n\n"; } diff --git a/comdel/domain/library.cpp b/comdel/domain/library.cpp index 1b6f19e..0f80c02 100644 --- a/comdel/domain/library.cpp +++ b/comdel/domain/library.cpp @@ -1,4 +1,5 @@ #include "library.h" +#include namespace domain { @@ -51,7 +52,7 @@ namespace domain { } bool Library::hasComponent(std::string name) { - for (uint i = 0; i < components.size(); i++) { + for (unsigned int i = 0; i < components.size(); i++) { if (components[i].getName() == name) { return true; } @@ -60,7 +61,7 @@ namespace domain { } bool Library::hasBus(std::string name) { - for (uint i = 0; i < buses.size(); i++) { + for (unsigned int i = 0; i < buses.size(); i++) { if (buses[i].getName() == name) { return true; } @@ -70,30 +71,30 @@ namespace domain { AddressSpace &Library::getAddressSpace(std::string addressSpace) { - for (uint i = 0; i < addressSpaces.size(); i++) { + for (unsigned int i = 0; i < addressSpaces.size(); i++) { if (addressSpaces[i].getName() == addressSpace) { return addressSpaces[i]; } } - throw std::exception(); + throw std::runtime_error("no address space with name '" + addressSpace + "'"); } Component &Library::getComponent(std::string component) { - for (uint i = 0; i < components.size(); i++) { + for (unsigned int i = 0; i < components.size(); i++) { if (components[i].getName() == component) { return components[i]; } } - throw std::exception(); + throw std::runtime_error("no component with name '" + component + "'"); } Bus &Library::getBus(std::string bus) { - for (uint i = 0; i < buses.size(); i++) { + for (unsigned int i = 0; i < buses.size(); i++) { if (buses[i].getName() == bus) { return buses[i]; } } - throw std::exception(); + throw std::runtime_error("no bus with name '" + bus + "'"); } @@ -102,7 +103,7 @@ namespace domain { } std::optional Library::getConnection(ConnectionComponent component, std::string bus) { - for (uint i = 0; i < connections.size(); i++) { + for (unsigned int i = 0; i < connections.size(); i++) { if (connections[i].isConnecting(component, bus)) { return connections[i]; } @@ -116,7 +117,7 @@ namespace domain { std::optional Library::getConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent) { - for (uint i = 0; i < connections.size(); i++) { + for (unsigned int i = 0; i < connections.size(); i++) { if (connections[i].isConnecting(component, bus, secondComponent)) { return connections[i]; } diff --git a/comdel/domain/schema_creator.cpp b/comdel/domain/schema_creator.cpp index c2881be..5e325aa 100644 --- a/comdel/domain/schema_creator.cpp +++ b/comdel/domain/schema_creator.cpp @@ -882,7 +882,7 @@ namespace domain { if (validator->getName() == function) { if (validator->getSignature().size() == node.params.size()) { std::vector params; - for (uint j = 0; j < validator->getSignature().size(); j++) { + for (unsigned int j = 0; j < validator->getSignature().size(); j++) { bool exists = false; auto type = toType(node.params[j]); if (type.getType() == Value::UNDEFINED) { diff --git a/comdel/domain/value.cpp b/comdel/domain/value.cpp index 5e458d1..1a9c5a2 100644 --- a/comdel/domain/value.cpp +++ b/comdel/domain/value.cpp @@ -1,6 +1,7 @@ #include "value.h" #include +#include namespace domain { @@ -44,32 +45,58 @@ namespace domain { return type == _type; } + std::string Value::getTypename() { + switch (type) { + case Value::BOOL: + return "bool"; + case Value::INT: + return "int"; + case Value::STRING: + return "string"; + case Value::ADDRESS_SPACE: + case Value::ADDRESS_SPACE_REFERENCE: + return "address space"; + case Value::WIRE_REFERENCE: + return "wire reference"; + case Value::ATTRIBUTE_REFERENCE: + return "attribute"; + case Value::NIL: + return "null"; + case Value::MEMORY: + case Value::MEMORY_REFERENCE: + return "memory"; + case Value::UNDEFINED: + return "undefined"; + } + return "unknown"; + } + long long Value::asInt() { if (isType(Value::INT)) { return intValue; } - throw std::exception(); + throw std::runtime_error("expected 'int' but value contains '" + getTypename() + "'"); } std::string Value::asString() { if (isType(Value::STRING)) { return stringValue; } - throw std::exception(); + throw std::runtime_error("expected 'string' but value contains '" + getTypename() + "'"); } bool Value::asBool() { if (isType(Value::BOOL)) { return boolValue; } - throw std::exception(); + throw std::runtime_error("expected 'bool' but value contains '" + getTypename() + "'"); } AddressSpace Value::asAddressSpace() { if (isType(Value::ADDRESS_SPACE)) { return *addressSpace; } - throw std::exception(); + throw std::runtime_error("expected 'address space' but value contains '" + getTypename() + "'"); } std::string Value::asReference() { @@ -77,7 +104,7 @@ namespace domain { isType(Value::ATTRIBUTE_REFERENCE) || isType(Value::UNDEFINED)) { return reference; } - throw std::exception(); + throw std::runtime_error("expected 'reference' but value contains '" + getTypename() + "'"); } std::optional Value::asMemoryReference() { @@ -93,7 +120,7 @@ namespace domain { if (isType(Value::INT)) { this->intValue = value; } else { - throw std::exception(); + throw std::runtime_error("expected to set 'int' but value contains '" + getTypename() + "'"); } } @@ -101,7 +128,7 @@ namespace domain { if (isType(Value::STRING)) { this->stringValue = value; } else { - throw std::exception(); + throw std::runtime_error("expected to set 'string' but value contains '" + getTypename() + "'"); } } @@ -109,7 +136,7 @@ namespace domain { if (isType(Value::BOOL)) { this->boolValue = value; } else { - throw std::exception(); + throw std::runtime_error("expected to set 'bool' but value contains '" + getTypename() + "'"); } } @@ -117,7 +144,7 @@ namespace domain { if (isType(Value::WIRE_REFERENCE)) { this->reference = value; } else { - throw std::exception(); + throw std::runtime_error("expected to set 'wire' but value contains '" + getTypename() + "'"); } } @@ -191,7 +218,7 @@ namespace domain { return "null"; } default: - throw std::exception(); + throw std::runtime_error("unknown type couldn't stringify '" + getTypename() + "'"); } } diff --git a/comdel/domain/value.h b/comdel/domain/value.h index f39b6d3..f6fb737 100644 --- a/comdel/domain/value.h +++ b/comdel/domain/value.h @@ -46,6 +46,7 @@ namespace domain { bool equals(Value value); std::string string(); + std::string getTypename(); ValueType getType(); diff --git a/comdel/parser/ast_nodes.h b/comdel/parser/ast_nodes.h index 1c410e1..464b423 100644 --- a/comdel/parser/ast_nodes.h +++ b/comdel/parser/ast_nodes.h @@ -408,7 +408,7 @@ struct WireNode : public AstNode { bool hidden = false; /** If wire isn't connected to anything it is replaced with terminate with terminateWith value */ - bool hasTerminateWith; + bool hasTerminateWith = false; ValueNode terminateWith; }; diff --git a/comdel/parser/comdel_parser.cpp b/comdel/parser/comdel_parser.cpp index bd668fc..8f9f496 100644 --- a/comdel/parser/comdel_parser.cpp +++ b/comdel/parser/comdel_parser.cpp @@ -74,7 +74,7 @@ PError ComdelParser::unexpected() { } else { ss << ": "; } - uint token_counter = 0; + unsigned int token_counter = 0; for (auto &type: expectedTokens) { if (type == TokenType::IDENTIFIER || type == TokenType::NUMBER || @@ -1365,4 +1365,4 @@ PResult ComdelParser::parseConnectionWire() { } else { return unexpected(); } -} \ No newline at end of file +} diff --git a/examples/arm/arm_library.csl b/examples/arm/arm_library.csl index 30b1ec3..2fa1a7e 100644 --- a/examples/arm/arm_library.csl +++ b/examples/arm/arm_library.csl @@ -2,10 +2,10 @@ @info "Primjer ARM biblioteke" @directory "." @header ` -\\ Version 0.0.1 +// Version 0.0.1 set load_performs_init; ` -@componentHeader " clock 100MHz;" +@componentHeader " clock 100 MHz;" // adresni prostori @address adresniProstor(0,0xFFFFFFFF) @@ -611,7 +611,7 @@ set load_performs_init; pin { x: 15; y: 30; w: 10; h: 10; type: "in"; - orientation: "top"; + orientation: "bottom"; } } } @@ -729,8 +729,9 @@ set load_performs_init; irq wired_or, fiq wired_or, nmreq wired_and, // hsel_* sel_mem hidden, sel_bridge, sel_dmac + sel_mem hidden, sel_bridge, sel_dmac // dmac - busreq, grant + busreq terminate_with 0, grant } } diff --git a/examples/arm/minimum.comdel b/examples/arm/minimum.comdel deleted file mode 100644 index f01a4f9..0000000 --- a/examples/arm/minimum.comdel +++ /dev/null @@ -1,67 +0,0 @@ - -\\ Version 0.0.1 -set load_performs_init; - -#include ".\arm7tdmi.comdel" -#include ".\decoder.comdel" -#include ".\memory.comdel" - - - -component System -{ - clock 100MHz; - //ahb - wire<32> addr; - wire<32> rdata; - wire<32> wdata; - wire<3> size; - wire write; - wired_or ready; - wired_or irq; - wired_or fiq; - wired_and nmreq; - wire --sel_mem; - wire sel_bridge; - wire sel_dmac; - wire busreq; - wire grant; - - - //gpio_port - wire --xp0; - wire --xp1; - wire --xp2; - wire --xp3; - wire --xp4; - wire --xp5; - wire --xp6; - wire --xp7; - - - // components -------------------------------------------- - subcomponent Memory64KiB memorija(addr, rdata, wdata, size, write, ready, --sel_mem); - subcomponent ARM7tdmi arm(addr, rdata, wdata, size, write, ready, irq, fiq, nmreq, busreq, grant, *, *) uses memorija; - subcomponent Decoder decoder(addr, nmreq, --sel_mem, sel_bridge, sel_dmac, 1, 1); - - display { - component { x: -473; y: -283; ref: "arm"; } - component { x: -433; y: 6; ref: "memorija"; } - component { x: -537; y: -202; ref: "decoder"; } - - // ahb bus - - rectangle { - x: -514; y: -86; - w: 249; h: 20; - } - - - // gpio_port bus - - - line {x1:-428; y1:6; x2:-389; y2:-75;} - line {x1:-418; y1:-152; x2:-389; y2:-75;} - line {x1:-517; y1:-172; x2:-389; y2:-75;} - } -} \ No newline at end of file diff --git a/examples/arm/minimum.csch b/examples/arm/minimum.csch index dbed685..47af5b3 100644 --- a/examples/arm/minimum.csch +++ b/examples/arm/minimum.csch @@ -2,20 +2,20 @@ @schema { @instance arm ARM7tdmi { - @position (-473, -283) + @position (1179, 326) @attribute _memory memorija } @instance memorija Memory64KiB { - @position (-433, 6) + @position (1148, 521) } @instance decoder Decoder { - @position (-537, -202) + @position (1070, 381) } @instance ahb AHB { - @position (-514, -86) + @position (1027, 465) @size 249 }