summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/build/create_modules.py
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2020-09-06 23:24:21 +0200
committer couriersud <couriersud@gmx.org>2020-09-12 23:20:16 +0200
commitca31c844cde7f54a285e3b9da358989e42258f5b (patch)
treef9e4a963b999e1352a4611a43a7c10c2d80957e7 /src/lib/netlist/build/create_modules.py
parentcda35c94020dbcb8dad8309aba11374c356c501e (diff)
netlist: move to generated header and link support files files.
* Removed device and macro header files. * All of those can be generated automatically so going forward there is no need for these any longer. * Introduced the modules concept. Modules are netlists for which automatic lib entries are generated. * Going forward you just store them in macro/modules and they will be automatically registered as device elements. * You need to do a "make generated" is src/lib/netlist/build * Some_device.cpp still needs to be added to netlist.lua * Added documentation on how to add devices to netlist. * Please refer to adding_devices.md for more information.
Diffstat (limited to 'src/lib/netlist/build/create_modules.py')
-rw-r--r--src/lib/netlist/build/create_modules.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/lib/netlist/build/create_modules.py b/src/lib/netlist/build/create_modules.py
new file mode 100644
index 00000000000..c3c9e7c19aa
--- /dev/null
+++ b/src/lib/netlist/build/create_modules.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+##
+## license:BSD-3-Clause
+## copyright-holders:Couriersud
+
+import os
+import os.path
+import re
+import sys
+import xml.sax
+import xml.sax.saxutils
+import zlib
+import datetime
+
+
+# workaround for version incompatibility
+if sys.version_info > (3, ):
+ long = int
+
+# globals
+
+last_src = ""
+
+def process_entry(srcfile, name, params):
+ global last_src
+ if (last_src != srcfile):
+ last_src = srcfile
+ print("// ---------------------------------------------------------------------")
+ print("// Source: {}".format(srcfile))
+ print("// ---------------------------------------------------------------------")
+ print("")
+ p = re.sub("\+","",params)
+ ps = p.split(",")
+ pusage = ""
+ pauto = ""
+ for x in ps:
+ if x[0:1] == "@":
+ pauto = pauto + ", " + x[1:]
+ else:
+ pusage = pusage + ", " + x
+ print("// usage : {}(name{})".format(name, pusage))
+ if len(pauto) > 0:
+ print("// auto connect: {}".format(pauto[2:]))
+ print("#define {}(...) \\".format(name))
+ print("\tNET_REGISTER_DEVEXT({}, __VA_ARGS__)".format(name))
+ print("")
+
+
+def process_file(srcfile):
+ src = open(srcfile,'r')
+ lines = src.readlines()
+ for line in lines:
+ ls = re.sub("\s+","",line.strip())
+ ls = re.sub("^\s*//.*","",ls)
+ ls = re.sub("\"","",ls)
+ m = re.match(r"NETLIST_START\((\w+)\)", ls)
+ if m != None:
+ print("\tEXTERNAL_LIB_ENTRY("+ m.group(1) + ")")
+ src.close()
+
+if __name__ == '__main__':
+ if (len(sys.argv) == 0):
+ print('Usage:')
+ print(' create_devinc files ...')
+ sys.exit(0)
+ files_sorted = [];
+ for argno in range(1, len(sys.argv)):
+ files_sorted.append(sys.argv[argno])
+ files_sorted.sort();
+ print("// license:CC0")
+ print("// copyright-holders:Couriersud")
+ print("")
+ now = datetime.datetime.now()
+ print("// File programmatically created " + now.strftime("%c"))
+ print("")
+ print("#include \"devices/net_lib.h\"")
+ print("")
+ print("NETLIST_START(modules_lib)")
+ print("")
+ for entry in files_sorted:
+ process_file(entry)
+ print("")
+ print("NETLIST_END()")