Commit Graph

36 Commits

Author SHA1 Message Date
Jack Palevich f1f39cca30 Make sure we don't overflow various internal compiler buffers.
We may replace some of these tables with dynamically growing data
structures, but in the meantime we will not trash memory.
2009-05-29 18:03:15 -07:00
Jack Palevich ac0e95eb60 Improve ACC error reporting.
Now return an error code and an error message, rather than just
printing to stderr or calling exit().

Check to see we don't exceed our code size.
2009-05-29 13:53:44 -07:00
Jack Palevich 653f42da92 Pointer-ize the acc front end.
The ACC compiler used to be able to compile itself. This was a neat
feature, but because ACC only supports ints, pointers are stored as
ints, and cast to pointers when used.

This checkin turns many ints that are really pointers back into
pointers, so that the code is clearer.

 int ch;
 char* glo;
 char* sym_stack;
 char* dstk;
 char* dptr;
 int dch;
 char* last_id;
2009-05-29 09:32:14 -07:00
Jack Palevich 09555c7a18 Fix symbol lookup logic, squelch LOG output. 2009-05-27 12:25:55 -07:00
Jack Palevich 1cdef20774 Convert libacc into a shared library.
Document internal CodeGenerator interface

Move license to a separate license file.

Define a public API for calling libacc.

Update the "acc" test program to use the public API.
Move "main.cpp" and test scripts into the tests subdirectory.
Move test data from tests to tests/data
Remove stale test data.
2009-05-22 12:09:55 -07:00
Jack Palevich 8b0624c3d3 Fix x64 int / pointer warnings. 2009-05-20 12:12:06 -07:00
Jack Palevich e7b590666d Implement architecture-dependent defaults.
If libacc is built on x86, then x86 is the default code generator.
If libacc is built on arm. then ARM is the default code generator
And so on for future architectures.

The 64-bit x64 machine has no working code generator currently.
We may add one to support the simulator builds.

Improved the test program so we don't try to run tests if the
compile failed. Also avoid running tests that don't work on
a given platform.
2009-05-20 11:27:04 -07:00
Jack Palevich 274663bf67 Add a test script for testing the libacc compiler on ARM. 2009-05-19 14:07:41 -07:00
Jack Palevich 3d474a74a7 ACC ARM codegen: implement /, % 2009-05-15 15:12:38 -07:00
Jack Palevich 7810bc9abd ACC ARM codegen: Implement calling indirect functions. 2009-05-15 14:31:47 -07:00
Jack Palevich 4d93f30bef ACC ARM code gen: Implement global variables.
Collapsed the inc/dec codegen into the loadEAX function, because it
allows us to generate better code for inc/dec'ing a global variable
on ARM, because we don't have to load the variable's address twice.
2009-05-15 13:30:00 -07:00
Jack Palevich 9918d0a2ee Add license, document language changes. 2009-05-15 11:01:21 -07:00
Jack Palevich bd894904f7 ACC: Arm code gen improvements ++/--, &, odds and ends
Added C++-style "//..end-of-line" comments, since I kept trying to use them when writing
test programs.

The biggest known missing piece is global variables.
2009-05-14 19:35:31 -07:00
Jack Palevich 8de461dc9e Implement <, >, ==, !=, >= <=, &&, and ||. 2009-05-14 17:21:45 -07:00
Jack Palevich 69796b6c84 ACC ARM code gen: Implement local variables, function args
+ Fix prolog and epilog code.
2009-05-14 16:43:18 -07:00
Jack Palevich cb1c9ef38c ACC ARM code gen improvements. printf("Hello, world\n"); works!
+ Improved li to handle all 32-bit values.
+ Implemented push/pop of temp registers during evaluation
+ Implemented the unary and binary easy math operators (+,-,*,<<,>>,|,&,^,~)
+ Implemented global function calling.
2009-05-14 14:27:06 -07:00
Jack Palevich a653561097 ARM codegen: Add disassembler, implement return
This program works:

    main() { return 42; }

The disassembler was borrowed from codeflinger, and just modified enough to compile
under C++ without warnings.

Implemented gsym
Implemented a hack verison of li, only works for -256..255
Implemented gjmp
2009-05-13 19:51:03 -07:00
Jack Palevich 546b2249ef Begin filling in ARM code generator.
We can now call functions that have no arguments (and return from them too!)
2009-05-13 15:10:04 -07:00
Jack Palevich 2230513fc0 Add stub Arm code generator. 2009-05-13 10:58:45 -07:00
Jack Palevich bf42c9c163 Move all x86-specific knowlege into the X86CodeGenerator. 2009-05-12 13:46:16 -07:00
Jack Palevich 21a15a2416 Various C++ improvements
+ Changed indentation, causes the stats to say there's a lot of lines changed.
+ Should be able to compile multiple times with the same compiler object.
+ Create a CodeBuffer class to hold the code.
+ Create a CodeGenerator class to encapsulate knowlege of the CPU instruction set.
+ Started filling in the code generator.
2009-05-11 18:49:27 -07:00
Frabrice Bellard a96930572c Document acc language features.
Original text from http://www.ioccc.org/2001/bellard.hint
2009-05-11 14:51:47 -07:00
Jack Palevich bbf8ab504a Added command-line option "-t" to allow run-time switching between running and dumping.
Fixed some C++ warnings reported by g++ .
Verified that the compiler actually works when run on 32-bit Linux.
2009-05-11 11:54:30 -07:00
Jack Palevich 77ae76eea9 converted to C++
Base address of constant table changed, so had to update the "-orig" files.
2009-05-10 19:59:24 -07:00
Jack Palevich f6b5a531d8 Remove all gcc warnings. 2009-05-10 19:16:42 -07:00
Jack Palevich e27bf3eb29 Replace acc.c with the contents of otccn.c, update tests.
We are no longer checking if the constant data is the same, just the
generated code.
2009-05-10 14:09:03 -07:00
Fabrice Bellard 16134598fb Original version of otccn.c from http://bellard.org/otcc/otccn.c 2009-05-10 14:01:59 -07:00
Jack Palevich 431055cc9b More deobfuscation. 2009-05-08 20:30:47 -07:00
Jack Palevich 7448a2ebb7 Converted code constants from decimal to hexidecimal. 2009-05-08 20:30:47 -07:00
Jack Palevich f0cbc92fc0 More unobfuscation. 2009-05-08 20:30:47 -07:00
Jack Palevich 50791f5466 Make our global variables static. 2009-05-08 20:30:47 -07:00
Jack Palevich d160530a58 Got rid of all warnings. (Yeah, right.) 2009-05-08 20:30:47 -07:00
Jack Palevich f54db02e5d Add a simple regression test framework. 2009-05-08 20:30:47 -07:00
Jack Palevich ae54f1fba8 Continue deobfuscation.
Add a license.

Indent the code.
Add includes for external functions.
Improve function prototypes.
Start adding the correct type to things that are pointers.
Start fixing compiler warnings.

Instead of directly executing the compiled code (which only works on x86 Linux),
write the internal compiler state to stdout. This makes it easier to test whether
or not our refactoring is breaking anything.

Return a zero status on success.

Add error checking for a missing input file.
2009-05-08 20:30:47 -07:00
Jack Palevich 883114867a Start de-obfuscation process. 2009-05-08 20:30:47 -07:00
Fabrice Bellard 38aa39a200 Original freeware Obfuscated Tiny C Compiler.
From http://bellard.org/otcc/otcc.c

License from http://bellard.org/otcc:

The obfuscated OTCC and OTCCELF are freeware.
2009-05-08 20:30:47 -07:00