Add lambda and static objects (#30)

* add some more tests for let

* support static strings

* add function calling

* add prints for windows debgu

* one test only

* try swapping r14 and r15 in windows

* swap back

* disable defun for now

* fix massive bug

* fix formatting
This commit is contained in:
water111
2020-09-12 13:11:42 -04:00
committed by GitHub
parent de5aa7e5e4
commit d56540f8c0
50 changed files with 1139 additions and 93 deletions
+9 -5
View File
@@ -103,17 +103,20 @@ FunctionRecord ObjectGenerator::add_function_to_seg(int seg, int min_align) {
rec.func_id = int(m_function_data_by_seg.at(seg).size());
m_function_data_by_seg.at(seg).emplace_back();
m_function_data_by_seg.at(seg).back().min_align = min_align;
m_all_function_records.push_back(rec);
return rec;
}
FunctionRecord ObjectGenerator::get_existing_function_record(int f_idx) {
return m_all_function_records.at(f_idx);
}
/*!
* Add a new IR instruction to the function. An IR instruction may contain 0, 1, or multiple
* actual Instructions. These Instructions can be added with add_instruction. The IR_Record
* can be used as a label for jump targets.
*/
IR_Record ObjectGenerator::add_ir(const FunctionRecord& func) {
// verify we aren't adding to an old function. not technically an error, but doesn't make sense
assert(func.func_id == int(m_function_data_by_seg.at(func.seg).size()) - 1);
IR_Record rec;
rec.seg = func.seg;
rec.func_id = func.func_id;
@@ -149,8 +152,6 @@ IR_Record ObjectGenerator::get_future_ir_record_in_same_func(const IR_Record& ir
* Add a new Instruction for the given IR instruction.
*/
InstructionRecord ObjectGenerator::add_instr(Instruction inst, IR_Record ir) {
// verify we aren't adding to an old instruction or function
assert(ir.func_id == int(m_function_data_by_seg.at(ir.seg).size()) - 1);
// only this second condition is an actual error.
assert(ir.ir_id ==
int(m_function_data_by_seg.at(ir.seg).at(ir.func_id).ir_to_instruction.size()) - 1);
@@ -166,7 +167,6 @@ InstructionRecord ObjectGenerator::add_instr(Instruction inst, IR_Record ir) {
}
void ObjectGenerator::add_instr_no_ir(FunctionRecord func, Instruction inst) {
assert(func.func_id == int(m_function_data_by_seg.at(func.seg).size()) - 1);
m_function_data_by_seg.at(func.seg).at(func.func_id).instructions.push_back(inst);
}
@@ -182,6 +182,10 @@ StaticRecord ObjectGenerator::add_static_to_seg(int seg, int min_align) {
return rec;
}
std::vector<u8>& ObjectGenerator::get_static_data(const StaticRecord& rec) {
return m_static_data_by_seg.at(rec.seg).at(rec.static_id).data;
}
/*!
* Add linking data to add a type pointer in rec at offset.
* This will add an entry to the linking data, which will get patched at runtime, during linking.