From ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Zrounba?= <6691770+clement-z@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:06:01 +0200 Subject: Initial release --- src/parser/parse_directive.cpp | 132 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/parser/parse_directive.cpp (limited to 'src/parser/parse_directive.cpp') diff --git a/src/parser/parse_directive.cpp b/src/parser/parse_directive.cpp new file mode 100644 index 0000000..e66e8cf --- /dev/null +++ b/src/parser/parse_directive.cpp @@ -0,0 +1,132 @@ +#include "parse_directive.h" +#include "devices/alldevices.h" +#include "directional_coupler.h" +#include "optical_signal.h" +#include "parse_tree.h" +#include "specs.h" + +using spx::oa_value_type; +using spx::ea_value_type; +using spx::ed_value_type; + +using spx::ed_bus_type; +using spx::oa_signal_type; +using spx::ea_signal_type; +using spx::ed_signal_type; +using spx::ed_bus_type; + +void OPTIONSDirective::create() const +{ + // Verify number of nodes + assert(args.size() == 0); + + // Parse keyword arguments + for (auto &p: kwargs) + { + string kw = p.first; + strutils::toupper(kw); + if (kw == "TRACEALL") + specsGlobalConfig.trace_all_optical_nets = p.second.as_boolean(); + else if (kw == "ABSTOL") + specsGlobalConfig.default_abstol = p.second.as_double(); + else if (kw == "RELTOL") + specsGlobalConfig.default_reltol = p.second.as_double(); + else if (kw == "TS" || kw == "TIMESCALE") + specsGlobalConfig.engine_timescale = (SPECSConfig::EngineTimescale)p.second.as_integer(); + else if (kw == "RESOLUTION") + specsGlobalConfig.default_resolution_multiplier = p.second.as_double(); + else if (kw == "TRACEALL") + specsGlobalConfig.trace_all_optical_nets = p.second.as_double(); + else if (kw == "TEST_VARIABLE") + cout << kw << "(" << p.second.kind() << "): " << p.second.get_str() << endl; + else { + cerr << "Unknown keyword: " << p.first; + cerr << " (value: " << p.second.get_str() << " (" << p.second.kind() << "))" <> ic_map; + auto &signals = parent->circuit_nets; + for (const auto &x : net_assignments) + { + const auto &key = x.first; + if (signals.count(key) == 0) + { + cerr << "Net not found " << key << endl; + exit(1); + } + if (ic_map.count(key) == 0) + { + //FIXME: + auto sig = dynamic_cast(signals[key].get()); + auto initial_val = sig->read(); + auto sig_address = dynamic_cast(signals[key].get()); + pair assignment{sig_address, initial_val}; + ic_map.emplace(key, assignment); + } + oa_value_type signal_val = ic_map[key].second; + for (const auto &assignment: x.second) + { + string attribute_name = assignment.first; + strutils::toupper(attribute_name); + const Variable &value = assignment.second; + + // cout << attribute_name << endl; + if (attribute_name == "P" || attribute_name == "POW" || attribute_name == "POWER") + { + signal_val.m_field = polar(sqrt(value.as_double()), arg(signal_val.m_field)); + // cout << "################" << endl; + // cout << signal_val << endl; + } + else if (attribute_name == "PHASE" || attribute_name == "PHI") + { + signal_val.m_field = polar(abs(signal_val.m_field), value.as_double()); + // cout << "################" << endl; + // cout << signal_val << endl; + } + else if (attribute_name == "WL" || attribute_name == "LAMBDA" || attribute_name == "WAVELENGTH") + { + signal_val.setWavelength(value.as_double()); + // cout << "################" << endl; + // cout << signal_val << endl; + } + else + { + cerr << "Unknown attribute" << endl; + exit(1); + } + } + specsGlobalConfig.nodeset_orders[key] = pair( + dynamic_cast(signals[key].get()) + , signal_val); + } +#endif +} + +void ICDirective::create() const +{ + cerr << "IC directive is not implemented" << endl; + exit(1); +} \ No newline at end of file -- cgit v1.2.3