From 962ad175aee634274b408ead38b13e6bc90e2fe7 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 17 Jun 2023 23:26:45 +0200 Subject: basic ELF output --- ir.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ir.c') diff --git a/ir.c b/ir.c index d8772ad..1351f02 100644 --- a/ir.c +++ b/ir.c @@ -1,4 +1,5 @@ #include "ir.h" +#include "common.h" uchar type2cls[NTYPETAG]; uchar cls2siz[KF8+1]; @@ -191,6 +192,22 @@ mkdatref(uint siz, uint align, const void *bytes, uint n, bool deref) return mkref(RXCON, addcon(&(struct xcon){.isdat = 1, .deref = deref, .dat = dattab.n - 1})); } +const char * +xcon2sym(int ref) +{ + extern const char *intern(const char *); + char buf[32]; + struct wbuf wbuf = MEMBUF(buf, sizeof buf); + struct xcon *con = &conht[ref]; + + assert(con->isdat || con->issym); + if (con->issym) return con->sym; + bfmt(&wbuf, ".L.%d", con->dat); + ioputc(&wbuf, 0); + assert(!wbuf.err); + return intern(buf); +} + struct instr mkalloca(uint siz, uint align) { -- cgit v1.2.3