Skip to content

Commit

Permalink
merge mra/prepare-generic-advanced
Browse files Browse the repository at this point in the history
# Done

- Update the config file parser, now handle input/output description in file
- Update 4069s' config file
- Update ReadMe

# To Do

- Advanced component
  • Loading branch information
Mael-RABOT authored Feb 16, 2024
2 parents a88b2c7 + 99c311d commit ea9afa6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Config/Gates/4069.nts.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
4069
pinNb 14
componentsData
Not1 Standard NOT
Not2 Standard NOT
Not3 Standard NOT
Not4 Standard NOT
Not5 Standard NOT
Not6 Standard NOT
Not1 Standard NOT {1} {2}
Not2 Standard NOT {1} {2}
Not3 Standard NOT {1} {2}
Not4 Standard NOT {1} {2}
Not5 Standard NOT {1} {2}
Not6 Standard NOT {1} {2}
end
pinRefTable
1 Not1 1
Expand Down
12 changes: 10 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ The file format is a simple text file with the following format:
[GATE_NAME]
PinNb [NUMBER]
componentsData
[COMPONENT_NAME] [TYPE] [TRUTH_TABLE]
[COMPONENT_NAME] [TYPE] [TRUTH_TABLE]
[COMPONENT_NAME] [TYPE] [TRUTH_TABLE] [INPUTS] [OUTPUTS]
[COMPONENT_NAME] [TYPE] [TRUTH_TABLE] [INPUTS] [OUTPUTS]
[...]
end
pinRefTable
Expand All @@ -118,6 +118,14 @@ The file format is a simple text file with the following format:
- [TRUTH_TABLE] is the truth table of the internal component.<br>
Thoses truth tables are the ones described in the .nts.init file.
- end is used to mark the end of the internal components' description.
- [INPUTS] is the list of input pins of the internal component.<br>
The format for the input is: {1,2,...}<br>
*Default value is: {1,2}*
- [OUTPUTS] is the list of output pins of the internal component.<br>
The format for the output is: {1,2,...}<br>
*Default value is: {3}*

Inputs and outputs aren't mandatory, but the format must be respected.<br>

#### Pin reference table:

Expand Down
8 changes: 5 additions & 3 deletions src/Component/gate/genericGate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace nts {
std::tuple<
std::string, // Internal component name
ComponentType, // Internal component type
std::vector<std::vector<nts::Tristate> // Internal component truth table
>>> componentsData, // Vector of tuples containing the internal components data
std::vector<std::vector<nts::Tristate>>, // Internal component truth table
std::vector<std::size_t>, // Internal component input pins
std::vector<std::size_t> // Internal component output pins
>> componentsData, // Vector of tuples containing the internal components data
std::map<
std::size_t, // Internal pin number
std::pair<
Expand All @@ -25,7 +27,7 @@ namespace nts {
: AComponent(pinNb, name, ComponentType::Standard), _pinRefTable(pinRefTable) {
for (auto &data : componentsData) { // Create the internal components
_components.push_back(std::make_pair(std::get<0>(data),
new Chipset(3, std::get<0>(data), std::get<1>(data), std::get<2>(data), {1, 2}, {3})));
new Chipset(3, std::get<0>(data), std::get<1>(data), std::get<2>(data), std::get<3>(data), std::get<4>(data))));
}
};
~GenericGate() {
Expand Down
33 changes: 30 additions & 3 deletions src/parseConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,42 @@ namespace nts {
std::getline(file, line);
int pinNb = std::stoi(line.substr(6)); // Skip "PinNb "

std::vector<std::tuple<std::string, ComponentType, std::vector<std::vector<nts::Tristate>>>> componentsData;
std::vector<std::tuple<std::string, ComponentType, std::vector<std::vector<nts::Tristate>>, std::vector<std::size_t>, std::vector<std::size_t>>> componentsData;
std::map<std::size_t, std::pair<std::string, std::size_t>> pinRefTable;

std::getline(file, line); // Skip "componentsData"
while (std::getline(file, line) && line != "end") {
std::istringstream iss(line);
std::string componentName, type, truthTableName;
std::string componentName, type, truthTableName, rest;
iss >> componentName >> type >> truthTableName;
componentsData.push_back({componentName, ComponentType::Standard, std::get<3>(_componentTruthTables[truthTableName])});
std::getline(iss, rest);

std::vector<std::size_t> inputs = {1, 2}, outputs = {3};
size_t start = rest.find('{');
size_t end = rest.find('}');
if (start != std::string::npos && end != std::string::npos) {
inputs.clear();
std::string inputsStr = rest.substr(start + 1, end - start - 1);
std::istringstream issInputs(inputsStr);
std::string input;
while (std::getline(issInputs, input, ',')) {
inputs.push_back(std::stoi(input));
}
}

start = rest.find('{', end + 1);
end = rest.find('}', end + 1);
if (start != std::string::npos && end != std::string::npos) {
outputs.clear();
std::string outputsStr = rest.substr(start + 1, end - start - 1);
std::istringstream issOutputs(outputsStr);
std::string output;
while (std::getline(issOutputs, output, ',')) {
outputs.push_back(std::stoi(output));
}
}

componentsData.push_back({componentName, ComponentType::Standard, std::get<3>(_componentTruthTables[truthTableName]), inputs, outputs});
}

std::getline(file, line); // Skip "pinRefTable"
Expand Down

0 comments on commit ea9afa6

Please sign in to comment.