Skip to content

Commit b9ce51b

Browse files
committed
Test
1 parent 9d34f38 commit b9ce51b

19 files changed

Lines changed: 302 additions & 418 deletions

File tree

include/lauf/config.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ typedef uint64_t lauf_uint;
4343
# if defined(__has_cpp_attribute)
4444
# if __has_cpp_attribute(clang::musttail)
4545
# define LAUF_TAIL_CALL [[clang::musttail]]
46+
# ifndef LAUF_HAS_TAIL_CALL_ELIMINATION
47+
# define LAUF_HAS_TAIL_CALL_ELIMINATION 1
48+
# endif
4649
# elif defined(__clang__)
4750
# define LAUF_TAIL_CALL [[clang::musttail]]
4851
# else
@@ -67,7 +70,7 @@ typedef uint64_t lauf_uint;
6770
#endif
6871

6972
#ifndef LAUF_HAS_TAIL_CALL_ELIMINATION
70-
# define LAUF_HAS_TAIL_CALL_ELIMINATION 1
73+
# define LAUF_HAS_TAIL_CALL_ELIMINATION 0
7174
#endif
7275

7376
//=== warnings ===//

include/lauf/runtime/memory.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ typedef struct lauf_asm_function lauf_asm_function;
1212
typedef struct lauf_asm_global lauf_asm_global;
1313
typedef struct lauf_asm_layout lauf_asm_layout;
1414
typedef struct lauf_asm_signature lauf_asm_signature;
15-
typedef struct lauf_runtime_address_store lauf_runtime_address_store;
1615
typedef struct lauf_runtime_address lauf_runtime_address;
1716
typedef struct lauf_runtime_fiber lauf_runtime_fiber;
1817
typedef struct lauf_runtime_function_address lauf_runtime_function_address;
@@ -36,7 +35,7 @@ const char* lauf_runtime_get_cstr(lauf_runtime_process* p, lauf_runtime_address
3635

3736
/// Gets the address for a native pointer of the specified allocation.
3837
/// On success, updates `allocation` to the actual address.
39-
bool lauf_runtime_get_address(lauf_runtime_process* p, lauf_runtime_address_store* allocation,
38+
bool lauf_runtime_get_address(lauf_runtime_process* p, lauf_runtime_address* allocation,
4039
const void* ptr);
4140

4241
/// Returns the address of a global variable of the process.
@@ -133,8 +132,7 @@ bool lauf_runtime_unpoison_allocation(lauf_runtime_process* p, lauf_runtime_addr
133132
/// Existing addresses for `a` are only valid if their offset is `< o`; otherwise, they become
134133
/// invalidated. Neither `a` nor `a'` can be freed until the allocation has been merged again.
135134
bool lauf_runtime_split_allocation(lauf_runtime_process* p, lauf_runtime_address addr,
136-
lauf_runtime_address_store* addr1,
137-
lauf_runtime_address_store* addr2);
135+
lauf_runtime_address* addr1, lauf_runtime_address* addr2);
138136

139137
/// Merges an allocation that has been previously split.
140138
///

include/lauf/runtime/value.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,19 @@
88

99
LAUF_HEADER_START
1010

11-
typedef struct lauf_runtime_address_store
12-
{
13-
uint64_t value;
14-
} lauf_runtime_address_store;
15-
1611
typedef struct lauf_runtime_address
1712
{
1813
// Order of the fields chosen carefully:
1914
// acess to allocation is an AND, acess to offset a SHIFT, access to generation SHIFT + AND
2015
// (which is the one only necessary for checks). In addition, treating it as an integer and e.g.
2116
// incrementing it changes allocation first, not offset. That way, bugs are caught earlier.
22-
uint64_t allocation : 30;
17+
uint32_t allocation : 30;
2318
uint32_t generation : 2;
2419
uint32_t offset;
2520
} lauf_runtime_address;
2621

2722
static const lauf_runtime_address lauf_runtime_address_null = {0x3FFFFFFF, 0x3, 0xFFFFFFFF};
2823

29-
lauf_runtime_address lauf_runtime_address_from_store(lauf_runtime_address_store addr);
30-
31-
lauf_runtime_address_store lauf_runtime_address_to_store(lauf_runtime_address addr);
32-
33-
void lauf_runtime_address_store_set_allocation(lauf_runtime_address_store* store,
34-
uint32_t allocation);
35-
36-
void lauf_runtime_address_store_set_generation(lauf_runtime_address_store* store,
37-
uint8_t generation);
38-
39-
void lauf_runtime_address_store_set_offset(lauf_runtime_address_store* store, uint32_t offset);
40-
4124
typedef struct lauf_runtime_function_address
4225
{
4326
uint16_t index;
@@ -53,7 +36,7 @@ typedef union lauf_runtime_value
5336
lauf_uint as_uint;
5437
lauf_sint as_sint;
5538
void* as_native_ptr;
56-
lauf_runtime_address_store as_address;
39+
lauf_runtime_address as_address;
5740
lauf_runtime_function_address as_function_address;
5841
} lauf_runtime_value;
5942

src/lauf/asm/builder.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ LAUF_NOINLINE lauf_asm_inst* emit_body(lauf_asm_inst* ip, lauf_asm_builder* b,
373373
assert(insts[dest->offset].op() == lauf::asm_op::block);
374374
auto dest_offset = dest->offset + 1;
375375

376-
LAUF_BITFIELD_CONVERSION(jump->jump.offset = std::int32_t(dest_offset - cur_offset));
376+
jump->jump.offset(std::int32_t(dest_offset - cur_offset));
377377
}
378378

379379
return ip;
@@ -673,7 +673,7 @@ const lauf_asm_block* lauf_asm_inst_branch(lauf_asm_builder* b, const lauf_asm_b
673673
else if (!b->cur->insts.empty() && b->cur->insts.back().op() == lauf::asm_op::cc)
674674
{
675675
// Remove the cc instruction.
676-
auto cc = b->cur->insts.back().cc.value;
676+
auto cc = b->cur->insts.back().cc.value();
677677
b->cur->insts.pop_back();
678678

679679
switch (cc)
@@ -1021,12 +1021,10 @@ void lauf_asm_inst_global_addr(lauf_asm_builder* b, const lauf_asm_global* globa
10211021

10221022
b->cur->insts.push_back(*b, LAUF_BUILD_INST_VALUE(global_addr, global->allocation_idx));
10231023
b->cur->vstack.push_constant(*b, [&] {
1024-
lauf_runtime_value result;
1025-
lauf_runtime_address addr;
1026-
LAUF_BITFIELD_CONVERSION(addr.allocation = global->allocation_idx);
1027-
addr.offset = 0;
1028-
addr.generation = 0; // Always true for globals.
1029-
result.as_address = lauf_runtime_address_to_store(addr);
1024+
lauf_runtime_value result;
1025+
LAUF_BITFIELD_CONVERSION(result.as_address.allocation = global->allocation_idx);
1026+
result.as_address.offset = 0;
1027+
result.as_address.generation = 0; // Always true for globals.
10301028
return result;
10311029
}());
10321030
}
@@ -1290,7 +1288,7 @@ load_store_constant load_store_constant_folding(lauf_asm_module* mod,
12901288
// TOCTOU is okay, we just can't constant fold because of it.
12911289
auto globals = lauf::get_globals(mod);
12921290

1293-
auto constant_addr = lauf_runtime_address_from_store(addr.as_constant.as_address);
1291+
auto constant_addr = addr.as_constant.as_address;
12941292
if (constant_addr.allocation >= globals.count && constant_addr.generation != 0
12951293
&& constant_addr.offset != 0)
12961294
return load_store_dynamic;
@@ -1332,10 +1330,8 @@ void lauf_asm_inst_load_field(lauf_asm_builder* b, lauf_asm_type type, size_t fi
13321330
else if (constant_folding == load_store_global)
13331331
{
13341332
add_pop_top_n(b, 1);
1335-
b->cur->insts.push_back( //
1336-
*b, LAUF_BUILD_INST_VALUE( //
1337-
load_global_value,
1338-
lauf_runtime_address_from_store(addr->as_constant.as_address).allocation));
1333+
b->cur->insts.push_back(*b, LAUF_BUILD_INST_VALUE(load_global_value,
1334+
addr->as_constant.as_address.allocation));
13391335
b->cur->vstack.push_output(*b, 1);
13401336
}
13411337
else if (type.layout.size == 0 && type.load_fn == nullptr)
@@ -1378,10 +1374,8 @@ void lauf_asm_inst_store_field(lauf_asm_builder* b, lauf_asm_type type, size_t f
13781374
else if (constant_folding == load_store_global)
13791375
{
13801376
add_pop_top_n(b, 1);
1381-
b->cur->insts.push_back( //
1382-
*b, LAUF_BUILD_INST_VALUE( //
1383-
store_global_value,
1384-
lauf_runtime_address_from_store(addr->as_constant.as_address).allocation));
1377+
b->cur->insts.push_back(*b, LAUF_BUILD_INST_VALUE(store_global_value,
1378+
addr->as_constant.as_address.allocation));
13851379
LAUF_BUILD_ASSERT(b->cur->vstack.pop(1), "missing value");
13861380
}
13871381
else if (type.layout.size == 0 && type.store_fn == nullptr)

src/lauf/asm/builder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ struct lauf_asm_builder : lauf::intrinsic_arena<lauf_asm_builder>
283283
[&](const char* context, std::ptrdiff_t offset) { \
284284
lauf_asm_inst result; \
285285
LAUF_BITFIELD_CONVERSION(result.Name = {lauf::asm_op::Name, std::int32_t(offset)}); \
286-
if (result.Name.offset != offset) \
286+
if (result.Name.offset() != offset) \
287287
b->error(context, "offset too big"); \
288288
return result; \
289289
}(LAUF_BUILD_ASSERT_CONTEXT, static_cast<std::int64_t>(Offset))
@@ -316,7 +316,7 @@ struct lauf_asm_builder : lauf::intrinsic_arena<lauf_asm_builder>
316316
[&](const char* context, std::size_t value) { \
317317
lauf_asm_inst result; \
318318
LAUF_BITFIELD_CONVERSION(result.Name = {lauf::asm_op::Name, std::uint32_t(value)}); \
319-
if (value != result.Name.value) \
319+
if (value != result.Name.value()) \
320320
b->error(context, "invalid value"); \
321321
return result; \
322322
}(LAUF_BUILD_ASSERT_CONTEXT, Value)

0 commit comments

Comments
 (0)