X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2Fbertos_utils.py;h=f4732edebfba4d295e23c4a984290134b6e25c57;hb=37a6db28f23f5fce42e2e3f3f91274f77a1ba41e;hp=3e8f36ba6ec4850085e974560eff052e86db835f;hpb=de2c05363918e67440d53c5b3a60664b26cd1afb;p=bertos.git diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 3e8f36ba..f4732ede 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -56,6 +56,8 @@ def createBertosProject(projectInfo): string = open(sourcesDir + "/" + key, "r").read() for parameter, infos in value.items(): value = infos["value"] + if "type" in infos["informations"] and infos["informations"]["type"] == "autoenabled": + value = "1" if "unsigned" in infos["informations"].keys() and infos["informations"]["unsigned"]: value += "U" if "long" in infos["informations"].keys() and infos["informations"]["long"]: @@ -68,6 +70,9 @@ def createBertosProject(projectInfo): makefile = open("mktemplates/template.mk", "r").read() makefile = mkGenerator(projectInfo, makefile) open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile) + ## Destination main.c file + main = open("srctemplates/main.c", "r").read() + open(prjdir + "/main.c", "w").write(main) if "codelite" in projectInfo.info("OUTPUT"): workspace = codeliteWorkspaceGenerator(projectInfo) open(directory + "/" + os.path.basename(prjdir) + ".workspace", "w").write(workspace) @@ -83,10 +88,11 @@ def mkGenerator(projectInfo, makefile): mkData["$cpuname"] = projectInfo.info("CPU_INFOS")["CORE_CPU"] mkData["$cflags"] = " ".join(projectInfo.info("CPU_INFOS")["C_FLAGS"]) mkData["$ldflags"] = " ".join(projectInfo.info("CPU_INFOS")["LD_FLAGS"]) - mkData["$csrc"], mkData["$pcsrc"] = csrcGenerator(projectInfo) + mkData["$csrc"], mkData["$pcsrc"], mkData["$constants"] = csrcGenerator(projectInfo) mkData["$prefix"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[0] mkData["$suffix"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[1] mkData["$cross"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[0] + mkData["$main"] = os.path.basename(projectInfo.info("PROJECT_PATH")) + "/main.c" for key in mkData: while makefile.find(key) != -1: makefile = makefile.replace(key, mkData[key]) @@ -103,33 +109,71 @@ def makefileGenerator(projectInfo, makefile): def csrcGenerator(projectInfo): modules = projectInfo.info("MODULES") + files = projectInfo.info("FILES") if "harvard" in projectInfo.info("CPU_INFOS")["CPU_TAGS"]: - pcsrc_need = projectInfo.info("CPU_INFOS")["PC_SRC"] + harvard = True else: - pcsrc_need = [] + harvard = False + ## file to be included in CSRC variable csrc = [] + ## file to be included in PCSRC variable pcsrc = [] + ## constants to be included at the beginning of the makefile + constants = {} + moduleFiles = set([]) + dependencyFiles = set([]) + ## assembly sources + asmFiles = set([]) for module, information in modules.items(): if information["enabled"]: - for filename, path in findDefinitions(module + ".c", projectInfo): - path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH")) - csrc.append(path + "/" + filename) - if module in pcsrc_need: - pcsrc.append(path + "/" + filename) - for filename, path in findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo): - path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH")) - csrc.append(path + "/" + filename) - if module in pcsrc_need: - pcsrc.append(path + "/" + filename) - for tag in projectInfo.info("CPU_INFOS")["CPU_TAGS"]: - for filename, path in findDefinitions(module + "_" + tag + ".c", projectInfo): - path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH")) - csrc.append(path + "/" + filename) - if module in pcsrc_need: - pcsrc.append(path + "/" + filename) + if "constants" in information: + constants.update(information["constants"]) + cfiles, sfiles = findModuleFiles(module, projectInfo) + moduleFiles |= set(cfiles) + asmFiles |= set(sfiles) + for fileDependency in information["depends"]: + if fileDependency in files: + dependencyCFiles, dependencySFiles = findModuleFiles(fileDependency, projectInfo) + dependencyFiles |= set(dependencyCFiles) + asmFiles |= set(dependencySFiles) + for file in moduleFiles: + if not harvard or "harvard" not in information or information["harvard"] == "both": + csrc.append(file) + if harvard and "harvard" in information: + pcsrc.append(file) + for file in dependencyFiles: + csrc.append(file) csrc = " \\\n\t".join(csrc) + " \\" pcsrc = " \\\n\t".join(pcsrc) + " \\" - return csrc, pcsrc + constants = "\n".join([os.path.basename(projectInfo.info("PROJECT_PATH")) + "_" + key + " = " + str(value) for key, value in constants.items()]) + return csrc, pcsrc, constants + +def findModuleFiles(module, projectInfo): + ## Find the files related to the selected module + cfiles = [] + sfiles = [] + ## .c files related to the module and the cpu architecture + for filename, path in findDefinitions(module + ".c", projectInfo) + \ + findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo): + path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "") + cfiles.append(path + "/" + filename) + ## .s files related to the module and the cpu architecture + for filename, path in findDefinitions(module + ".s", projectInfo) + \ + findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".s", projectInfo) + \ + findDefinitions(module + ".S", projectInfo) + \ + findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".S", projectInfo): + path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "") + sfiles.append(path + "/" + filename) + ## .c and .s files related to the module and the cpu tags + for tag in projectInfo.info("CPU_INFOS")["CPU_TAGS"]: + for filename, path in findDefinitions(module + "_" + tag + ".c", projectInfo): + path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "") + cfiles.append(path + "/" + filename) + for filename, path in findDefinitions(module + "_" + tag + ".s", projectInfo) + \ + findDefinitions(module + "_" + tag + ".S", projectInfo): + path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "") + sfiles.append(path + "/" + filename) + return cfiles, sfiles def codeliteProjectGenerator(projectInfo): template = open("cltemplates/bertos.project").read() @@ -240,20 +284,31 @@ def loadModuleDefinition(first_comment): moduleDefinition["module_description"] = line[line.find("\\brief") + len("\\brief "):] moduleDict = {} if "module_name" in moduleDefinition.keys(): - moduleDict[moduleDefinition[const.MODULE_DEFINITION["module_name"]]] = {} - if "module_depends" in moduleDefinition.keys(): + moduleName = moduleDefinition[const.MODULE_DEFINITION["module_name"]] + del moduleDefinition[const.MODULE_DEFINITION["module_name"]] + moduleDict[moduleName] = {} + if const.MODULE_DEFINITION["module_depends"] in moduleDefinition.keys(): if type(moduleDefinition[const.MODULE_DEFINITION["module_depends"]]) == str: moduleDefinition[const.MODULE_DEFINITION["module_depends"]] = (moduleDefinition[const.MODULE_DEFINITION["module_depends"]],) - moduleDict[moduleDefinition[const.MODULE_DEFINITION["module_name"]]]["depends"] = moduleDefinition[const.MODULE_DEFINITION["module_depends"]] + moduleDict[moduleName]["depends"] = moduleDefinition[const.MODULE_DEFINITION["module_depends"]] + del moduleDefinition[const.MODULE_DEFINITION["module_depends"]] else: - moduleDict[moduleDefinition[const.MODULE_DEFINITION["module_name"]]]["depends"] = () - if "module_configuration" in moduleDefinition.keys(): - moduleDict[moduleDefinition[const.MODULE_DEFINITION["module_name"]]]["configuration"] = moduleDefinition[const.MODULE_DEFINITION["module_configuration"]] + moduleDict[moduleName]["depends"] = () + if const.MODULE_DEFINITION["module_configuration"] in moduleDefinition.keys(): + moduleDict[moduleName]["configuration"] = moduleDefinition[const.MODULE_DEFINITION["module_configuration"]] + del moduleDefinition[const.MODULE_DEFINITION["module_configuration"]] else: - moduleDict[moduleDefinition[const.MODULE_DEFINITION["module_name"]]]["configuration"] = "" + moduleDict[moduleName]["configuration"] = "" if "module_description" in moduleDefinition.keys(): - moduleDict[moduleDefinition[const.MODULE_DEFINITION["module_name"]]]["description"] = moduleDefinition["module_description"] - moduleDict[moduleDefinition[const.MODULE_DEFINITION["module_name"]]]["enabled"] = False + moduleDict[moduleName]["description"] = moduleDefinition["module_description"] + del moduleDefinition["module_description"] + if const.MODULE_DEFINITION["module_harvard"] in moduleDefinition.keys(): + harvard = moduleDefinition[const.MODULE_DEFINITION["module_harvard"]] + if harvard == "both" or harvard == "pgm_memory": + moduleDict[moduleName]["harvard"] = harvard + del moduleDefinition[const.MODULE_DEFINITION["module_harvard"]] + moduleDict[moduleName]["constants"] = moduleDefinition + moduleDict[moduleName]["enabled"] = False return toBeParsed, moduleDict def loadDefineLists(commentList): @@ -317,7 +372,8 @@ def loadModuleData(project): moduleInfoDict = {} listInfoDict = {} configurationInfoDict = {} - for filename, path in findDefinitions("*.h", project): + fileDict = {} + for filename, path in findDefinitions("*.h", project) + findDefinitions("*.c", project) + findDefinitions("*.s", project) + findDefinitions("*.S", project): commentList = getCommentList(open(path + "/" + filename, "r").read()) if len(commentList) > 0: moduleInfo = {} @@ -352,6 +408,7 @@ def loadModuleData(project): project.setInfo("MODULES", moduleInfoDict) project.setInfo("LISTS", listInfoDict) project.setInfo("CONFIGURATIONS", configurationInfoDict) + project.setInfo("FILES", fileDict) def formatParamNameValue(text): """ @@ -372,6 +429,7 @@ def loadConfigurationInfos(path): "min": the minimum value for integer parameters "max": the maximum value for integer parameters "long": boolean indicating if the num is a long + "unsigned": boolean indicating if the num is an unsigned "value_list": the name of the enum for enum parameters """ configurationInfos = {} @@ -381,6 +439,8 @@ def loadConfigurationInfos(path): configurationInfos[name] = {} configurationInfos[name]["value"] = value configurationInfos[name]["informations"] = informations + if not "type" in configurationInfos[name]["informations"]: + configurationInfos[name]["informations"]["type"] = findParameterType(configurationInfos[name]) if ("type" in configurationInfos[name]["informations"].keys() and configurationInfos[name]["informations"]["type"] == "int" and configurationInfos[name]["value"].find("L") != -1): @@ -395,6 +455,12 @@ def loadConfigurationInfos(path): configurationInfos[name]["brief"] = brief return configurationInfos +def findParameterType(parameter): + if "value_list" in parameter["informations"]: + return "enum" + if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None: + return "int" + def sub(string, parameter, value): """ Substitute the given value at the given parameter define in the given string