aboutsummaryrefslogtreecommitdiff
path: root/sys/gen.py
diff options
context:
space:
mode:
Diffstat (limited to 'sys/gen.py')
-rwxr-xr-xsys/gen.py48
1 files changed, 45 insertions, 3 deletions
diff --git a/sys/gen.py b/sys/gen.py
index 02ff952..4dcbc4d 100755
--- a/sys/gen.py
+++ b/sys/gen.py
@@ -289,6 +289,44 @@ def fmtsyscallold(writer, musl):
print(f"# {word[0][1:]:<8}{name[0]:<10} {name[1]}", file=writer)
# ------------------------------------------------------------------------
+# atomic
+
+def snaketolower(name):
+ return "".join(w for w in name.split("_"))
+
+def modifytype(line):
+ return line.replace("uint64_t", "uint64").replace("uint32_t", "uint32").replace("uintptr_t","uintptr")
+
+def fmtatomic(writer, reader):
+ def fmt(name):
+ prefix = ""
+ index = name.find("a_")
+ if index > 0:
+ prefix = name[:index]
+
+ name = name[index:]
+ name = name.replace("a_", "")
+ return prefix + "atomicĀ·" + snaketolower(name)
+
+ for line in reader:
+ word = [modifytype(w) for w in line.split(" ")]
+ if len(word) == 3:
+ if word[0].strip() == "#define" and word[1].strip() == word[2].strip():
+ continue
+ if len(word) == 2:
+ if word[0].strip() == "#define" and "libc.h" in word[1]:
+ continue
+
+ ours = [ fmt(w) if "a_" in w else w for w in word ]
+ line = " ".join(ours)
+ line = line.replace("static inline void ", "static inline void\n")\
+ .replace("static inline int ", "static inline int\n")\
+ .replace("if (", "if(").replace("for (", "for(").replace("while (", "while(")\
+ .replace("do {", "do{").replace("} while", "}while").replace(") {", "){")
+
+ print(line, file=writer, end="")
+
+# ------------------------------------------------------------------------
# types
stdintdefs=[
@@ -384,6 +422,10 @@ if __name__ == "__main__":
with open(f"{libnarch}/bits.h", "w") as io:
fmtbits(io, musl, source)
+ print("--> emitting atomics", file=stderr)
+ with open(f"{musl}/atomic_arch.h") as reader, open(f"{libnarch}/atomic.h", "w") as writer:
+ fmtatomic(writer,reader)
+
print("--> emitting syscalls", file=stderr)
with open(f"{libn}/syscall.h", "w") as io:
fmtsyscall(io,musl)
@@ -394,17 +436,17 @@ if __name__ == "__main__":
source, target = "generic", "port"
musl = f"{muslroot}/arch/{source}"
- libn = f"linux/{target}/arch"
+ libn = f"linux/{target}/os"
mkpath(libnarch, exist_ok=True)
with open(f"{libn}/errno.h","w") as io:
fmterrno(io, musl)
musl = f"{muslroot}/src/errno"
- libn = "src/errno.inc.h"
+ libn = "linux/src/errno.inc.h"
with open(libn,"w") as io:
fmtstrerror(io, musl)
- libn = "src/internal.h"
+ libn = "linux/src/internal.h"
musl = f"{muslroot}/src/internal/syscall.h"
needfix = False