Commit Graph

40 Commits

Author SHA1 Message Date
Kartik Agaram 5a9795bb66 4881 2018-12-28 08:56:21 -08:00
Kartik Agaram 81605224f0 4847 2018-12-06 09:41:40 -08:00
Kartik Agaram 0043952064 4819 2018-12-02 16:58:30 -08:00
Kartik Agaram c7d45d918b 4812 2018-11-30 22:57:52 -08:00
Kartik Agaram 9d27e966b5 4808 - clean up comments in all subx files 2018-11-30 16:45:15 -08:00
Kartik Agaram ee9a9237d6 4802
Some automated commenting cleanup. Still needs more careful manual scanning.

  sed -i 's/^#   1-3/# . 1-3/' *.subx */*.subx
  sed -i 's/^#   op/# . op/' *.subx */*.subx
  sed -i 's/# vim/# . . vim/' *.subx */*.subx
  sed -i 's/^    # push args/    # . . push args/' *.subx */*.subx
  sed -i 's/^    # discard args/    # . . discard args/' *.subx */*.subx
  sed -i 's/^    # call/    # . . call/' *.subx */*.subx
  sed -i 's/^    # prolog/    # . prolog/' *.subx */*.subx
  sed -i 's/^    # epilog/    # . epilog/' *.subx */*.subx
  sed -i 's/^    # save registers/    # . save registers/' *.subx */*.subx
  sed -i 's/^    # restore registers/    # . restore registers/' *.subx */*.subx
  sed -i 's/  operand  /  register /' *.subx */*.subx
2018-11-30 11:13:36 -08:00
Kartik Agaram 6030d7e2e5 4801
Reindent all SubX code to make some room for the new comment style.
2018-11-30 10:54:42 -08:00
Kartik Agaram 93be389bef 4731 2018-10-28 12:41:04 -07:00
Kartik Agaram 04be5eb2ae 4703 2018-10-16 23:02:42 -07:00
Kartik Agaram f613a8bed5 4700 2018-10-16 00:10:15 -07:00
Kartik Agaram c25d9aa42a 4684
Turns out the tests for 'trace' have been broken in native mode since the
original commit (4674). Dangers of running my tests on Darwin, where I
can't run them natively.

The test failures didn't get flagged on CI because I'd forgotten to update
the exit code of the factorial app in commit 4664. At least that's fixed
in this commit.
2018-10-11 00:08:50 -07:00
Kartik Agaram c9d21799d6 4670 2018-10-05 21:54:08 -07:00
Kartik Agaram 94ad882e82 4668 2018-10-05 21:30:22 -07:00
Kartik Agaram 03d50cc83c 4667
Standardize on hyphens in all names.
And we'll use colons for namespacing labels in functions.
2018-10-05 19:49:47 -07:00
Kartik Agaram 9f1d0ef3fb 4663 2018-10-05 11:56:20 -07:00
Kartik Agaram ed0e64a981 4662 2018-10-05 10:42:16 -07:00
Kartik Agaram d383ba7634 4655 2018-10-02 20:58:39 -07:00
Kartik Agaram 5ddf4a4023 4653 2018-10-02 14:28:10 -07:00
Kartik Agaram 66aa96ecc7 4651 2018-10-02 13:34:19 -07:00
Kartik Agaram d25e51dc0f 4644 2018-10-01 15:53:44 -07:00
Kartik Agaram 1666b12f37 4641 2018-10-01 14:21:27 -07:00
Kartik Agaram 57628c0e44 4638 - extract some common libraries from apps
I'm still trying to figure out what the defaults should be. At the moment
you have to explicitly pass in every file you want loaded into the output
binary. Maybe that control is a good thing. The examples need no libraries
so far.
2018-10-01 12:27:39 -07:00
Kartik Agaram 1dcd9350ce 4624
Start requiring a '-o' flag to designate the output binary when translating.

Things currently get funky if you pass in multiple inputs, but that's ok.
This is the first step to supporting multiple input files for a single
output binary.
2018-09-30 23:12:54 -07:00
Kartik Agaram bc3e572acd 4518 2018-09-24 23:49:43 -07:00
Kartik Agaram 5347cf8bf4 4517 2018-09-24 23:01:38 -07:00
Kartik K. Agaram c5d9a32fe6 4516
More calling convention tweaks.

Use EBP to get consistently at parameters and locals.
Always put the first function argument closest to EBP.
2018-09-24 22:55:37 -07:00
Kartik Agaram ffa45b450b 4514
Get the calling convention right, per http://www.cs.virginia.edu/~evans/cs216/guides/x86.html
2018-09-24 17:28:48 -07:00
Kartik Agaram fd0ab85567 4513 2018-09-24 17:22:09 -07:00
Kartik Agaram 20d9875459 4508
Upgrade the test harness for the factorial "app" from ex11.
2018-09-23 21:01:28 -07:00
Kartik Agaram bf86f7f39d 4506
check_ints_equal now prints a newline after the failure message on failure.

We still don't know how to print a final newline after all the tests have
run, for the common case when all tests pass.

Ideally I could just emit a few instructions to `run_tests`. But I'd also
need to add a variable for the newline to the data segment. Or I need some
literal syntax for newlines in strings. We don't have support for backslash-escapes
yet.
2018-09-23 12:12:02 -07:00
Kartik Agaram d48cfd0f36 4505
Extract a helper from the factorial unit test: check_ints_equal.

Start of a vocabulary for unit tests.

I *could* also start thinking of supporting multi-file programs, but I'm
going to resist the temptation for now. Copy helpers as necessary, and
allow them to mutate and diverge for a while before we pummel them into
a Procrustean "standard library". Extracting a body of shared code immediately
starts to discourage innovation in the shared code.
2018-09-23 11:17:11 -07:00
Kartik Agaram 2b36eee9b1 4502 - support string literals directly in code
Doesn't de-duplicate in the data segment, though. If you use the literal
"foo" a hundred times in your code segment you're gonna spend a hundred
times the space you need to.

We can now simplify our test harness a bit in the factorial app, but we
still have to put in commandline args to compare with manually. We only
support length-prefixed strings, not null-terminated ones.
2018-09-22 22:17:09 -07:00
Kartik Agaram 8c580ba1de 4591 2018-09-22 10:33:41 -07:00
Kartik Agaram 3f8597bc3d 4586 - factorial checks commandline to run tests
No automated tests for argv_equal because we need it to run automated tests.
But maybe we should have them anyway.
2018-09-21 23:52:48 -07:00
Kartik Agaram 9372c16c00 4581
Even more cuddling. We want to keep lines short where the opcode and operands
are self-explanatory.

If there are any implicit registers, etc., we'll continue to do the table
layout.

The first two columns look messy now; let's see how this goes.
Maybe I'll give up on the tabular layout altogether, just string args with
a single space.
2018-09-21 16:56:37 -07:00
Kartik Agaram caaeccd68e 4567 - support automated tests in SubX
All it takes is to code-generate a simple function called 'run_tests' that
calls all functions starting with 'test_' one by one.

I've temporarily switched the factorial app to run as a test. But that's
temporary, because all the code to print '.' vs 'F' needs to get extracted
out into a helper.
2018-09-21 13:44:16 -07:00
Kartik Agaram a5a9c2afd6 4554 2018-09-20 15:50:05 -07:00
Kartik Agaram e07a3f2886 4537
Streamline the factorial function; we don't need to save a stack variable
into a register before operating on it. All instructions can take a stack
variable directly.

In the process we found two bugs:

a) Opcode f7 was not implemented correctly. It was internally consistent
but I'd never validated it against a natively running program. Turns out
it encodes multiple instructions, not just 'not'.

b) The way we look up imm32 operands was sometimes reading them before
disp8/disp32 operands.
2018-09-07 22:19:13 -07:00
Kartik Agaram a49bc41365 4531 - automatically compute segment addresses 2018-09-01 20:10:06 -07:00
Kartik Agaram 6ff9ce26e8 4530 - create an apps/ directory 2018-09-01 10:54:20 -07:00