fout(p, "%%String = type i8*\n");
fout(p, "declare ptr @allocate(i64)\n");
fout(p, "declare void @deallocate(ptr)\n");
- fout(p,
- "%%obj.header.t = type { i64 }"
- "\n"
- "define private void @addref(ptr %%0) {\n"
- " %%2 = icmp eq ptr %%0, null\n"
- " br i1 %%2, label %%7, label %%3\n"
- "3:\n"
- " %%4 = getelementptr inbounds %%obj.header.t, ptr %%0, i64 -1\n"
- " %%5 = load i64, ptr %%4, align 8\n"
- " %%6 = add nsw i64 %%5, 1\n"
- " store i64 %%6, ptr %%4, align 8\n"
- " br label %%7\n"
- "7:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define private void @delref(ptr %%0) {\n"
- " %%2 = icmp eq ptr %%0, null\n"
- " br i1 %%2, label %%9, label %%3\n"
- "3:\n"
- " %%4 = getelementptr inbounds %%obj.header.t, ptr %%0, i64 -1\n"
- " %%5 = load i64, ptr %%4, align 8\n"
- " %%6 = add nsw i64 %%5, -1\n"
- " store i64 %%6, ptr %%4, align 8\n"
- " %%7 = icmp eq i64 %%6, 0\n"
- " br i1 %%7, label %%8, label %%9\n"
- "8:\n"
- " tail call void @deallocate(ptr %%0) #4\n"
- " br label %%9\n"
- "9:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define private void @retref(ptr %%0) {\n"
- " %%2 = icmp eq ptr %%0, null\n"
- " br i1 %%2, label %%7, label %%3\n"
- "3:\n"
- " %%4 = getelementptr inbounds %%obj.header.t, ptr %%0, i64 -1\n"
- " %%5 = load i64, ptr %%4, align 8\n"
- " %%6 = add nsw i64 %%5, -1\n"
- " store i64 %%6, ptr %%4, align 8\n"
- " br label %%7\n"
- "7:\n"
- " ret void\n"
- "}\n"
- );
+ fout(p, "declare void @addref(ptr %%0);\n");
+ fout(p, "declare void @delref(ptr %%0);\n");
+ fout(p, "declare void @retref(ptr %%0);\n");
}
void codegen_symbol(Parser* p, Symbol* sym)
{
Parser p = {0};
compile_module(&p, path, true);
- char* link_cmd = strmcat("clang -static -o ", p.name, " ", 0);
+ char* link_cmd = strmcat("clang -static -g -o ", p.name, " ", 0);
for (size_t i = 0; i < p.nmods; i++)
{
if (!p.mods[i].path) continue;
}
char* object = strdup(p.outpath);
object[strlen(object)-1] = 'o';
- link_cmd = strmcat(link_cmd, "\"", object, "\" ", "-lm", 0);
+ link_cmd = strmcat(link_cmd, "\"", object, "\" ", "-L. ", "-lm ", "-lcerise", 0);
puts(link_cmd);
if (system(link_cmd) != 0)
{