Release 1.0.0

This commit is contained in:
Jeremiah Orians 2018-08-26 16:34:31 -04:00
parent 951d259339
commit e249069cac
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
13 changed files with 9135 additions and 10404 deletions

View File

@ -30,10 +30,20 @@ Reordered conditionals for easier implementation and reduced operations
Broke out OUT and FUNCTION to silence a single GCC warning
Moved required_match and line_error into cc_core.c and removed required_match.c
Relocated contents of test/functions to functions
Upgrades mescc-tools to 40537c0200ad28cd5090bc0776251d5983ef56e3 commit
Tweaked order for for, while and do loops to make them more in commone
Tweaked source to better match assembly
Simplify implementation order of logic
Simplifed the promote_type logic to a much breifer form
Broke out generally useful member lookup
Upgraded seed.M1 to be generated by cc_x86
** Fixed
Fixed detection of locals to screen out all non-primitive name space collisions
Checked in updated gcc function definition
Changed's numerate_number's behavior related to zeros
Improved error message to help debugging
Fixed bootstrap.sh to build a working M2-Planet binary
** Removed
Removed redundent steps in Recursive statement

View File

@ -4,16 +4,21 @@ set -ex
# Make the required bin directry
[ -d bin ] || mkdir bin
# Build debug footer
blood-elf -f seed.M1 \
-o bin/seed-footer.M1 || exit 1
# Macro assemble with libc written in M1-Macro
M1 -f test/common_x86/x86_defs.M1 \
-f test/functions/libc-core.M1 \
-f functions/libc-core.M1 \
-f seed.M1 \
-f bin/seed-footer.M1 \
--LittleEndian \
--Architecture 1 \
-o bin/seed.hex2 || exit 1
-o bin/seed.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_x86/ELF-i386.hex2 \
hex2 -f test/common_x86/ELF-i386-debug.hex2 \
-f bin/seed.hex2 \
--LittleEndian \
--Architecture 1 \

112
cc_core.c
View File

@ -305,36 +305,24 @@ void primary_expr_variable()
void primary_expr();
struct type* promote_type(struct type* a, struct type* b)
{
if(NULL == a)
{
return b;
}
if(NULL == b)
{
return a;
}
if(NULL == a)
{
return b;
}
struct type* i;
for(i = global_types; NULL != i; i = i->next)
{
if(a->name == i->name)
{
return a;
}
if(b->name == i->name)
{
return b;
}
if(a->name == i->indirect->name)
{
return a;
}
if(b->name == i->indirect->name)
{
return b;
}
if(a->name == i->name) break;
if(b->name == i->name) break;
if(a->name == i->indirect->name) break;
if(b->name == i->indirect->name) break;
}
return NULL;
return i;
}
void common_recursion(FUNCTION f)
@ -381,26 +369,16 @@ int ceil_log2(int a)
* postfix-expr ( expression-list-opt )
* postfix-expr -> member
*/
struct type* lookup_member(struct type* parent, char* name);
void postfix_expr_arrow()
{
emit_out("# looking up offset\n");
global_token = global_token->next;
struct type* i;
for(i = current_target->members; NULL != i; i = i->members)
{
if(match(i->name, global_token->s)) break;
}
if(NULL == i)
{
file_print("ERROR in postfix_expr ", stderr);
file_print(current_target->name, stderr);
file_print("->", stderr);
file_print(global_token->s, stderr);
file_print(" does not exist\n", stderr);
line_error();
exit(EXIT_FAILURE);
}
struct type* i = lookup_member(current_target, global_token->s);
current_target = i->type;
global_token = global_token->next;
if(0 != i->offset)
{
emit_out("# -> offset calculation\n");
@ -408,12 +386,11 @@ void postfix_expr_arrow()
emit_out(numerate_number(i->offset));
emit_out("\nADD_ebx_to_eax\n");
}
if(!match("=", global_token->next->s) && !match("char**",i->type->name))
if(!match("=", global_token->s) && !match("char**", current_target->name))
{
emit_out("LOAD_INTEGER\n");
}
current_target = i->type;
global_token = global_token->next;
}
void postfix_expr_array()
@ -421,19 +398,18 @@ void postfix_expr_array()
struct type* array = current_target;
common_recursion(expression);
current_target = array;
char* assign;
char* assign = "LOAD_INTEGER\n";
/* Add support for Ints */
if(!match("char*", current_target->name))
if(match("char*", current_target->name))
{
assign = "LOAD_BYTE\n";
}
else
{
emit_out("SAL_eax_Immediate8 !");
emit_out(numerate_number(ceil_log2(current_target->indirect->size)));
emit_out("\n");
assign = "LOAD_INTEGER\n";
}
else
{
assign = "LOAD_BYTE\n";
}
emit_out("ADD_ebx_to_eax\n");
@ -704,17 +680,18 @@ void process_if()
void process_for()
{
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
struct token_list* nested_locals = break_frame;
char* nested_break_head = break_target_head;
char* nested_break_func = break_target_func;
char* nested_break_num = break_target_num;
struct token_list* nested_locals = break_frame;
break_frame = function->locals;
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
break_target_head = "FOR_END_";
break_target_func = function->s;
break_target_num = number_string;
break_frame = function->locals;
break_target_func = function->s;
emit_out("# FOR_initialization_");
uniqueID_out(function->s, number_string);
@ -780,17 +757,18 @@ void process_asm()
/* Process do while loops */
void process_do()
{
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
struct token_list* nested_locals = break_frame;
char* nested_break_head = break_target_head;
char* nested_break_func = break_target_func;
char* nested_break_num = break_target_num;
struct token_list* nested_locals = break_frame;
break_frame = function->locals;
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
break_target_head = "DO_END_";
break_target_func = function->s;
break_target_num = number_string;
break_frame = function->locals;
break_target_func = function->s;
emit_out(":DO_");
uniqueID_out(function->s, number_string);
@ -819,18 +797,18 @@ void process_do()
/* Process while loops */
void process_while()
{
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
struct token_list* nested_locals = break_frame;
char* nested_break_head = break_target_head;
char* nested_break_func = break_target_func;
char* nested_break_num = break_target_num;
struct token_list* nested_locals = break_frame;
break_frame = function->locals;
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
break_target_head = "END_WHILE_";
break_target_func = function->s;
break_target_num = number_string;
break_frame = function->locals;
break_target_func = function->s;
emit_out(":WHILE_");
uniqueID_out(function->s, number_string);
@ -852,10 +830,10 @@ void process_while()
emit_out(":END_WHILE_");
uniqueID_out(function->s, number_string);
break_frame = nested_locals;
break_target_head = nested_break_head;
break_target_func = nested_break_func;
break_target_num = nested_break_num;
break_frame = nested_locals;
}
/* Ensure that functions return */
@ -896,7 +874,7 @@ void process_break()
emit_out("_");
emit_out(break_target_num);
emit_out("\n");
require_match("ERROR in statement\nMissing ;\n", ";");
require_match("ERROR in break statement\nMissing ;\n", ";");
}
void recursive_statement()

View File

@ -109,6 +109,24 @@ struct type* lookup_type(char* s, struct type* start)
return NULL;
}
struct type* lookup_member(struct type* parent, char* name)
{
struct type* i;
for(i = parent->members; NULL != i; i = i->members)
{
if(match(i->name, name)) return i;
}
file_print("ERROR in lookup_member ", stderr);
file_print(parent->name, stderr);
file_print("->", stderr);
file_print(global_token->s, stderr);
file_print(" does not exist\n", stderr);
line_error();
file_print("\n", stderr);
exit(EXIT_FAILURE);
}
struct type* type_name();
void require_match(char* message, char* required);

View File

@ -31,7 +31,6 @@ char* numerate_number(int a)
if(0 == a)
{
result[0] = '0';
result[1] = 10;
return result;
}

19309
seed.M1

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ b45fae655b7f848b28ebdb8eb2e30ae789fbcf7920bc315395d53986bb1adae4 test/results/t
d511db73158a9544a5b5f828a79751e3de8a04b81c143fd0c146fc22c938aa9f test/results/test08-binary
907e1808f2e2b15ac72ebf13898b15c678e68ebd43d673dcd0f408d907e7962f test/results/test09-binary
ef179cd359ba1d61d45089e314cd4ac2069c8dc4dd7494d7c766344ea3c8cf88 test/results/test10-binary
bf1d76df4d3e701c420e031910ca0da3f390fb3b6d198a0b93349bdbc285adb7 test/results/test100-binary
cefac04111bd46b335b6ebf995c07989920fbdbb3eb07e0b29fb7d62dcc70cfe test/results/test100-binary
5aaf399fe706d4a8c85c121c75ada29a65c293b57c98e8999961a2ef0bab0d62 test/results/test11-binary
4f8111e73e07255ae203963438c82ea8bcff7474e1594b52b426c58a03cb30eb test/results/test12-binary
dd74dabfdce8657ff440c1eef531cbf67a64854f2020d4d6bcb65c9cc2d199cb test/results/test13-binary
@ -18,10 +18,10 @@ e216869c3fb06de7a41578517c797169e219b20a5697a822ba11eeef0d04f181 test/results/t
315ae5cc5c9d5bdcae0eddd55371128e53e3e9267a2a7c53832ed0af51693bea test/results/test16-binary
fdce9856f885418a7b2f69fc24a6cc0c85922313b49694d8030c544e4b2ad16f test/results/test17-binary
9a426972b6df90a158aebe3b8f3eb9ef8a63ce317d764afb92be4fce16542743 test/results/test18-binary
8459b95fb7232f6c0d9c2af94be061d7a14f39659767486af51d5b76e818824e test/results/test19-binary
91b761d241dd9969230b235c6cb3bc86cc6b0076d9d1a04c4950de32228149f5 test/results/test19-binary
48d845d20fff86183047342641cc8a6174e71c0ca004be882f0195a141bd64ea test/results/test20-binary
65354ea5f760e42ea054785033a6519e0eee30d21b1b69ac7715ef958c5e0e2f test/results/test21-binary
dffc0dbe1d99fd156ab406d0b71ce48e6d91072f75b8103a208510293e37735a test/results/test22-binary
c745adaa7c5ba2230877fc8d2137a87d25597212069660813460cb6d764de2a0 test/results/test23-binary
9a79bdfb35c1c17bb0c66357836382bb08d3876ae8c0c77356776d16aa7faa7f test/results/test22-binary
96e1789254675815a3ec5ad93c1cc32c4805d1ad7f029721cef102c4501df8e2 test/results/test23-binary
50215e4b4e2ce22a959ea7bcfc77c4d6ac45464455f5103afcaea0e84f9bf1d1 test/results/test24-binary
0013b8786068520e386a0cf2ce39c5145462439f17c264e62a9eddb1eed0433b test/results/test99-binary

View File

@ -17,6 +17,7 @@ then
-f cc_types.c \
-f cc_core.c \
-f cc.c \
--debug \
-o test/test100/cc.M1 || exit 1
else
./bin/M2-Planet-gcc -f functions/file.c \
@ -33,19 +34,30 @@ else
-f cc_types.c \
-f cc_core.c \
-f cc.c \
--debug \
-o test/test100/cc.M1 || exit 1
fi
# Build debug footer
blood-elf -f test/test100/cc.M1 \
-o test/test100/cc-footer.M1 || exit 2
# Macro assemble with libc written in M1-Macro
M1 -f test/common_x86/x86_defs.M1 \
-f functions/libc-core.M1 \
-f test/test100/cc.M1 \
-f test/test100/cc-footer.M1 \
--LittleEndian \
--Architecture 1 \
-o test/test100/cc.hex2 || exit 2
-o test/test100/cc.hex2 || exit 3
# Resolve all linkages
hex2 -f test/common_x86/ELF-i386.hex2 -f test/test100/cc.hex2 --LittleEndian --Architecture 1 --BaseAddress 0x8048000 -o test/results/test100-binary --exec_enable || exit 3
hex2 -f test/common_x86/ELF-i386-debug.hex2 \
-f test/test100/cc.hex2 \
--LittleEndian \
--Architecture 1 \
--BaseAddress 0x8048000 \
-o test/results/test100-binary --exec_enable || exit 4
# Ensure binary works if host machine supports test
if [ "$(get_machine)" = "x86_64" ]
@ -65,10 +77,10 @@ then
-f cc_types.c \
-f cc_core.c \
-f cc.c \
-o test/test100/proof || exit 4
-o test/test100/proof || exit 5
out=$(sha256sum -c test/test100/proof.answer)
[ "$out" = "test/test100/proof: OK" ] || exit 5
[ "$out" = "test/test100/proof: OK" ] || exit 6
[ ! -e bin/M2-Planet ] && mv test/results/test100-binary bin/M2-Planet
else
cp bin/M2-Planet-gcc bin/M2-Planet

View File

@ -1 +1 @@
3243a9d889030bcdb2d8f7dfde62c41a3d5bd2bdf944328c2eccf1d9a3a7592e test/test100/proof
4715ce02b077c7487b9d131b5581e662f3c15360bd70371b490bf4563193b9bd test/test100/proof

View File

@ -1,20 +1,20 @@
/* -*- c-file-style: "linux";indent-tabs-mode:t -*- */
/* Copyright (C) 2017 Jeremiah Orians
* Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
* This file is part of MES
* This file is part of mescc-tools
*
* MES is free software: you can redistribute it and/or modify
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MES is distributed in the hope that it will be useful,
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with stage0. If not, see <http://www.gnu.org/licenses/>.
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>

View File

@ -1,20 +1,20 @@
/* -*- c-file-style: "linux";indent-tabs-mode:t -*- */
/* Copyright (C) 2017 Jeremiah Orians
* Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
* This file is part of MES
* This file is part of mescc-tools
*
* MES is free software: you can redistribute it and/or modify
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MES is distributed in the hope that it will be useful,
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with stage0. If not, see <http://www.gnu.org/licenses/>.
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
@ -179,6 +179,7 @@ int Architectural_displacement(int target, int base)
if(0 == Architecture) return (target - base);
else if(1 == Architecture) return (target - base);
else if(2 == Architecture) return (target - base);
else if(40 == Architecture) return (target - base);
file_print("Unknown Architecture, aborting before harm is done\n", stderr);
exit(EXIT_FAILURE);
@ -221,7 +222,11 @@ void storePointer(char ch, FILE* source_file)
displacement = Architectural_displacement(target, base);
/* output calculated difference */
if(33 == ch) outputPointer(displacement, 1); /* Deal with ! */
if(33 == ch)
{
if(40 == Architecture) outputPointer(displacement - 7, 1); /* Deal with ! */
else outputPointer(displacement, 1); /* Deal with ! */
}
else if(36 == ch) outputPointer(target, 2); /* Deal with $ */
else if(64 == ch) outputPointer(displacement, 2); /* Deal with @ */
else if(38 == ch) outputPointer(target, 4); /* Deal with & */
@ -457,7 +462,8 @@ int main(int argc, char **argv)
file_print(argv[0], stderr);
file_print(" -f FILENAME1 {-f FILENAME2} (--BigEndian|--LittleEndian)", stderr);
file_print(" [--BaseAddress 12345] [--Architecture 12345]\nArchitecture", stderr);
file_print(" 0: Knight; 1: x86; 2: AMD64\nTo leverage octal or binary", stderr);
file_print(" 0: Knight; 1: x86; 2: AMD64; 40: armv7", stderr);
file_print("\nTo leverage octal or binary", stderr);
file_print(" input: --octal, --binary\n", stderr);
exit(EXIT_SUCCESS);
}

View File

@ -1,20 +1,20 @@
/* -*- c-file-style: "linux";indent-tabs-mode:t -*- */
/* Copyright (C) 2016 Jeremiah Orians
* Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
* This file is part of stage0.
* This file is part of mescc-tools.
*
* stage0 is free software: you can redistribute it and/or modify
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* stage0 is distributed in the hope that it will be useful,
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with stage0. If not, see <http://www.gnu.org/licenses/>.
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
@ -478,7 +478,7 @@ void eval_immediates(struct Token* p)
if((NULL == i->Expression) && !(i->type & MACRO))
{
int value;
if((1 == Architecture) || (2 == Architecture))
if((1 == Architecture) || (2 == Architecture) || (40 == Architecture))
{
value = numerate_string(i->Text + 1);
if(('0' == i->Text[1]) || (0 != value))
@ -559,7 +559,8 @@ int main(int argc, char **argv)
{
file_print("Usage: ", stderr);
file_print(argv[0], stderr);
file_print(" -f FILENAME1 {-f FILENAME2} (--BigEndian|--LittleEndian) [--BaseAddress 12345] [--Architecture 12345]\nArchitecture 0: Knight; 1: x86; 2: AMD64", stderr);
file_print(" -f FILENAME1 {-f FILENAME2} (--BigEndian|--LittleEndian) ", stderr);
file_print("[--Architecture 12345]\nArchitecture 0: Knight; 1: x86; 2: AMD64; 40: armv7", stderr);
exit(EXIT_SUCCESS);
}
else if(match(argv[option_index], "-f") || match(argv[option_index], "--file"))

View File

@ -1,19 +1,19 @@
/* -*- c-file-style: "linux";indent-tabs-mode:t -*- */
/* Copyright (C) 2017 Jeremiah Orians
* This file is part of stage0.
* This file is part of mescc-tools.
*
* stage0 is free software: you can redistribute it and/or modify
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* stage0 is distributed in the hope that it will be useful,
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with stage0. If not, see <http://www.gnu.org/licenses/>.
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
@ -21,7 +21,6 @@
#include <stdlib.h>
#include <sys/utsname.h>
void file_print(char* s, FILE* f);
char* numerate_number(int a);
/* Standard C main program */
int main()