Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 183b0d2

Browse files
committed
groundwork for ranges by named ref
1 parent e53d1b8 commit 183b0d2

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

basecode/compiler/byte_code_emitter.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ namespace basecode::compiler {
137137
if (named_ref->type == vm::assembler_named_ref_type_t::label)
138138
return;
139139

140-
if (temp_name == named_ref->name)
140+
if (temp_name == named_ref->name1)
141141
return;
142142

143143
auto is_pointer_type = result.type_result.inferred_type->is_pointer_type();
@@ -154,6 +154,7 @@ namespace basecode::compiler {
154154
vm::instruction_operand_t temp(_session.assembler().make_named_ref(
155155
vm::assembler_named_ref_type_t::local,
156156
temp_name,
157+
{},
157158
size));
158159

159160
if (is_composite && !is_pointer_type) {
@@ -256,6 +257,7 @@ namespace basecode::compiler {
256257
vm::instruction_operand_t(_session.assembler().make_named_ref(
257258
vm::assembler_named_ref_type_t::local,
258259
var->symbol()->name(),
260+
{},
259261
vm::op_size_for_byte_size(var->type_ref()->type()->size_in_bytes()))),
260262
vm::instruction_operand_t(_session.assembler().make_named_ref(
261263
vm::assembler_named_ref_type_t::label,
@@ -432,6 +434,7 @@ namespace basecode::compiler {
432434
vm::instruction_operand_t target_operand(assembler.make_named_ref(
433435
vm::assembler_named_ref_type_t::local,
434436
temp_local_name(target_number_class, 2),
437+
{},
435438
vm::op_size_for_byte_size(target_size)));
436439
result.operands.emplace_back(target_operand);
437440

@@ -803,7 +806,7 @@ namespace basecode::compiler {
803806
return false;
804807
}
805808
label_ref = flow_control->exit_label;
806-
label_name = label_ref->name;
809+
label_name = label_ref->name1;
807810
}
808811

809812
block->comment(
@@ -1133,6 +1136,7 @@ namespace basecode::compiler {
11331136
vm::instruction_operand_t result_operand(assembler.make_named_ref(
11341137
vm::assembler_named_ref_type_t::local,
11351138
temp_local_name(target_number_class, 1),
1139+
{},
11361140
vm::op_size_for_byte_size(target_size)));
11371141
result.operands.emplace_back(result_operand);
11381142
block->pop(result_operand);
@@ -1192,6 +1196,7 @@ namespace basecode::compiler {
11921196
vm::instruction_operand_t target_operand(assembler.make_named_ref(
11931197
vm::assembler_named_ref_type_t::local,
11941198
temp_local_name(target_number_class, 2),
1199+
{},
11951200
vm::op_size_for_byte_size(target_size)));
11961201
result.operands.emplace_back(target_operand);
11971202

@@ -1223,7 +1228,7 @@ namespace basecode::compiler {
12231228
return false;
12241229
}
12251230
label_ref = flow_control->continue_label;
1226-
label_name = label_ref->name;
1231+
label_name = label_ref->name1;
12271232
}
12281233

12291234
block->comment(
@@ -1237,6 +1242,7 @@ namespace basecode::compiler {
12371242
result.operands.emplace_back(_session.assembler().make_named_ref(
12381243
vm::assembler_named_ref_type_t::local,
12391244
var->symbol()->name(),
1245+
{},
12401246
vm::op_size_for_byte_size(result.type_result.inferred_type->size_in_bytes())));
12411247
break;
12421248
}
@@ -1421,6 +1427,7 @@ namespace basecode::compiler {
14211427
vm::instruction_operand_t result_operand(assembler.make_named_ref(
14221428
vm::assembler_named_ref_type_t::local,
14231429
temp_local_name(result.type_result.inferred_type->number_class(), 3),
1430+
{},
14241431
size));
14251432

14261433
switch (op_type) {
@@ -2572,6 +2579,7 @@ namespace basecode::compiler {
25722579
vm::instruction_operand_t(assembler.make_named_ref(
25732580
vm::assembler_named_ref_type_t::offset,
25742581
name,
2582+
{},
25752583
vm::op_sizes::word)));
25762584
}
25772585

@@ -2765,6 +2773,7 @@ namespace basecode::compiler {
27652773
vm::instruction_operand_t result_operand(assembler.make_named_ref(
27662774
vm::assembler_named_ref_type_t::local,
27672775
temp_local_name(result.type_result.inferred_type->number_class(), 1),
2776+
{},
27682777
vm::op_sizes::byte));
27692778
result.operands.emplace_back(result_operand);
27702779

@@ -2879,6 +2888,7 @@ namespace basecode::compiler {
28792888
vm::instruction_operand_t result_operand(assembler.make_named_ref(
28802889
vm::assembler_named_ref_type_t::local,
28812890
temp_local_name(result.type_result.inferred_type->number_class(), 1),
2891+
{},
28822892
size));
28832893
result.operands.emplace_back(result_operand);
28842894

@@ -2990,7 +3000,7 @@ namespace basecode::compiler {
29903000
bool byte_code_emitter::is_temp_local(const vm::instruction_operand_t& operand) {
29913001
if (operand.type() == vm::instruction_operand_type_t::named_ref) {
29923002
auto named_ref = *operand.data<vm::assembler_named_ref_t*>();
2993-
return named_ref->name.substr(1, 4) == "temp";
3003+
return named_ref->name1.substr(1, 4) == "temp";
29943004
}
29953005
return false;
29963006
}

basecode/vm/assembler.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ namespace basecode::vm {
8989
continue;
9090

9191
switch (operand.fixup_ref->type) {
92+
case assembler_named_ref_type_t::range: {
93+
break;
94+
}
9295
case assembler_named_ref_type_t::local: {
93-
auto it = _locals.find(operand.fixup_ref->name);
96+
auto it = _locals.find(operand.fixup_ref->name1);
9497
if (it != _locals.end()) {
9598
const auto& local = it->second;
9699
operand.value.r = local.reg.number;
@@ -108,7 +111,7 @@ namespace basecode::vm {
108111
break;
109112
}
110113
case assembler_named_ref_type_t::offset: {
111-
auto it = _locals.find(operand.fixup_ref->name);
114+
auto it = _locals.find(operand.fixup_ref->name1);
112115
if (it != _locals.end()) {
113116
const auto& local = it->second;
114117
auto imm_value = local.offset;
@@ -142,7 +145,7 @@ namespace basecode::vm {
142145
auto label_ref = boost::get<assembler_named_ref_t*>(v);
143146
r.error(
144147
"A031",
145-
fmt::format("unexpected assembler_named_ref_t*: {}", label_ref->name));
148+
fmt::format("unexpected assembler_named_ref_t*: {}", label_ref->name1));
146149
continue;
147150
}
148151
_terp->write(
@@ -234,7 +237,7 @@ namespace basecode::vm {
234237

235238
switch (operand.fixup_ref->type) {
236239
case assembler_named_ref_type_t::label: {
237-
auto label = find_label(operand.fixup_ref->name);
240+
auto label = find_label(operand.fixup_ref->name1);
238241
if (label != nullptr) {
239242
operand.value.u = label->address();
240243
}
@@ -258,7 +261,7 @@ namespace basecode::vm {
258261
if (named_ref != nullptr) {
259262
switch (named_ref->type) {
260263
case assembler_named_ref_type_t::label: {
261-
auto label = find_label(named_ref->name);
264+
auto label = find_label(named_ref->name1);
262265
if (label != nullptr) {
263266
value = label->address();
264267
}
@@ -296,9 +299,10 @@ namespace basecode::vm {
296299

297300
assembler_named_ref_t* assembler::make_named_ref(
298301
assembler_named_ref_type_t type,
299-
const std::string& name,
302+
const std::string& name1,
303+
const std::string& name2,
300304
vm::op_sizes size) {
301-
auto key = fmt::format("{}{}", name, static_cast<uint8_t>(type));
305+
auto key = fmt::format("{}{}{}", name1, name2, static_cast<uint8_t>(type));
302306
auto it = _named_refs.find(key);
303307
if (it != _named_refs.end()) {
304308
auto ref = &it->second;
@@ -309,7 +313,8 @@ namespace basecode::vm {
309313
auto insert_pair = _named_refs.insert(std::make_pair(
310314
key,
311315
assembler_named_ref_t {
312-
.name = name,
316+
.name1 = name1,
317+
.name2 = name2,
313318
.size = size,
314319
.type = type
315320
}));
@@ -577,7 +582,7 @@ namespace basecode::vm {
577582
if (v.which() == 0)
578583
items += fmt::format(format_spec, boost::get<uint64_t>(v));
579584
else
580-
items += boost::get<assembler_named_ref_t*>(v)->name;
585+
items += boost::get<assembler_named_ref_t*>(v)->name1;
581586
if ((item_index % 8) == 0) {
582587
source_file->add_source_line(
583588
listing_source_line_type_t::data_definition,

basecode/vm/assembler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ namespace basecode::vm {
5959

6060
assembler_named_ref_t* make_named_ref(
6161
assembler_named_ref_type_t type,
62-
const std::string& name,
62+
const std::string& name1,
63+
const std::string& name2 = {},
6364
vm::op_sizes size = vm::op_sizes::qword);
6465

6566
bool apply_addresses(common::result& r);

basecode/vm/instruction_block.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ namespace basecode::vm {
100100
case assembler_named_ref_type_t::none: {
101101
break;
102102
}
103+
case assembler_named_ref_type_t::range: {
104+
op.type |= operand_encoding_t::flags::reg
105+
| operand_encoding_t::flags::range;
106+
break;
107+
}
103108
case assembler_named_ref_type_t::local: {
104109
op.type |= operand_encoding_t::flags::reg;
105110
break;

basecode/vm/vm_types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,13 @@ namespace basecode::vm {
493493
none,
494494
label,
495495
local,
496+
range,
496497
offset,
497498
};
498499

499500
struct assembler_named_ref_t {
500-
std::string name;
501+
std::string name1;
502+
std::string name2;
501503
vm::op_sizes size = vm::op_sizes::qword;
502504
assembler_named_ref_type_t type = assembler_named_ref_type_t::none;
503505
};

0 commit comments

Comments
 (0)