Commit graph

95 commits

Author SHA1 Message Date
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
Jack Palevich
dc45646238 Implement a "#line" directive. 2009-07-16 16:50:56 -07:00
Jack Palevich
b1544cad42 Detect assignments to undeclared variables.
Previously we only detected reading from undefined variables.
2009-07-16 15:09:20 -07:00
Jack Palevich
ce105a9082 If the compile failed, return NULL from symbol lookups. 2009-07-16 14:30:33 -07:00
Jack Palevich
d1f57e689b Improve error handling
Don't segfault if the right-hand operand of a binary operator is missing.
Don't segfault if a semicolon is missing at the end of a forward
declaration.
2009-07-15 18:23:22 -07:00
Jack Palevich
2aaf21f1be Improve numerical constant parsing. 2009-07-15 16:16:37 -07:00
Jack Palevich
8c246a9dc2 Add accRegisterSymbolCallback API to control external symbol linkage.
Until now dlsym was used to lookup external symbols. Now you can
register your own function to be called when an undefined symbol is
used.
2009-07-14 21:14:10 -07:00
Jack Palevich
37c54bd22e Make forward declarations of external symbols really work.
Until now we had always been treating external variables as "int",
and external functions as int (...);
2009-07-14 18:35:36 -07:00
Jack Palevich
7ecc5556ae Remove unused variable. 2009-07-14 16:24:55 -07:00
Jack Palevich
a8f427f606 Implement pointer arithmetic. 2009-07-13 18:40:08 -07:00
Jack Palevich
25c0ccaed4 Implement support for "char" local and global variables. 2009-07-13 16:56:28 -07:00
Jack Palevich
45431bc252 Implement general casts and pointer dereferencing.
Prior to this casts and pointer dereferencing were special-cased.
2009-07-13 15:57:26 -07:00
Jack Palevich
b7718b973c Implement floating point for ARM. 2009-07-09 22:00:24 -07:00
Jack Palevich
bab8064203 Add x86 floating point test. 2009-07-09 13:54:54 -07:00
Jack Palevich
2a4e1a9f88 Finish implementing x86 floating point
Support floating-point if/while statements: if(1.0) { ... }
Support reading values from float and double pointers.

And some additional error checking.
Detect malformed "return" statements
Detect passing the results of "void" functions as arguments.
2009-07-09 13:34:25 -07:00
Jack Palevich
a39749f641 Implement x86 floating point operations
+ unary floating point operation -
 + unary floating point compare: !
 + binary floating point operations +-*/
 + binary floating point comparisons: < <= == != >= >
2009-07-08 20:40:31 -07:00
Marco Nelissen
eea5ae9ceb Class with virtual methods should have virtual destructors too. 2009-07-08 17:43:17 -07:00
Jack Palevich
9cbd226960 Implement global, local, and stack based float and double variables. 2009-07-08 16:48:41 -07:00
Jack Palevich
128ad2d204 Implement x86 int <--> float. 2009-07-08 14:51:31 -07:00
Jack Palevich
1a539db23c Some x86 floating point code works.
We now check the types and number of arguments to a function.
2009-07-08 13:04:41 -07:00
Jack Palevich
8df4619e09 Start tracking types in expressions. 2009-07-07 14:48:51 -07:00