-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
2,315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Copyright (C) 2020 Jeremiah Orians | ||
## This file is part of stage0. | ||
## | ||
## stage0 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, | ||
## 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/>. | ||
|
||
|
||
# The compiled C compiler | ||
cc_aarch64 | ||
# temp files | ||
*.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright (C) 2016 Jeremiah Orians | ||
* This file is part of stage0. | ||
* | ||
* stage0 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, | ||
* 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/>. | ||
*/ | ||
#include<stdlib.h> | ||
#include<stdio.h> | ||
#include<string.h> | ||
#include"cc.h" | ||
|
||
/* The core functions */ | ||
void initialize_types(); | ||
struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename); | ||
struct token_list* reverse_list(struct token_list* head); | ||
struct token_list* program(); | ||
void recursive_output(struct token_list* i, FILE* out); | ||
int match(char* a, char* b); | ||
void file_print(char* s, FILE* f); | ||
char* parse_string(char* string); | ||
|
||
int main() | ||
{ | ||
hold_string = calloc(MAX_STRING, sizeof(char)); | ||
FILE* in = fopen("tape_01", "r"); | ||
FILE* destination_file = fopen("tape_02", "w"); | ||
|
||
global_token = read_all_tokens(in, global_token, "tape_01"); | ||
|
||
if(NULL == global_token) | ||
{ | ||
file_print("Either no input files were given or they were empty\n", stderr); | ||
exit(EXIT_FAILURE); | ||
} | ||
global_token = reverse_list(global_token); | ||
|
||
initialize_types(); | ||
reset_hold_string(); | ||
struct token_list* output_list = program(); | ||
|
||
/* Output the program we have compiled */ | ||
file_print("\n# Core program\n", destination_file); | ||
recursive_output(output_list, destination_file); | ||
/* file_print("\n:ELF_data\n", destination_file); */ | ||
file_print("\n# Program global variables\n", destination_file); | ||
recursive_output(globals_list, destination_file); | ||
file_print("\n# Program strings\n", destination_file); | ||
recursive_output(strings_list, destination_file); | ||
file_print("\n:ELF_end\n", destination_file); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* Copyright (C) 2016 Jeremiah Orians | ||
* This file is part of stage0. | ||
* | ||
* stage0 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, | ||
* 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/>. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#define MAX_STRING 4096 | ||
// CONSTANT MAX_STRING 4096 | ||
#define FALSE 0 | ||
// CONSTANT FALSE 0 | ||
#define TRUE 1 | ||
// CONSTANT TRUE 1 | ||
|
||
void file_print(char* s, FILE* f); | ||
int match(char* a, char* b); | ||
char* copy_string(char* target, char* source); | ||
void reset_hold_string(); | ||
int in_set(int c, char* s); | ||
|
||
struct type | ||
{ | ||
struct type* next; | ||
int size; | ||
int offset; | ||
struct type* indirect; | ||
struct type* members; | ||
struct type* type; | ||
char* name; | ||
}; | ||
|
||
struct token_list | ||
{ | ||
struct token_list* next; | ||
union | ||
{ | ||
struct token_list* locals; | ||
struct token_list* prev; | ||
}; | ||
char* s; | ||
union | ||
{ | ||
struct type* type; | ||
char* filename; | ||
}; | ||
union | ||
{ | ||
struct token_list* arguments; | ||
int depth; | ||
int linenumber; | ||
}; | ||
}; | ||
|
||
/* What types we have */ | ||
struct type* global_types; | ||
struct type* prim_types; | ||
|
||
/* What we are currently working on */ | ||
struct token_list* global_token; | ||
|
||
/* Output reorder collections*/ | ||
struct token_list* strings_list; | ||
struct token_list* globals_list; | ||
|
||
/* Make our string collection more efficient */ | ||
char* hold_string; | ||
int string_index; |
Oops, something went wrong.