FPGA is new default device, fuck bf to c compiling
This commit is contained in:
parent
5b3c9a61be
commit
a4d8ea1374
|
@ -74,86 +74,6 @@ static char* intoLogisim (char* tokens) {
|
||||||
return binary;
|
return binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @name intoC
|
|
||||||
* @return static char*
|
|
||||||
* @brief Return binary as c file.
|
|
||||||
*
|
|
||||||
* @param char* tokens
|
|
||||||
*/
|
|
||||||
static char* intoC (char* tokens) {
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
char* binary = 0;
|
|
||||||
|
|
||||||
/* TODO: Change size to match C language */
|
|
||||||
/* Using c with the current memory space (256x4) has the fixed size of 533 bytes. */
|
|
||||||
int filesize = 533;
|
|
||||||
int pos = 0; /* used to navigate around binary */
|
|
||||||
|
|
||||||
/* Allocate memory for binary */
|
|
||||||
binary = (char*)malloc(sizeof(char) * filesize);
|
|
||||||
if (!binary) {
|
|
||||||
/* Error */
|
|
||||||
perror("malloc error on memory allocation of: binary");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Replace by C program */
|
|
||||||
char version_number[] = "v3.0 hex words plain";
|
|
||||||
for (int i = 0; i < 20; i++) {
|
|
||||||
binary[i] = version_number[i];
|
|
||||||
}
|
|
||||||
pos = 20; /* position after loop */
|
|
||||||
|
|
||||||
binary[pos++] = '\n';
|
|
||||||
|
|
||||||
int pos_space = pos + 1; /* save the index to fill with spaces here */
|
|
||||||
|
|
||||||
/* Loop through tokens and add matching code to binary. */
|
|
||||||
for (char* cursor = tokens; *cursor; cursor++) {
|
|
||||||
|
|
||||||
/* TODO: Replace by C thingies */
|
|
||||||
/* Switch case holds all operands. */
|
|
||||||
switch (*cursor) {
|
|
||||||
case '>': binary[pos] = '0';break;
|
|
||||||
case '<': binary[pos] = '1';break;
|
|
||||||
case '+': binary[pos] = '2';break;
|
|
||||||
case '-': binary[pos] = '3';break;
|
|
||||||
case ',': binary[pos] = '4';break;
|
|
||||||
case '.': binary[pos] = '5';break;
|
|
||||||
case '[': binary[pos] = '6';break;
|
|
||||||
case ']': binary[pos] = '7';break;
|
|
||||||
default: return (char*)EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* every second position is space or newline */
|
|
||||||
pos += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fill remaining instruction space with > operations */
|
|
||||||
for (; pos < filesize; pos += 2) {
|
|
||||||
binary[pos] = '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reset position to the first space and start filling up */
|
|
||||||
pos = pos_space;
|
|
||||||
for (; pos < filesize; pos += 2) {
|
|
||||||
/* Calculate whether to use space or newline. */
|
|
||||||
if ((pos - 20) % 64 == 0) {
|
|
||||||
binary[pos] = '\n';
|
|
||||||
} else {
|
|
||||||
binary[pos] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Finally, end the string. */
|
|
||||||
binary[filesize-1] = '\n';
|
|
||||||
|
|
||||||
return binary;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name assemble
|
* @name assemble
|
||||||
* @return char*
|
* @return char*
|
||||||
|
@ -168,8 +88,6 @@ char* assemble (char* device, char* tokens) {
|
||||||
/* supported devices are hardcoded here. */
|
/* supported devices are hardcoded here. */
|
||||||
if (!strcmp(device, "logisim")) {
|
if (!strcmp(device, "logisim")) {
|
||||||
rv = intoLogisim(tokens);
|
rv = intoLogisim(tokens);
|
||||||
} else if (!strcmp(device, "c")) {
|
|
||||||
rv = intoClang(tokens);
|
|
||||||
}else {
|
}else {
|
||||||
(void)printf("ERROR: Chosen device %s does not exist!\n", device);
|
(void)printf("ERROR: Chosen device %s does not exist!\n", device);
|
||||||
rv = (char*)EXIT_FAILURE;
|
rv = (char*)EXIT_FAILURE;
|
||||||
|
|
|
@ -20,7 +20,7 @@ int main (int argc, char** argv) {
|
||||||
|
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
char* filename;
|
char* filename;
|
||||||
char* device = "logisim";
|
char* device = "FPGA";
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (argv[i][0] == '-' && ((i+1) < argc)) {
|
if (argv[i][0] == '-' && ((i+1) < argc)) {
|
||||||
|
|
Loading…
Reference in New Issue