Commit a6da8020 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

be: Move be_emit_asm() into a separate file for asm handling.

parent 73db736b
......@@ -13,6 +13,7 @@
#include "amd64_new_nodes.h"
#include "amd64_nodes_attr.h"
#include "be_t.h"
#include "beasm.h"
#include "beblocksched.h"
#include "bediagnostic.h"
#include "begnuas.h"
......
/*
* This file is part of libFirm.
* Copyright (C) 2015 University of Karlsruhe.
*/
#include <ctype.h>
#include "beasm.h"
#include "bediagnostic.h"
#include "beemitter.h"
#include "ident_t.h"
void be_emit_asm(ir_node const *const asmn, ident *const text, unsigned const n_operands, be_emit_asm_operand_func *const emit_asm_operand)
{
be_emit_cstring("#APP");
be_emit_finish_line_gas(asmn);
char const *s = get_id_str(text);
if (s[0] != '\t')
be_emit_char('\t');
char const *last = s;
while ((s = strchr(s, '%'))) {
be_emit_string_len(last, s - last);
++s; /* Skip '%'. */
switch (*s) {
case '%':
case '{':
case '|':
case '}':
be_emit_char(*s++);
break;
default: {
char const modifier = isalpha((unsigned char)*s) ? *s++ : '\0';
unsigned pos;
int p;
if (sscanf(s, "%u%n", &pos, &p) == 1) {
s += p;
if (pos < n_operands) {
emit_asm_operand(asmn, modifier, pos);
} else {
be_errorf(asmn, "asm operand number '%u' out of range", pos);
}
} else {
be_errorf(asmn, "could not parse asm operand number");
}
break;
}
}
last = s;
}
be_emit_string(last);
be_emit_cstring("\n#NO_APP\n");
be_emit_write_line();
}
/*
* This file is part of libFirm.
* Copyright (C) 2015 University of Karlsruhe.
*/
/**
* @file
* @brief Helper functions to handle inline assembler nodes.
*/
#ifndef FIRM_BE_BEASM_H
#define FIRM_BE_BEASM_H
#include "firm_types.h"
typedef void be_emit_asm_operand_func(ir_node const *asmn, char modifier, unsigned pos);
void be_emit_asm(ir_node const *asmn, ident *text, unsigned n_operands, be_emit_asm_operand_func *emit_asm_operand);
#endif
......@@ -9,9 +9,6 @@
* @author Matthias Braun
* @date 12.03.2007
*/
#include <ctype.h>
#include "bediagnostic.h"
#include "bedwarf.h"
#include "beemitter.h"
#include "benode.h"
......@@ -19,7 +16,6 @@
#include "panic.h"
#include "irnode_t.h"
#include "irprintf.h"
#include "ident.h"
#include "tv.h"
#include "dbginfo.h"
#include "util.h"
......@@ -106,50 +102,3 @@ void be_emit_node(ir_node const *const node)
DEBUG_ONLY(if (!emit) panic("no emit handler for node %+F (%+G, graph %+F)", node, node, get_irn_irg(node));)
emit(node);
}
void be_emit_asm(ir_node const *const asmn, ident *const text, unsigned const n_operands, be_emit_asm_operand_func *const emit_asm_operand)
{
be_emit_cstring("#APP");
be_emit_finish_line_gas(asmn);
char const *s = get_id_str(text);
if (s[0] != '\t')
be_emit_char('\t');
char const *last = s;
while ((s = strchr(s, '%'))) {
be_emit_string_len(last, s - last);
++s; /* Skip '%'. */
switch (*s) {
case '%':
case '{':
case '|':
case '}':
be_emit_char(*s++);
break;
default: {
char const modifier = isalpha((unsigned char)*s) ? *s++ : '\0';
unsigned pos;
int p;
if (sscanf(s, "%u%n", &pos, &p) == 1) {
s += p;
if (pos < n_operands) {
emit_asm_operand(asmn, modifier, pos);
} else {
be_errorf(asmn, "asm operand number '%u' out of range", pos);
}
} else {
be_errorf(asmn, "could not parse asm operand number");
}
break;
}
}
last = s;
}
be_emit_string(last);
be_emit_cstring("\n#NO_APP\n");
be_emit_write_line();
}
......@@ -125,8 +125,4 @@ void be_emit_nothing(ir_node const *node);
*/
void be_emit_node(ir_node const *node);
typedef void be_emit_asm_operand_func(ir_node const *asmn, char modifier, unsigned pos);
void be_emit_asm(ir_node const *asmn, ident *text, unsigned n_operands, be_emit_asm_operand_func *emit_asm_operand);
#endif
......@@ -30,6 +30,7 @@
#include "be_t.h"
#include "bearch_ia32_t.h"
#include "beasm.h"
#include "beblocksched.h"
#include "bediagnostic.h"
#include "begnuas.h"
......
......@@ -11,6 +11,7 @@
#include <inttypes.h>
#include "bearch_sparc_t.h"
#include "beasm.h"
#include "beblocksched.h"
#include "bediagnostic.h"
#include "begnuas.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment