Skip to content

Commit 1d8c313

Browse files
committed
Improve asm output
1 parent 77a3093 commit 1d8c313

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

playground/umka.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/umka_gen.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,21 @@ int genTryRemoveCopyResultToTempVar(CodeGen *gen)
10731073

10741074
int genAsm(CodeGen *gen, char *buf, int size)
10751075
{
1076-
int ip = 0, chars = 0;
1076+
bool *jumpFrom = calloc(gen->capacity + 1, 1);
1077+
bool *jumpTo = calloc(gen->capacity + 1, 1);
1078+
1079+
int ip = 0;
1080+
do
1081+
{
1082+
if (gen->code[ip].opcode == OP_GOTO || gen->code[ip].opcode == OP_GOTO_IF || gen->code[ip].opcode == OP_GOTO_IF_NOT)
1083+
{
1084+
jumpFrom[ip] = true;
1085+
jumpTo[(int)gen->code[ip].operand.intVal] = true;
1086+
}
1087+
} while (gen->code[ip++].opcode != OP_HALT);
1088+
1089+
ip = 0;
1090+
int chars = 0;
10771091
do
10781092
{
10791093
if (ip == 0 || gen->debugPerInstr[ip].fileName != gen->debugPerInstr[ip - 1].fileName)
@@ -1085,11 +1099,14 @@ int genAsm(CodeGen *gen, char *buf, int size)
10851099
chars += vmAsm(ip, gen->code, gen->debugPerInstr, buf + chars, nonneg(size - chars));
10861100
chars += snprintf(buf + chars, nonneg(size - chars), "\n");
10871101

1088-
if (gen->code[ip].opcode == OP_GOTO || gen->code[ip].opcode == OP_GOTO_IF || gen->code[ip].opcode == OP_GOTO_IF_NOT || gen->code[ip].opcode == OP_RETURN)
1102+
if (gen->code[ip].opcode == OP_RETURN || jumpFrom[ip] || jumpTo[ip + 1])
10891103
chars += snprintf(buf + chars, nonneg(size - chars), "\n");
10901104

10911105
} while (gen->code[ip++].opcode != OP_HALT);
10921106

1107+
free(jumpFrom);
1108+
free(jumpTo);
1109+
10931110
return chars;
10941111
}
10951112

src/umka_ident.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ char *identMethodNameWithRcv(Ident *method, char *buf, int size)
342342
{
343343
char typeBuf[DEFAULT_STR_LEN + 1];
344344
typeSpelling(method->type->sig.param[0]->type, typeBuf);
345-
snprintf(buf, size, "%s.%s", typeBuf, method->name);
345+
snprintf(buf, size, "(%s)%s", typeBuf, method->name);
346346
return buf;
347347
}
348348

0 commit comments

Comments
 (0)