MCPcopy Create free account
hub / github.com/Xilinx/Vitis_Libraries / inst_generator

Class inst_generator

solver/scripts/instance_generator.py:82–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80# ------------------------------------------------------------------------------
81
82class inst_generator:
83 def __init__(self, spec_file, api_name, param_file, param_name):
84 self.spec_file = spec_file
85 self.spec_data = get_api_spec(spec_file, api_name)
86 self.params = get_params(param_file, param_name)
87
88 def valid_all_params(self):
89 #lifecycle_status
90 if "lifecycle_status" in self.spec_data:
91 lifecycle_status = self.spec_data["lifecycle_status"]
92 if lifecycle_status in ["obsolete", "superseded"]:
93 print("WARNING: API {} is {}!".format(self.spec_data["api_name"], lifecycle_status))
94 else:
95 print("INFO: API {} version: {}".format(self.spec_data["api_name"], lifecycle_status))
96
97 for p in self.spec_data["parameters"]:
98 if p["name"] not in self.params:
99 print("Parameter {} is not defined in parameter file.".format(p["name"]))
100 return False
101 v = self.params[p["name"]]
102 # type/enum/min/max checkings
103 #if p["type"] not in ["int", "uint", "float", "double", "bool", "typename"]
104 # print("Valid alues are [typename, bool, int, double")
105 # return False
106 if p["type"] == "typename":
107 if "enum" in p and v not in p["enum"]:
108 print("{} is not valid enum for {}.".format(v, p["name"]))
109 return False
110 elif p["type"] == "int" or p["type"] == "uint":
111 if "minimum" in p and int(v) < int(p["minimum"]):
112 print("{!s} is less than minimum {} of {}.".format(v, p["minimum"], p["name"]))
113 return False
114 if "maximum" in p and int(v) > int(p["maximum"]):
115 print("{!s} is greater than maximum {} of {}.".format(v, p["maximum"], p["name"]))
116 return False
117 if "enum" in p and v not in [int(item) for item in p["enum"]]:
118 print("{} is not valid enum for {}.".format(v, p["name"]))
119 return False
120 elif p["type"] == "double" or p["type"] == "float":
121 if "minimum" in p and float(v) < float(p["minimum"]):
122 print("{!s} is less than minimum {} of {}.".format(v, p["minimum"], p["name"]))
123 return False
124 if "maximum" in p and float(v) > float(p["maximum"]):
125 print("{!s} is greater than maximum {} of {}.".format(v, p["maximum"], p["name"]))
126 return False
127 if "enum" in p and v not in [float(item) for item in p["enum"]]:
128 print("{} is not valid enum for {}.".format(v, p["name"]))
129 return False
130 elif p["type"] == "bool":
131 if v not in ["true", "false"]:
132 print("{} is not valid bool type for {}.".format(v, p["name"]))
133 #validator
134 #standard output:
135 #{"is_valid": true}
136 #{"is_valid": false, "err_message": "TT_COEF must be the same as TT_DATA"}
137 if "validator" in p:
138 od = run_function(os.path.join(os.path.dirname(self.spec_file), p["validator"]["file"]), p["validator"]["function"], self.params)
139 if not od["is_valid"]:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected