Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bedrock2/src/bedrock2/ToCString.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Definition prelude := "// Generated from Bedrock code. Avoid editing directly.
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <stdalign.h>

#define BR_WORD_MAX UINTPTR_MAX
typedef uintptr_t br_word_t;
Expand All @@ -28,6 +29,12 @@ static_assert(~(br_signed_t)0 == -(br_signed_t)1, ""two's complement"");
#error ""failed to confirm that target is little-endian""
#endif

// Word-align stackalloc buffers so they can be passed to external code that
// takes word pointers. Define BR_STACKALLOC_ALIGN empty for byte alignment.
#ifndef BR_STACKALLOC_ALIGN
#define BR_STACKALLOC_ALIGN alignas(br_word_t)
#endif

// ""An object shall have its stored value accessed only ... a character type.""
static inline br_word_t _br_load1(br_word_t a) {
return *((uint8_t *)a);
Expand Down Expand Up @@ -224,7 +231,7 @@ Fixpoint c_cmd (indent : string) (c : cmd) : string :=
* favoring readability over timely deallocation (which clang et al don't
* do anyway. However, name collisions can cause compilation errors. *)
let tmp := "_br_stackalloc_"++x in
indent ++ "uint8_t "++tmp++"["++c_lit n++"] = {0}; "++x++" = (br_word_t)&"++tmp++";"++LF++
indent ++ "BR_STACKALLOC_ALIGN uint8_t "++tmp++"["++c_lit n++"] = {0}; "++x++" = (br_word_t)&"++tmp++";"++LF++
c_cmd indent body
| cmd.set x (expr.inlinetable s t ei) =>
indent ++ "{ " ++ c_inlinetable t ++ " " ++ x ++ " = " ++ c_loadtable s (c_expr ei) ++ "; }" ++ LF
Expand Down
Loading