diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-11-23 05:37:42 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-11-23 05:37:42 +0100 |
commit | c6052ed87c983f35bb53207f1add7d642c9f34f9 (patch) | |
tree | 3aab13dad2fa23ffffabb8a41818c8b4fb99d9ca | |
parent | 316550e9bef1afbebefd5438093b94eec4a0ecdd (diff) | |
download | bxgen-c6052ed87c983f35bb53207f1add7d642c9f34f9.zip |
Use 0 for UNDEFINED
-rwxr-xr-x | bxgen.c | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -28,7 +28,6 @@ #/ To-Do list #/ #/ - Simplify -#/ - Use 0 for UNDEFINED. Make the zero value useful #/ - Factor out checks #/ - Allow to format the message in CHECK and FAIL macros #/ - String table for names and arrays @@ -93,6 +92,8 @@ #/ #/ Done features #/ +#/ - Simplify +#/ - Use 0 for UNDEFINED. Make the zero value useful #/ - Library #/ - IO static dispatch #/ - Correct serialization for endianness @@ -216,7 +217,7 @@ enum { MAX_NUM_ENTITIES = 16 * 1024, // For indices - UNDEFINED = -1, // FIXME Make it 0. + UNDEFINED = 0, // Sea of Nodes flow type // @@ -816,6 +817,9 @@ u64 u64_from_dec_str(c8 *s, c8 *s_end) { // i64 pool_add(Pool *pool, Entity data) { + if (pool->num_entities == 0) + ++pool->num_entities; + CHECK(pool != NULL && pool->entities != NULL, "Invalid arguments", UNDEFINED); CHECK(pool->num_entities < pool->capacity, "Out of memory", UNDEFINED); @@ -1027,6 +1031,9 @@ void proc_node_add(Pool *pool, i64 proc, i64 node) { CHECK(n->index_in_proc == UNDEFINED, "Internal",); + if (p->num_nodes == UNDEFINED) + ++p->num_nodes; + i64 index = p->num_nodes; if (n->op == CTRL_RET) @@ -1096,6 +1103,9 @@ void unit_proc_add(Pool *pool, i64 unit, i64 proc) { CHECK(p->index_in_unit == UNDEFINED, "Internal",); + if (u->num_procs == UNDEFINED) + ++u->num_procs; + i64 index = u->num_procs; CHECK(index < MAX_NUM_PROCS, "Out of memory",); @@ -1858,6 +1868,7 @@ void x86_64_emit_node( i64 node, u32 context ) { + // FIXME Return success status. // TODO Log generated asm. CHECK(pool != NULL && pool->entities != NULL, "Invalid arguments",); @@ -2793,7 +2804,6 @@ void x86_64_emit_node( .offset = codegen->offset_code + 2, .size = 8, .value = arg_offset, - .proc = UNDEFINED, // FIXME use zero value }; write_u8(LE, 0x48, begin + 10, end); // movabs @@ -2805,7 +2815,6 @@ void x86_64_emit_node( .size = 8, .name_size = n->call.target_name_size, .name = n->call.target_name, - .proc = UNDEFINED, // FIXME use zero value }; write_u8(LE, 0xff, begin + 20, end); // call @@ -2827,7 +2836,6 @@ void x86_64_emit_node( .size = 8, .name_size = n->call.target_name_size, .name = n->call.target_name, - .proc = UNDEFINED, // FIXME use zero value }; write_u8(LE, 0xff, begin + 11, end); // call @@ -2874,7 +2882,6 @@ void x86_64_emit_node( .size = 8, .name_size = n->call.target_name_size, .name = n->call.target_name, - .proc = UNDEFINED, // FIXME use zero value }; write_u8(LE, 0xff, begin + 16, end); // call @@ -2958,7 +2965,6 @@ void x86_64_emit_node( .offset = codegen->offset_code + 17, .size = 8, .value = arg_2_offset, - .proc = UNDEFINED, // FIXME use zero value }; write_u8 (LE, 0x48, begin + 25, end); // movabs @@ -2991,7 +2997,6 @@ void x86_64_emit_node( .size = 8, .name_size = n->call.target_name_size, .name = n->call.target_name, - .proc = UNDEFINED, // FIXME use zero value }; write_u8(LE, 0xff, begin + 80, end); // call @@ -3173,7 +3178,7 @@ void emit_proc( // NOTE // Now we assume that nodes are already sorted. - for (i64 i = 0; i < p->num_nodes; ++i) + for (i64 i = 1; i < p->num_nodes; ++i) x86_64_emit_node(pool, codegen, codegen->entities + proc, p->nodes[i], context); codegen->entities[proc].emit_done = 1; @@ -3184,7 +3189,7 @@ void emit_unit(Pool *pool, Codegen_Context *codegen, i64 unit, u16 arch) { CHECK(unit != UNDEFINED && pool->entities[unit].is_enabled, "No unit",); CHECK(pool->entities[unit].type == ENTITY_UNIT, "Invalid entity",); - for (i64 i = 0; i < pool->entities[unit].unit.num_procs; ++i) { + for (i64 i = 1; i < pool->entities[unit].unit.num_procs; ++i) { u32 context = 0; if (i == pool->entities[unit].unit.entry_point_index) { |