Ejemplo n.º 1
0
void StructTypeReplacement::flatten(const P4::TypeMap* typeMap,
                                    cstring prefix,
                                    const IR::Type* type,
                                    IR::IndexedVector<IR::StructField> *fields) {
    if (auto st = type->to<IR::Type_Struct>()) {
        structFieldMap.emplace(prefix, st);
        for (auto f : st->fields)
            flatten(typeMap, prefix + "." + f->name, f->type, fields);
        return;
    }
    cstring fieldName = prefix.replace(".", "_") +
                        cstring::to_cstring(fieldNameRemap.size());
    fieldNameRemap.emplace(prefix, fieldName);
    fields->push_back(new IR::StructField(IR::ID(fieldName), type->getP4Type()));
}
Ejemplo n.º 2
0
void bmlwriter::node(cstring name, cstring val, mode m, bool enter)
{
	m = type(val, m);
	bool inlined = (m <= icol && m_caninline && !enter);
	if (m_data)
	{
		if (inlined) m_data += " ";
		else m_data += "\n"+indent();
	}
	
	m_indent++;
	
	if ((m==anon || m==eq || m==quote) && enter) m_caninline = true;
	if (m==icol || m==col || m==multiline) m_caninline = false;
	//for other modes, inlinability isn't affected
	
	switch (m)
	{
		case ianon:
		case anon:
			m_data += name;
			break;
		case ieq:
		case eq:
			m_data += name+"="+val;
			break;
		case iquote:
		case quote:
			m_data += name+"=\""+val+"\"";
			break;
		case icol:
		case col:
			m_data += name+": "+val;
			break;
		case multiline:
			string prefix = "\n"+indent()+":";
			m_data += name + prefix + val.replace("\n", prefix);
			break;
	}
	if (!enter) m_indent--;
}