59 lines
1.4 KiB
C
59 lines
1.4 KiB
C
#include "header.h"
|
|
#include <ccompiler/ccompiler.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char** argv) {
|
|
// gcc rv32ima_codegen.c -o rv32gen.exe
|
|
init_lib_core();
|
|
log_set_level(NULL, LOG_LEVEL_ERROR | LOG_LEVEL_WARN | LOG_LEVEL_FATAL);
|
|
|
|
const char* infilename = "test.c";
|
|
const char* outfilename = "flat.bin";
|
|
if (argc >= 2) {
|
|
infilename = argv[1];
|
|
}
|
|
if (argc >= 3) {
|
|
outfilename = argv[2];
|
|
}
|
|
FILE* in = fopen(infilename, "r");
|
|
FILE* out = fopen(outfilename, "wb");
|
|
if (in == NULL || out == NULL) {
|
|
printf("Failed to open file\n");
|
|
return 1;
|
|
}
|
|
|
|
smcc_cc_t cc = {
|
|
.file = infilename,
|
|
.sread = (sread_fn)fread,
|
|
.stream = in,
|
|
};
|
|
|
|
asm_prog_t *prog = smcc_cc(&cc);
|
|
// gen_rv32_instr(&prog->rv32);
|
|
|
|
rv32_prog_t* rv32_crt = gen_rv32_crt();
|
|
rv32_prog_t* rv32_progs[3] = {
|
|
rv32_crt,
|
|
&prog->rv32,
|
|
NULL,
|
|
};
|
|
// rv32_progs[0] = rv32_crt;
|
|
// rv32_progs[1] = &prog->rv32;
|
|
// rv32_progs[2] = NULL;
|
|
|
|
rv32_prog_t* code = link_rv32_prog(rv32_progs);
|
|
|
|
// for (int i = 0; i < code->instrs.size; i++) {
|
|
// fwrite(&code->instrs.data[i].instr, 4, 1, out);
|
|
// fflush(out);
|
|
// }
|
|
|
|
// Flatbin fmt
|
|
fwrite(code->text.data, sizeof(u32_t), code->text.size, out);
|
|
// fwrite(code->data.data, sizeof(u8_t)code->text.size, 1, out);
|
|
|
|
fclose(in);
|
|
fclose(out);
|
|
return 0;
|
|
}
|