#include <limits.h>
+#include "xmalloc.h"
#include "tv.h"
#include "iredges.h"
#include "debug.h"
tarval *tv = get_ia32_Immop_tarval(n);
if (tv) {
- buf = malloc(SNPRINTF_BUF_LEN);
+ buf = xmalloc(SNPRINTF_BUF_LEN);
tarval_snprintf(buf, SNPRINTF_BUF_LEN, tv);
return buf;
}
tarval *tv = get_ia32_am_offs(n);
if (tv) {
- buf = malloc(SNPRINTF_BUF_LEN);
+ buf = xmalloc(SNPRINTF_BUF_LEN);
tarval_snprintf(buf, SNPRINTF_BUF_LEN, tv);
return buf;
}
FILE *F = emit_env->out;
/* fill the table structure */
- tbl.label = malloc(SNPRINTF_BUF_LEN);
+ tbl.label = xmalloc(SNPRINTF_BUF_LEN);
tbl.label = get_unique_label(tbl.label, SNPRINTF_BUF_LEN, "JMPTBL_");
tbl.defProj = NULL;
tbl.num_branches = get_irn_n_edges(irn);
- tbl.branches = calloc(tbl.num_branches, sizeof(tbl.branches[0]));
+ tbl.branches = xcalloc(tbl.num_branches, sizeof(tbl.branches[0]));
tbl.min_value = INT_MAX;
tbl.max_value = INT_MIN;
}
+
+/**
+ * Emits code for Alloca (increase stack pointer, cpoy to destination)
+ */
+void emit_Alloca(ir_node *irn, emit_env_t *emit_env, int is_imm) {
+ const lc_arg_env_t *env = ia32_get_arg_env();
+ FILE *F = emit_env->out;
+ char *sp;
+
+ if (emit_env->cg->has_alloca) {
+ sp = "%ebp";
+ }
+ else {
+ sp = "%esp";
+ }
+
+
+ /* allocate the memory */
+ fprintf(F, "\tsub %s", sp);
+
+ if (is_imm) {
+ lc_efprintf(env, F, "%C", irn);
+ }
+ else {
+ lc_efprintf(env, F, "%1S", irn);
+ }
+
+ fprintf(F, "\t\t\t\t/* reserve memory on stack */\n");
+
+ /* copy the new stack pointer to destination register */
+ lc_efprintf(env, F, "\tmov %s, %1D\t\t\t/* copy stack pointer to destination */\n", sp, irn);
+}
+
+void emit_ia32_Alloca(ir_node *irn, emit_env_t *emit_env) {
+ emit_Alloca(irn, emit_env, 0);
+}
+
+void emit_ia32_Alloca_i(ir_node *irn, emit_env_t *emit_env) {
+ emit_Alloca(irn, emit_env, 1);
+}
+
+
/***********************************************************************************
* _ __ _
* (_) / _| | |
IA32_EMIT(CondJmp_i);
IA32_EMIT(SwitchJmp);
IA32_EMIT(Call);
+ IA32_EMIT(Alloca);
+ IA32_EMIT(Alloca_i);
EMIT(Jmp);
EMIT(Proj);