Step 6: optional reals HasReals, beside Target in parse.pas, says whether the target has reals (x86-64: yes). gen's UsesReals notes on a proc's chunk the first place its code computes with a real (Value of an F32/F64, a real literal); after MarkLive, now called from raz.pas, not WriteElf, a live chunk so noted is an error, "this target has no reals", when the target lacks them. Unused code and module-level decls aren't noted, so Fmt's interface can stay the same; a real moved whole (record copy) needs no FPU and isn't noted either. No option to test it: it was checked by flipping the const by hand. conform/check.sh -noreals skips run/X with an X.reals marker (Arith, Defers, Procs, RealRead), as appendix A has it.
| @@ -120,7 +120,7 @@ | ||
| 120 | 120 | - [x] 4. The tests split: a conformance suite any implementation |
| 121 | 121 | passes, apart from this compiler's own messages. |
| 122 | 122 | - [x] 5. The system integer. |
| 123 | -- [ ] 6. Optional reals: a target says whether it has them. | |
| 123 | +- [x] 6. Optional reals: a target says whether it has them. | |
| 124 | 124 | - [ ] 6a. `+` joins string constants (report, section 4). |
| 125 | 125 | - [ ] 6b. Array constants: `const P: [5]I64 = [...]`, in read-only |
| 126 | 126 | data, used as a variable that can't be changed (section 4). |
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | # The conformance suite: programs whose behaviour the report defines, |
| 3 | 3 | # which every implementation of raz must give, whatever its target. |
| 4 | 4 | # |
| 5 | -# conform/check.sh COMPILER [MESSAGES] | |
| 5 | +# conform/check.sh [-noreals] COMPILER [MESSAGES] | |
| 6 | 6 | # |
| 7 | 7 | # run from the directory above conform/. COMPILER is run as |
| 8 | 8 | # COMPILER -I DIR -o EXE FILE |
| @@ -14,6 +14,8 @@ | ||
| 14 | 14 | # run/X.expect its standard output |
| 15 | 15 | # run/X.args its arguments, one per line (optional) |
| 16 | 16 | # run/X.status its exit status (optional; 0 if missing) |
| 17 | +# run/X.reals there if the program uses reals, which a target may | |
| 18 | +# leave out (report, appendix A); -noreals skips it | |
| 17 | 19 | # err/X.raz a program the report says is an error, which must not |
| 18 | 20 | # compile; err/mods holds the modules it imports |
| 19 | 21 | # |
| @@ -21,10 +23,9 @@ | ||
| 21 | 23 | # included, is the implementation's own (appendix A). One that keeps |
| 22 | 24 | # its text may give MESSAGES, a directory of X.stderr and X.err, the |
| 23 | 25 | # standard error of run/X and of compiling err/X, compared when there. |
| 24 | -# | |
| 25 | -# Programs that use reals are among the rest, until a target may leave | |
| 26 | -# them out. | |
| 27 | 26 | |
| 27 | +noreals= | |
| 28 | +if [ "$1" = -noreals ]; then noreals=1; shift; fi | |
| 28 | 29 | raz=$1 |
| 29 | 30 | msg=${2:-/nonexistent} |
| 30 | 31 | out=build/conform |
| @@ -34,6 +35,7 @@ | ||
| 34 | 35 | |
| 35 | 36 | for f in conform/run/*.raz; do |
| 36 | 37 | name=$(basename $f .raz) |
| 38 | + [ -n "$noreals" ] && [ -f conform/run/$name.reals ] && continue | |
| 37 | 39 | if ! $raz -I conform/run/mods -o $out/$name $f 2>$out/$name.cerr; then |
| 38 | 40 | echo "FAIL $f: doesn't compile: $(cat $out/$name.cerr)" |
| 39 | 41 | fail=$((fail + 1)); continue |
An empty file.
An empty file.
An empty file.
An empty file.
| @@ -11,12 +11,12 @@ | ||
| 11 | 11 | | `src/diag.pas` | 274 | 198 | Messages: positions, source excerpts, colour, counts | |
| 12 | 12 | | `src/scan.pas` | 851 | 722 | Symbols, literals, comments, positions | |
| 13 | 13 | | `src/sym.pas` | 596 | 497 | Types, objects, scopes, layout | |
| 14 | -| `src/x64.pas` | 693 | 557 | Code buffer, chunks, fixups, places, instruction encoder | | |
| 15 | -| `src/gen.pas` | 1,733 | 1,481 | Items: loading, storing, copying, frames, calls | | |
| 16 | -| `src/parse.pas` | 2,464 | 2,221 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 14 | +| `src/x64.pas` | 695 | 559 | Code buffer, chunks, fixups, places, instruction encoder | | |
| 15 | +| `src/gen.pas` | 1,750 | 1,493 | Items: loading, storing, copying, frames, calls | | |
| 16 | +| `src/parse.pas` | 2,468 | 2,222 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 17 | 17 | | `src/link.pas` | 180 | 139 | Tree shaking, layout, patching, the places | |
| 18 | -| `src/elf.pas` | 425 | 352 | Static and dynamic ELF, symbol table, line numbers | | |
| 19 | -| `src/raz.pas` | 227 | 179 | The command line, the entry points | | |
| 18 | +| `src/elf.pas` | 424 | 351 | Static and dynamic ELF, symbol table, line numbers | | |
| 19 | +| `src/raz.pas` | 234 | 185 | The command line, the entry points | | |
| 20 | 20 | |
| 21 | 21 | Every file opens with a comment that says what it is, what it depends |
| 22 | 22 | on and what it leaves out. Read those first; they are the map. |
| @@ -67,9 +67,9 @@ | ||
| 67 | 67 | entry point, `_start`, is written as one more chunk: save `argc` and |
| 68 | 68 | `argv` and the address of the places (below), call every used |
| 69 | 69 | module's body, call `main`, call `Rt.exit`. |
| 70 | -6. `WriteElf` (`elf.pas`) has `link.pas` mark what `_start` reaches, | |
| 71 | - place it and patch it, then writes headers, code, data, symbols and | |
| 72 | - line numbers. | |
| 70 | +6. `MarkLive` (`link.pas`) marks what `_start` reaches; then | |
| 71 | + `WriteElf` (`elf.pas`) has `link.pas` place it and patch it, and | |
| 72 | + writes headers, code, data, symbols and line numbers. | |
| 73 | 73 | |
| 74 | 74 | ## A procedure, compiled |
| 75 | 75 | |
| @@ -443,7 +443,12 @@ | ||
| 443 | 443 | the program uses: `Use` marks the modules imported from the main module |
| 444 | 444 | and `Rt`; `UsesC` decides whether the program is dynamic, refusing one |
| 445 | 445 | that both uses C and has a module saying `link static`. Then it writes |
| 446 | -the entry point. A static program starts at `_start` itself. A dynamic | |
| 446 | +the entry point, and has `MarkLive` mark what it reaches. On a target | |
| 447 | +without reals (`HasReals`, beside `Target` in `parse.pas`; x86-64 has | |
| 448 | +them), a live chunk that computes with one is an error at the first | |
| 449 | +place it does: `UsesReals` in `gen.pas` notes it, from `Value` and a | |
| 450 | +real literal, on the chunk of the procedure being compiled. A real | |
| 451 | +moved whole, as a record's bytes are, isn't noted. A static program starts at `_start` itself. A dynamic | |
| 447 | 452 | one starts at a `_start` that calls `__libc_start_main` the way C's own |
| 448 | 453 | start-up does, which sets C up and calls back a `main` that runs the |
| 449 | 454 | module bodies and the program's `main`. |
| @@ -316,7 +316,6 @@ | ||
| 316 | 316 | cap := 1 shl 16; |
| 317 | 317 | buf := GetMem(cap); |
| 318 | 318 | len := 0; |
| 319 | - MarkLive(entry); | |
| 320 | 319 | dynamic := numNeeded > 0; |
| 321 | 320 | roExtra := 0; dynSize := 0; |
| 322 | 321 | if dynamic then SizeTables(roExtra, dynSize); |
| @@ -76,6 +76,7 @@ | ||
| 76 | 76 | procedure MakeItem(var x: TItem; o: PObj); |
| 77 | 77 | function RealOf(const x: TItem): double; |
| 78 | 78 | |
| 79 | +procedure UsesReals(const p: TPos); | |
| 79 | 80 | procedure Value(var x: TItem); |
| 80 | 81 | procedure Address(var x: TItem; r: longint); |
| 81 | 82 | procedure Save(var x: TItem); |
| @@ -149,6 +150,7 @@ | ||
| 149 | 150 | pushEnd: longint; { the code just after the last push of rax } |
| 150 | 151 | result: PType; { the procedure's result, or nil } |
| 151 | 152 | exitL: longint; |
| 153 | + codeChunk: longint = -1; { the procedure or body being compiled, or -1 } | |
| 152 | 154 | { parameters arriving in registers: where each is stored on entry } |
| 153 | 155 | inReg: array[0..13] of longint; |
| 154 | 156 | inSlot: array[0..13] of int64; |
| @@ -367,8 +369,21 @@ | ||
| 367 | 369 | if Unpush then begin dec(pc); dec(depth); pushEnd := -1 end; |
| 368 | 370 | end; |
| 369 | 371 | |
| 372 | +{ Code computing with a real is noted on its chunk, at the first place, | |
| 373 | + for a target without reals (report 5.1) to refuse if the chunk turns | |
| 374 | + out to be used. A real moved whole, as a record's bytes are copied, | |
| 375 | + needs nothing the target lacks, and isn't noted. } | |
| 376 | +procedure UsesReals(const p: TPos); | |
| 377 | +begin | |
| 378 | + if (codeChunk >= 0) and not chunks^[codeChunk].reals then begin | |
| 379 | + chunks^[codeChunk].reals := true; | |
| 380 | + chunks^[codeChunk].realsAt := p; | |
| 381 | + end; | |
| 382 | +end; | |
| 383 | + | |
| 370 | 384 | procedure Value(var x: TItem); |
| 371 | 385 | begin |
| 386 | + if x.typ^.form = fReal then UsesReals(x.pos); | |
| 372 | 387 | case x.mode of |
| 373 | 388 | mConst: ConstTo(RAX, x); |
| 374 | 389 | mVar: LoadVar(x, RAX); |
| @@ -1571,6 +1586,7 @@ | ||
| 1571 | 1586 | var i, top: longint; n: int64; |
| 1572 | 1587 | begin |
| 1573 | 1588 | BeginChunk(c); |
| 1589 | + codeChunk := c; | |
| 1574 | 1590 | NoteLine(line, 1); { a declaration starts a line } |
| 1575 | 1591 | Push(RBP); |
| 1576 | 1592 | MovRR(RBP, RSP); |
| @@ -1707,6 +1723,7 @@ | ||
| 1707 | 1723 | procedure EndProc(c: longint); |
| 1708 | 1724 | var n: int64; |
| 1709 | 1725 | begin |
| 1726 | + codeChunk := -1; | |
| 1710 | 1727 | if depth <> 0 then Fatal('internal error: stack depth'); |
| 1711 | 1728 | { running off the end returns zeros } |
| 1712 | 1729 | if result <> nil then |
| @@ -27,6 +27,10 @@ | ||
| 27 | 27 | Target = 'linux-x86_64'; |
| 28 | 28 | TargetOS = 'linux'; |
| 29 | 29 | TargetArch = 'x86_64'; |
| 30 | + { Whether the target has reals (report, appendix A): x86-64 always has | |
| 31 | + SSE2. Without them, used code that computes with one is an error, | |
| 32 | + which raz.pas reports once it knows what the program uses. } | |
| 33 | + HasReals: boolean = true; | |
| 30 | 34 | |
| 31 | 35 | var |
| 32 | 36 | libDir, mainDir: shortstring; |
| @@ -1053,7 +1057,7 @@ | ||
| 1053 | 1057 | if ival < 0 then MakeConst(x, tU64, ival) else MakeConst(x, tConst, ival); |
| 1054 | 1058 | Next; |
| 1055 | 1059 | end; |
| 1056 | - sReal: begin MakeReal(x, rval); Next end; | |
| 1060 | + sReal: begin MakeReal(x, rval); UsesReals(TokPos); Next end; | |
| 1057 | 1061 | sString: begin MakeStr(x); Next end; |
| 1058 | 1062 | sIdent: begin |
| 1059 | 1063 | Designator(x, called); |
| @@ -212,6 +212,13 @@ | ||
| 212 | 212 | Ud2; |
| 213 | 213 | EndChunk(start); |
| 214 | 214 | |
| 215 | + MarkLive(entry); | |
| 216 | + if not HasReals then | |
| 217 | + for i := 0 to numChunks - 1 do | |
| 218 | + if chunks^[i].live and chunks^[i].reals then | |
| 219 | + Error(chunks^[i].realsAt, 'this target has no reals'); | |
| 220 | + if errors > 0 then Finish; | |
| 221 | + | |
| 215 | 222 | mainPath := path; |
| 216 | 223 | if run then begin |
| 217 | 224 | { argv from Main.raz on is the program's, ending in nil as it must } |
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | |
| 21 | 21 | interface |
| 22 | 22 | |
| 23 | -uses scan; | |
| 23 | +uses scan, diag; | |
| 24 | 24 | |
| 25 | 25 | const |
| 26 | 26 | RAX = 0; RCX = 1; RDX = 2; RBX = 3; RSP = 4; RBP = 5; RSI = 6; RDI = 7; |
| @@ -59,6 +59,8 @@ | ||
| 59 | 59 | adr: int64; { its address, set by the linker } |
| 60 | 60 | live: boolean; { reached from the entry point } |
| 61 | 61 | ext: boolean; { bss: the address of a C symbol, its name } |
| 62 | + reals: boolean; { code: computes with reals, first at realsAt } | |
| 63 | + realsAt: TPos; | |
| 62 | 64 | end; |
| 63 | 65 | |
| 64 | 66 | { A place in the source whose code starts at a place in text: for |