[scripts] Make j6libc.py into the codegen package

j6libc.py was initially made for libc to generate stdint.h, but it
gained a few things that aren't libc-specific. Move it to a package and
split the int-types-specific code into codegen.int_types.
This commit is contained in:
Justin C. Miller
2024-08-10 23:29:21 -07:00
parent ff64d1989f
commit fca570a163
6 changed files with 21 additions and 18 deletions

View File

@@ -0,0 +1,16 @@
import cog
supported_architectures = {
"amd64": "__amd64__",
}
def arch_includes(header, root=""):
prefix = "if"
for arch, define in supported_architectures.items():
cog.outl(f"#{prefix} defined({define})")
cog.outl(f"#include <{root}arch/{arch}/{header}>")
prefix = "elif"
cog.outl("#else")
cog.outl('#error "Unsupported platform"')
cog.outl("#endif")

View File

@@ -0,0 +1,43 @@
import cog
int_widths = (8, 16, 32, 64)
int_mods = ("fast", "least")
int_types = {
# type: abbrev
"char": "char",
"short": "short",
"int": "int",
"long": "long",
"long long": "llong",
}
def definition(kind, name, val, width=24):
cog.outl(f"{kind} {name:{width}} {val}")
atomic_types = {
"_Bool": "bool",
"signed char": "schar",
"char16_t": "char16_t",
"char32_t": "char32_t",
"wchar_t": "wchar_t",
"wchar_t": "wchar_t",
"size_t": "size_t",
"ptrdiff_t": "ptrdiff_t",
"intptr_t": "intptr_t",
"uintptr_t": "uintptr_t",
"intmax_t": "intmax_t",
"uintmax_t": "uintmax_t",
}
for name, abbrev in int_types.items():
atomic_types.update({name: abbrev, f"unsigned {name}": f"u{abbrev}"})
for width in int_widths:
atomic_types.update({t: t for t in (
f"int_least{width}_t",
f"uint_least{width}_t",
f"int_fast{width}_t",
f"uint_fast{width}_t")})