Skip to content

Commit

Permalink
tmp file name is based off of .sk filename now
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod committed Aug 14, 2020
1 parent 76baff9 commit 31b8bcf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
24 changes: 22 additions & 2 deletions skullc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,35 @@ int main(int argc, char *argv[]) {

str_to_llvm_ir(repl_read_raw(f), builder, ctx);

size_t len = strlen(argv[1]);
char *ll_filename = malloc(sizeof(char) * (len + 5));

char *slash_pos = strrchr(argv[1], '/');
if (!slash_pos) {
ll_filename[0] = '.';
memcpy(ll_filename + 1, argv[1], len);
}
else {
long offset = (long)(slash_pos - argv[1]);

memcpy(ll_filename, argv[1], len);
ll_filename[offset + 1] = '.';
memcpy(ll_filename + offset + 2, slash_pos + 1, len - (size_t)offset);
}
memcpy(ll_filename + len + 1, ".ll\0", 4);

char *err = NULL;
LLVMBool status = LLVMPrintModuleToFile(
main_module,
".tmp.ll",
ll_filename,
&err
);
free(ll_filename);

if (err || status) {
puts("error occurred!");
printf("error occurred: %s\n", err);
LLVMDisposeMessage(err);
return 1;
}

LLVMDisposeMessage(err);
Expand Down
12 changes: 7 additions & 5 deletions skullc/skullc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env bash

$(dirname $0)/_skullc $@ || exit 1
$(dirname $0)/_skullc $1 || exit 1

llc-9 .tmp.ll -filetype=obj || exit 1
rm .tmp.ll
base=$(dirname $1)/.$(basename $1)

cc .tmp.o -o "${1%.*}"
rm .tmp.o
llc-9 $base.ll -filetype=obj || exit 1
rm $base.ll

cc $base.o -o "${1%.*}"
rm $base.o

0 comments on commit 31b8bcf

Please sign in to comment.