mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[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:
16
scripts/codegen/__init__.py
Normal file
16
scripts/codegen/__init__.py
Normal 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")
|
||||
|
||||
43
scripts/codegen/int_types.py
Normal file
43
scripts/codegen/int_types.py
Normal 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")})
|
||||
|
||||
Reference in New Issue
Block a user