about summary refs log tree commit diff stats
path: root/apps
Commit message (Collapse)AuthorAgeFilesLines
* 5921Kartik Agaram2020-01-262-5/+130
|
* 5920Kartik Agaram2020-01-262-29/+57
|
* 5919Kartik Agaram2020-01-262-24/+0
|
* 5918Kartik Agaram2020-01-262-22/+11
|
* 5916Kartik Agaram2020-01-222-3/+3
|
* 5913Kartik Agaram2020-01-201-6/+0
|
* 5911 - support for compound typesKartik Agaram2020-01-202-15/+13
|
* 5909Kartik Agaram2020-01-201-18/+62
| | | | Draft 5.
* 5908Kartik Agaram2020-01-201-4/+6
| | | | | Now parse-type passes, but some outer test is failing. The result is not being consumed right by `type-equal?`.
* 5907Kartik Agaram2020-01-201-10/+24
| | | | | | Draft 3. Getting close. Now the tree structure seems right.
* 5906Kartik Agaram2020-01-201-3/+35
| | | | Draft 2.
* 5905Kartik Agaram2020-01-201-84/+329
| | | | | | | Draft of my first, incorrect attempt at parsing s-expressions. No matter how many times I've done this, I never get it right the first time.
* 5904Kartik Agaram2020-01-192-3/+3
|
* 5903Kartik Agaram2020-01-192-4/+5
|
* 5902Kartik Agaram2020-01-191-6/+6
|
* 5898 - strengthen slice-empty? checkKartik Agaram2020-01-1914-0/+0
| | | | | | | | | | | Anytime we create a slice, the first check tends to be whether it's empty. If we handle ill-formed slices here where start > end, that provides a measure of safety. In the Mu translator (mu.subx) we often check for a trailing ':' or ',' and decrement slice->end to ignore it. But that could conceivably yield ill-formed slices if the slice started out empty. Now we make sure we never operate on such ill-formed slices.
* 5897 - rename comparison instructionsKartik Agaram2020-01-1622-379/+379
| | | | | | | Signed and unsigned don't quite capture the essence of what the different combinations of x86 flags are doing for SubX. The crucial distinction is that one set of comparison operators is for integers and the second is for addresses.
* 5896Kartik Agaram2020-01-161-1/+1
|
* 5895Kartik Agaram2020-01-161-1/+1
|
* 5894Kartik Agaram2020-01-162-5/+5
|
* 5890Kartik Agaram2020-01-141-0/+0
|
* 5887 - reorganize libraryKartik Agaram2020-01-1414-0/+0
| | | | | | | Layers 0-89 are used in self-hosting SubX. Layers 90-99 are not needed for self-hosting SubX, and therefore could use transitional levels of syntax sugar. Layers 100 and up use all SubX syntax sugar.
* 5885Kartik Agaram2020-01-122-62/+231
| | | | Finalize design for type trees.
* 5883 - drop the `ref` keywordKartik Agaram2020-01-1214-229/+229
| | | | | | | | | | When I created it I was conflating two things: a) needing to refer to just the start, rather than the whole, and b) counting indirections. Both are kinda ill-posed. Now Mu will have just `addr` and `handle` types. Normal types will translate implicitly to `addr` types, while `handle` will always require explicit handling.
* 5882Kartik Agaram2020-01-101-3/+1
|
* 5880Kartik Agaram2020-01-108-8/+8
|
* 5879Kartik Agaram2020-01-102-10/+99
|
* 5877Kartik Agaram2020-01-031-2/+2
|
* 5876 - address -> addrKartik Agaram2020-01-0316-182/+182
|
* 5872Kartik Agaram2020-01-022-1/+14
|
* 5868Kartik Agaram2020-01-021-0/+0
| | | | | Follow stupid GNU convention, because why not: https://www.gnu.org/prep/standards/html_node/Releases.html
* 5860Kartik Agaram2020-01-011-0/+17
|
* 5856Kartik Agaram2020-01-0125-2/+877
|
* 5849 - more integration testing of function callsKartik Agaram2020-01-012-7/+98
| | | | | | | | | | | | | | | | I can now run this program: fn main -> result/ebx: int { result <- do-add 3 4 } fn do-add a: int, b: int -> result/ebx: int { result <- copy a result <- add b } We still can't define local variables, but can write any programs involving ints by passing in enough arguments for temporaries.
* 5848Kartik Agaram2020-01-011-5/+5
|
* 5847 - literal inputsKartik Agaram2019-12-3115-1/+207
|
* 5846Kartik Agaram2019-12-301-10/+10
|
* 5845Kartik Agaram2019-12-301-0/+3
|
* 5844Kartik Agaram2019-12-301-3/+3
| | | | | Let's start putting r32 first in compare instructions that need it. Ordering there is quite subtle and of great import.
* 5834Kartik Agaram2019-12-272-3/+4
| | | | Bugfix.
* 5833Kartik Agaram2019-12-271-1/+1
|
* 5832 - support for function outputsKartik Agaram2019-12-272-14/+138
| | | | | | | | | | | We haven't implemented it yet, but there's now a design for how we check whether a function has written its output correctly. Functions must write to each output at the top level at least once, and never overwrite an output register in the top-level once it's been defined. This is conservative (it can be perfectly reasonable for functions to write the output, reuse the register for a temporary, and then write the output again) but easy to check.
* 5831Kartik Agaram2019-12-272-27/+38
|
* 5830Kartik Agaram2019-12-262-1/+5
| | | | | Bugfix: statements defining a new register variable require an initializer instruction.
* 5828 - copy (mov) instructionsKartik Agaram2019-12-262-22/+144
|
* 5827 - give primitives one more bit of metadataKartik Agaram2019-12-262-4/+59
| | | | | Copy (mov) instructions are unlike instructions we've encoded so far, in that their destination is not read.
* 5826 - done with basic binary opsKartik Agaram2019-12-262-0/+197
|
* 5825 - code-generation for add opcodesKartik Agaram2019-12-262-26/+158
|
* 5824 - code-generation for all inc/dec opcodesKartik Agaram2019-12-262-2/+199
|
* 5823Kartik Agaram2019-12-222-0/+55
|
lass="w"> for (int i = /*skip code segment*/1; i < SIZE(p.segments); ++i) drop_labels(p.segments.at(i)); } void replace_global_variables_with_addresses(program& p, const map<string, uint32_t>& address) { if (p.segments.empty()) return; replace_global_variables_in_code_segment(p.segments.at(0), address); for (int i = /*skip code*/1; i < SIZE(p.segments); ++i) replace_global_variables_in_data_segment(p.segments.at(i), address); } void replace_global_variables_in_code_segment(segment& code, const map<string, uint32_t>& address) { for (int i = 0; i < SIZE(code.lines); ++i) { line& inst = code.lines.at(i); line new_inst; for (int j = 0; j < SIZE(inst.words); ++j) { const word& curr = inst.words.at(j); if (!contains_key(address, curr.data)) { if (!looks_like_hex_int(curr.data)) raise << "missing reference to global '" << curr.data << "'\n" << end(); new_inst.words.push_back(curr); continue; } if (!valid_use_of_global_variable(curr)) { raise << "'" << to_string(inst) << "': can't refer to global variable '" << curr.data << "'\n" << end(); return; } emit_hex_bytes(new_inst, get(address, curr.data), 4); } inst.words.swap(new_inst.words); trace(99, "transform") << "instruction after transform: '" << data_to_string(inst) << "'" << end(); } } void replace_global_variables_in_data_segment(segment& data, const map<string, uint32_t>& address) { for (int i = 0; i < SIZE(data.lines); ++i) { line& l = data.lines.at(i); line new_l; for (int j = 0; j < SIZE(l.words); ++j) { const word& curr = l.words.at(j); if (!contains_key(address, curr.data)) { if (looks_like_hex_int(curr.data)) { if (has_operand_metadata(curr, "imm32")) emit_hex_bytes(new_l, curr, 4); else if (has_operand_metadata(curr, "imm16")) emit_hex_bytes(new_l, curr, 2); else if (has_operand_metadata(curr, "imm8")) emit_hex_bytes(new_l, curr, 1); else if (has_operand_metadata(curr, "disp8")) raise << "can't use /disp8 in a non-code segment\n" << end(); else if (has_operand_metadata(curr, "disp16")) raise << "can't use /disp16 in a non-code segment\n" << end(); else if (has_operand_metadata(curr, "disp32")) raise << "can't use /disp32 in a non-code segment\n" << end(); else new_l.words.push_back(curr); } else { raise << "missing reference to global '" << curr.data << "'\n" << end(); new_l.words.push_back(curr); } continue; } trace(99, "transform") << curr.data << " maps to " << HEXWORD << get(address, curr.data) << end(); emit_hex_bytes(new_l, get(address, curr.data), 4); } l.words.swap(new_l.words); trace(99, "transform") << "after transform: '" << data_to_string(l) << "'" << end(); } } bool valid_use_of_global_variable(const word& curr) { if (has_operand_metadata(curr, "imm32")) return true; // End Valid Uses Of Global Variable(curr) return false; } //:: a more complex sanity check for how we use global variables //: requires first saving some data early before we pack operands :(after "Begin Level-2 Transforms") Transform.push_back(correlate_disp32_with_mod); :(code) void correlate_disp32_with_mod(program& p) { if (p.segments.empty()) return; segment& code = p.segments.at(0); for (int i = 0; i < SIZE(code.lines); ++i) { line& inst = code.lines.at(i); for (int j = 0; j < SIZE(inst.words); ++j) { word& curr = inst.words.at(j); if (has_operand_metadata(curr, "disp32") && has_operand_metadata(inst, "mod")) curr.metadata.push_back("has_mod"); } } } :(before "End Valid Uses Of Global Variable(curr)") if (has_operand_metadata(curr, "disp32")) return has_metadata(curr, "has_mod"); // todo: more sophisticated check, to ensure we don't use global variable // addresses as a real displacement added to other operands. :(code) bool has_metadata(const word& w, const string& m) { for (int i = 0; i < SIZE(w.metadata); ++i) if (w.metadata.at(i) == m) return true; return false; } void test_global_variable_disallowed_in_jump() { Hide_errors = true; run( "== code\n" "eb/jump x/disp8\n" "== data\n" "x:\n" " 00 00 00 00\n" ); CHECK_TRACE_CONTENTS( "error: 'eb/jump x/disp8': can't refer to global variable 'x'\n" // sub-optimal error message; should be //? "error: can't jump to data (variable 'x')\n" ); } void test_global_variable_disallowed_in_call() { Hide_errors = true; run( "== code\n" "e8/call x/disp32\n" "== data\n" "x:\n" " 00 00 00 00\n" ); CHECK_TRACE_CONTENTS( "error: 'e8/call x/disp32': can't refer to global variable 'x'\n" // sub-optimal error message; should be //? "error: can't call to the data segment ('x')\n" ); } void test_global_variable_in_data_segment() { run( "== 0x1\n" "b9 x/imm32\n" "== 0x0a000000\n" "x:\n" " y/imm32\n" "y:\n" " 00 00 00 00\n" ); // check that we loaded 'x' with the address of 'y' CHECK_TRACE_CONTENTS( "load: 0x0a000000 -> 04\n" "load: 0x0a000001 -> 00\n" "load: 0x0a000002 -> 00\n" "load: 0x0a000003 -> 0a\n" ); CHECK_TRACE_COUNT("error", 0); } void test_raw_number_with_imm32_in_data_segment() { run( "== 0x1\n" "b9 x/imm32\n" "== 0x0a000000\n" "x:\n" " 1/imm32\n" ); // check that we loaded 'x' with the address of 1 CHECK_TRACE_CONTENTS( "load: 0x0a000000 -> 01\n" "load: 0x0a000001 -> 00\n" "load: 0x0a000002 -> 00\n" "load: 0x0a000003 -> 00\n" ); CHECK_TRACE_COUNT("error", 0); } void test_duplicate_global_variable() { Hide_errors = true; run( "== 0x1\n" "40/increment-EAX\n" "== 0x0a000000\n" "x:\n" "x:\n" " 00\n" ); CHECK_TRACE_CONTENTS( "error: duplicate global 'x'\n" ); } void test_global_variable_disp32_with_modrm() { run( "== code\n" "8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX x/disp32\n" "== data\n" "x:\n" " 00 00 00 00\n" ); CHECK_TRACE_COUNT("error", 0); } void test_global_variable_disp32_with_call() { transform( "== code\n" "foo:\n" " e8/call bar/disp32\n" "bar:\n" ); CHECK_TRACE_COUNT("error", 0); } string to_full_string(const line& in) { ostringstream out; for (int i = 0; i < SIZE(in.words); ++i) { if (i > 0) out << ' '; out << in.words.at(i).data; for (int j = 0; j < SIZE(in.words.at(i).metadata); ++j) out << '/' << in.words.at(i).metadata.at(j); } return out.str(); }