From b33de6076b1794cb95438d05bc9ac33e3fdb4b19 Mon Sep 17 00:00:00 2001 From: asoffer Date: Sat, 18 Nov 2023 15:36:14 -0500 Subject: [PATCH] Adding more generated constants to C compatibility headers. --- toolchain/stdlib/compat/c/BUILD | 47 ++++++++++++++++++- toolchain/stdlib/compat/c/locale.template.ic | 13 +++++ .../compat/c/{stdio.ic => stdio.template.ic} | 19 ++++++++ toolchain/stdlib/compat/c/test.ic | 0 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 toolchain/stdlib/compat/c/locale.template.ic rename toolchain/stdlib/compat/c/{stdio.ic => stdio.template.ic} (77%) create mode 100644 toolchain/stdlib/compat/c/test.ic diff --git a/toolchain/stdlib/compat/c/BUILD b/toolchain/stdlib/compat/c/BUILD index 2cf4377e6..fdea2cafb 100644 --- a/toolchain/stdlib/compat/c/BUILD +++ b/toolchain/stdlib/compat/c/BUILD @@ -50,9 +50,36 @@ generated_ic_library( deps = [], ) -ic_library( +generated_ic_library( + name = "locale", + srcs = ["locale.template.ic"], + includes = ["locale.h"], + symbols = { + "LC_ALL": "int", + "LC_COLLATE": "int", + "LC_CTYPE": "int", + "LC_MONETARY": "int", + "LC_NUMERIC": "int", + "LC_TIME": "int", + }, + deps = [], +) + +generated_ic_library( name = "stdio", - srcs = ["stdio.ic"], + srcs = ["stdio.template.ic"], + includes = ["stdio.h"], + symbols = { + "BUFSIZ": "int", + "EOF": "int", + "FOPEN_MAX": "int", + "FILENAME_MAX": "int", + "L_tmpnam": "int", + "SEEK_CUR": "int", + "SEEK_END": "int", + "SEEK_SET": "int", + "TMP_MAX": "int", + }, deps = [":types"], ) @@ -74,3 +101,19 @@ generated_ic_library( ":types", ], ) + +ic_library( + name = "test_build", + srcs = ["test.ic"], + testonly = True, + visibility = ["//visibility:private"], + deps = [ + ":ctype", + ":limits", + ":locale", + ":string", + ":stdio", + ":types", + ":time", + ], +) diff --git a/toolchain/stdlib/compat/c/locale.template.ic b/toolchain/stdlib/compat/c/locale.template.ic new file mode 100644 index 000000000..1ac6c836e --- /dev/null +++ b/toolchain/stdlib/compat/c/locale.template.ic @@ -0,0 +1,13 @@ +// This module provides an interface to functions in the C-header file. + +let lconv ::= builtin.opaque() +let LC_ALL ::= {{{LC_ALL}}} +let LC_COLLATE ::= {{{LC_COLLATE}}} +let LC_CTYPE ::= {{{LC_CTYPE}}} +let LC_MONETARY ::= {{{LC_MONETARY}}} +let LC_NUMERIC ::= {{{LC_NUMERIC}}} +let LC_TIME ::= {{{LC_TIME}}} + +// Additionally, the C-header defines the constant `NULL`, for which +// there is no corresponding value in this module. For such uses, prefer the +// Icarus native `null` constant. diff --git a/toolchain/stdlib/compat/c/stdio.ic b/toolchain/stdlib/compat/c/stdio.template.ic similarity index 77% rename from toolchain/stdlib/compat/c/stdio.ic rename to toolchain/stdlib/compat/c/stdio.template.ic index 90b4bf31d..fae48e694 100644 --- a/toolchain/stdlib/compat/c/stdio.ic +++ b/toolchain/stdlib/compat/c/stdio.template.ic @@ -5,6 +5,21 @@ let c ::= import "std.compat.c.types" let FILE ::= builtin.opaque() let fpos_t ::= builtin.opaque() +let size_t ::= c.unsigned_long // TODO: Generate this. + +let _IOFBF ::= null +let _IOLBF ::= null +let _IONBF ::= null + +let BUFSIZ ::= {{{BUFSIZ}}} +// let EOF ::= {{{EOF}}} TODO: Enable when negation is support +let FOPEN_MAX ::= {{{FOPEN_MAX}}} +let FILENAME_MAX ::= {{{FILENAME_MAX}}} +let L_tmpnam ::= {{{L_tmpnam}}} +let SEEK_CUR ::= {{{SEEK_CUR}}} +let SEEK_END ::= {{{SEEK_END}}} +let SEEK_SET ::= {{{SEEK_SET}}} +let TMP_MAX ::= {{{TMP_MAX}}} let fopen ::= builtin.foreign("fopen", ([*]char, [*]char) -> *FILE) let freopen ::= builtin.foreign("freopen", ([*]char, [*]char, *FILE) -> *FILE) @@ -42,3 +57,7 @@ let remove ::= builtin.foreign("remove", [*]char -> c.int) let rename ::= builtin.foreign("rename", ([*]char, [*]char) -> c.int) let tmpfile ::= builtin.foreign("tmpfile", () -> *FILE) let tmpnam ::= builtin.foreign("tmpnam", [*]char -> [*]char) + +// Additionally, the C-header defines the constant `NULL`, for which +// there is no corresponding value in this module. For such uses, prefer the +// Icarus native `null` constant. diff --git a/toolchain/stdlib/compat/c/test.ic b/toolchain/stdlib/compat/c/test.ic new file mode 100644 index 000000000..e69de29bb