Commit Graph

115 Commits

Author SHA1 Message Date
Jack Palevich ba48fe2f4e Fix memory deallocation bug in toy vector class.
Yet another reason to use standard collection classes. :-)
2009-11-27 11:51:36 +08:00
Jack Palevich 13edb721c0 am 556c60f4: am 51da51a2: am 02effee6: Correctly compute the type of an assignment expression.
Merge commit '556c60f4f27e2a3bfde6a47acf876716ea8d5795'

* commit '556c60f4f27e2a3bfde6a47acf876716ea8d5795':
  Correctly compute the type of an assignment expression.
2009-11-09 16:28:51 -08:00
Jack Palevich 02effee6a9 Correctly compute the type of an assignment expression.
This change enables following types of statements to work correctly:

    a = b = 3;
    if ((a = getchar()) < 0) { ... }

This fixes 2232082 acc: assignment in comparison segfaults
2009-11-09 12:52:45 +08:00
Jack Palevich 46f2bd2080 Fix type bug that breaks 64-bit OSX build. 2009-10-29 17:56:56 -07:00
Jack Palevich c951c59232 Add support for the continue statement
Add error check for a break statement that's not inside a loop. (We just
generated bad code before. Oops!)
2009-10-29 15:04:27 -07:00
Jack Palevich ee1f829dd4 Implement typedef. 2009-10-28 16:10:17 -07:00
Jack Palevich 188a5a7a3a Support nested macros. (Still don't support macro arguments.)
Now you can say:

    #define A B
    #define B C
    #define C 4

int x = A;

And it will work as expected.

Print an error message rather than assert when we're expecting a
function value, but don't find one.
2009-10-27 17:23:20 -07:00
Jack Palevich b13d4e857a Improve error-handling when an expected token is missing.
We had been arbitrarily swallowing the next token, even if it wasn't
the one we were expecting. Now we only swallow it if it _is_ the one
we were expecting.
2009-09-18 16:26:05 -07:00
Jack Palevich 1c60e46e0e Produce error rather than assert when encountering a nested function.
Remove extra '\n' characters from error messages.

Dynamically allocate error message buffer.
2009-09-18 15:03:03 -07:00
Jack Palevich 53f0658792 Update peephole optimizer
+ Save one instruction for loads of local byte or float values.
+ Save two instructions for pointer arithmetic with a stride that
  is a power of two.
2009-09-10 14:01:58 -07:00
Jack Palevich d30a2ce244 Implement a simple peephole optimization framework for ARM.
Implement some optimizations:

+ performing arithmetic by a small constant is 3 instructions shorter.
+ reading a local variables is 1 instruction shorter.
+ constant array indexing (e.g. p[5]) is 5 instructions shorter.
2009-09-09 19:08:54 -07:00
Jack Palevich d5315573d7 Move ARM disassembler out of libacc and into the acc command-line tool. 2009-09-09 13:19:34 -07:00
Jack Palevich c408bbf4a7 Turn an assert into an error to handle bad struct members more gracefully. 2009-09-08 12:07:32 -07:00
Jack Palevich 9116bc4c18 Improved DEBUG_SAVE_INPUT_TO_FILE logic. 2009-09-08 11:46:42 -07:00
Jack Palevich 61de31feff Generate an error for the use of an undeclared struct. 2009-09-08 11:06:40 -07:00
Jack Palevich 8fe5dcac34 Improve error message for unknown struct members
We now customize the error message to correctly refer to the '.' or
'->' operator , whichever one is actually being used when the error
occurs.
2009-09-04 15:34:21 -07:00
Jack Palevich 5fd66ae01e Improve address operator (unary &).
Until now the address operator only worked with simple variables.
Now it works with arbitrary expressions (that are lvalues or function
names). So for example this now works:

struct S { int a[10]};

int f(struct S* p) {
    return &p->a[3];
}
2009-09-04 15:24:23 -07:00
Joe Onorato ecfd8e73e4 acc error tweaks 2009-08-28 09:26:31 -07:00
Jack Palevich 9221bcccb3 Preliminary struct and union support.
Working features:
 - struct
 - union
 - nested structs
 - anonymous structs
 - forward declarations
 - '.' and '->'
 - copying structs using '='

Missing features:
 - passing structs by value
 - returning structs by value
 - typedef
 - sizeof

Example:

struct v {float x, y, z, w; };

void add(struct v* result, struct v* a, struct v* b) {
    result->x = a->x + b->x;
    result->y = a->y + b->y;
    result->z = a->z + b->z;
    result->w = a->w + b->w;
}

Reworked size-of and alignment logic to support structs.

Improved encoding of ARM immediate constants.
2009-08-26 16:15:07 -07:00
Jack Palevich c0f253359f Make pointer casting work. 2009-08-25 12:23:43 -07:00
Jack Palevich 30321cb3f3 Add ARM hardware floating point support. 2009-08-20 15:34:23 -07:00
Jack Palevich 0a01a5db56 Handle functions with anonymous arguments
Example:

int f(int a, int, int c) {
    return a + c;
}
2009-08-19 10:53:43 -07:00
Jack Palevich 815d8b8fdb Allow redefinition of macros.
Example:

#define A 3
#define A 4

This used to do strange things, but now works as it should.
2009-08-18 18:25:56 -07:00
Jack Palevich 0b1827a5b2 Allow '//'-style comments in #defines. 2009-08-18 17:44:12 -07:00
Jack Palevich 0b2de0de64 Allow parenthesized expressions as the value of defines
For example, this now works:

#define A (1 + 2)

Note that we still don't support defines with argument lists, so this is
still illegal:

#define A(X) (X + 2)

Also in this change: The compiler test script allows command-line
arguments to disable testing on ARM and to disable testing the output
of the old OTCC compiler.

Disabling testing on ARM is handy for developing front-end code when no
device or emulator is available.

Disabling testing OTCC output is handy for some 64-bit Linux environments,
because the original OTCC needs some tweaking to be fully compatible, and
I don't have time to investigate this problem right now.
2009-08-18 16:04:03 -07:00
Jack Palevich 7f5b1a2b31 do not merge: cherry-picked ecd23c09e8 from master branch 2009-08-17 16:54:56 -07:00
Jack Palevich 80e4972625 Support 2D arrays. 2009-08-04 15:39:49 -07:00
Jack Palevich b61545096d Implement arrays.
Added check to see that pointer types are compatible when passing function
arguments.
2009-08-04 14:56:09 -07:00
Jack Palevich c9b8ffc389 Add support for "short" data type. 2009-08-03 14:42:57 -07:00
Jack Palevich 96138992ac Fix parsing of function declarations that return pointers.
Check that <op>= only evaluates the left-hand-side once.
2009-07-31 15:58:19 -07:00
Jack Palevich 47cbea9c69 Support brackets for accessing array values.
Don't yet support allocating arrays.
2009-07-31 15:25:53 -07:00
Jack Palevich 5b65909f93 Clean up the way we handle postfix operators.
Function names are now treated just like any other variable.
2009-07-31 14:55:07 -07:00
Jack Palevich aaac9284b4 Implement pre-increment / pre-decrement 2009-07-31 14:34:34 -07:00
Jack Palevich 43aaee31b9 Support the comma operator. 2009-07-31 14:01:37 -07:00
Jack Palevich 0c01774816 Implement op=. 2009-07-31 12:00:39 -07:00
Jack Palevich 29daf577a1 Assignment in ordinary expressions is now handled using lvals and rvals. 2009-07-30 19:38:55 -07:00
Jack Palevich b5e3331159 Start using lvals and rvals. 2009-07-30 19:06:34 -07:00
Jack Palevich 8968e8e115 Change assignment code gen to use leaR0 .. storeR0ToTOS.
This is another step towards being able to handle lval / rvals.

Improved storeR0ToTOS to convert R0 to the proper type to store into
*TOS. (This is something that storeR0 was already doing.)

Removed storeR0 as it is no longer being used.
2009-07-30 16:57:33 -07:00
Jack Palevich 8f361faffc Fix bad ARM code generation for '||' and '&&' operators.
Add tests of '&', '&&', '|' and '||' operators.
2009-07-30 16:19:43 -07:00
Jack Palevich 9f51a26961 Load function symbols using lea syntax.
Use a common code path for ordinary, forward, and indirect calls.
2009-07-29 16:22:26 -07:00
Jack Palevich a7813bda4a Remove loadR0 in favor of lea + loadR0FromR0.
(This is another small step towards lval/rval.)

+ Use strd to store local doubles.
+ loadR0FromR0 now handles pointers.
2009-07-29 11:36:04 -07:00
Jack Palevich ddf7c9c141 Implement inc/dec in a more lval-friendly way. 2009-07-29 10:28:18 -07:00
Jack Palevich 7fcdf1c5f8 Adjust stack alignment for local variables to work more like arguments.
This makes it easier to generate frame-pointer-relative addresses for ARM.

Prior to this we had stored char sized local variables in the highest
address of the 4-byte stack allocation. Now we store "char"s in the
lowest address of the 4-byte stack allocation, just like chars are
passed as arguments.

We now store global chars on byte boundaries.
2009-07-27 17:54:10 -07:00
Jack Palevich 2ff5c22e96 Keep track of the current arena.
This means we don't have to pass it around as an argument.

This change was made because I'm about to start creating pointer types
during expression evaluation, and I didn't want to add an arena
argument to all the expression functions.
2009-07-23 15:11:22 -07:00
Jack Palevich 89baa2083f Fix the ARM postdecrement operator.
Add a test for ++ and -- so this bug won't happen again.
2009-07-23 11:45:15 -07:00
Jack Palevich 58c30eef99 Code generator cleanup
Factor ARM integer binary operation setup code into a function.

Don't pass redundant pType information into loadR0FromR0, storeR0ToTOS,
gcmp, gUnaryCmp, li

Separate inc/dec from variable loading. Generates worse code, but now
we handle pointer inc/dec and char inc/dec.
2009-07-17 16:35:23 -07:00
Jack Palevich b40367bde1 Remove unused logging code. 2009-07-17 13:51:51 -07:00
Jack Palevich ba929a4ffa Track lvalues vs. rvalues. 2009-07-17 10:20:32 -07:00
Jack Palevich 3377bfd845 Report error (rather than crashing) when a declaration name is missing.
Repo case:

void main()
{
   int );
}
2009-07-16 19:05:07 -07:00
Jack Palevich 8148c5be54 Coerce R0 to destination type before storing it into a variable. 2009-07-16 18:24:47 -07:00