[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")
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
import cog
|
||||
|
||||
supported_architectures = {
|
||||
"amd64": "__amd64__",
|
||||
}
|
||||
|
||||
def arch_includes(header):
|
||||
prefix = "if"
|
||||
for arch, define in supported_architectures.items():
|
||||
cog.outl(f"#{prefix} defined({define})")
|
||||
cog.outl(f"#include <__j6libc/arch/{arch}/{header}>")
|
||||
prefix = "elif"
|
||||
cog.outl("#endif")
|
||||
|
||||
|
||||
int_widths = (8, 16, 32, 64)
|
||||
int_mods = ("fast", "least")
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
|
||||
/**[[[cog code generation
|
||||
from j6libc import arch_includes
|
||||
from codegen import arch_includes
|
||||
|
||||
arch_includes("errno.h")
|
||||
arch_includes("errno.h", root="__j6libc")
|
||||
|
||||
]]]*/
|
||||
/*[[[end]]]*/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/**[[[cog code generation
|
||||
import cog
|
||||
from j6libc import definition, int_widths, int_mods
|
||||
from codegen.int_types import definition, int_widths, int_mods
|
||||
|
||||
for width in int_widths:
|
||||
definition("#define", f"PRId{width}", f"__INT{width}_FMTd__")
|
||||
|
||||
@@ -18,7 +18,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/**[[[cog code generation
|
||||
from j6libc import atomic_types
|
||||
from codegen.int_types import atomic_types
|
||||
|
||||
deftypes = ["BOOL", "CHAR16", "CHAR32", "CHAR", "INT",
|
||||
"LLONG", "SHORT", "WCHAR_T", "POINTER"]
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/**[[[cog code generation
|
||||
import cog
|
||||
from j6libc import definition, int_widths, int_mods
|
||||
from codegen.int_types import definition, int_widths, int_mods
|
||||
|
||||
for width in int_widths:
|
||||
definition("typedef", f"__INT{width}_TYPE__", f"int{width}_t;")
|
||||
|
||||
Reference in New Issue
Block a user