3 // This software is copyright (c) 2008 Scott Wood <scott@buserror.net>.
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
17 void CPPFile::output_ifaceinfo(Interface *iface)
22 file << indent << "void _invoke(::System::RunTime::Array"
23 << "< ::System::RunTime::ID> objlist,\n"
24 << indent << " ::System::RunTime::ParamInfoBlock::Segment *segs,\n"
25 << indent << " int nsegs);\n\n";
28 file << indent << "__attribute__((weak)) __attribute__((unused))\n"
29 << indent << "::System::RunTime::IFaceInfo _info = {\n"
30 << indent << "\t&_guid,\n"
34 void CPPFile::align_type(Symbol *sym)
37 << indent << "ctx.buf.align_to(__alignof__(";
38 cpp_output_name(file, sym);
42 void CPPFile::grow_buf()
44 file << indent << "ptr = ctx.buf.grow_by(len);\n";
47 void CPPFile::marshall_members(Struct *sym)
49 for (Struct::entries_iterator i = sym->entries_begin();
50 i != sym->entries_end(); ++i)
55 member->type->output_lang(this, trav_marshall, member);
57 output_marshall(member->def.basictype, member);
61 void CPPFile::output_marshall_array(Datum *d)
64 << indent << "ctx.buf.align_to(__alignof__(*data->" << **d->name << ".ptr));\n"
65 << indent << "len = data->" << **d->name
66 << ".count * sizeof(*data->" << **d->name << ".ptr);\n";
70 file << indent << "memcpy(ptr, data->" << **d->name << ".ptr, len);\n";
73 void CPPFile::output_marshall_method(Struct *sym)
75 file << indent << "__attribute__((weak)) __attribute__((unused))\n"
76 << indent << "void *_marshall(::System::RunTime::MarshCtx &ctx, ";
77 cpp_output_name(file, sym);
79 cpp_output_name(file, sym);
83 indent.indent_level++;
85 file << indent << "__attribute__((unused)) ";
86 cpp_output_name(file, sym);
88 << indent << "void *ptr;\n"
89 << indent << "size_t len;\n"
90 << indent << "__attribute__((unused)) size_t i = 0;\n";
93 file << indent << "*link = (";
94 cpp_output_name(file, sym);
95 file << " *)ctx.buf.count;\n";
96 file << indent << "len = sizeof(*data);\n";
99 file << indent << "memcpy(ptr, data, len);\n"
100 << indent << "sptr = (";
101 cpp_output_name(file, sym);
104 marshall_members(sym);
105 indent.indent_level--;
107 file << indent << "\treturn 0;\n"
108 << indent << "}\n\n";
111 void CPPFile::output_marshall_inline_method(Struct *sym)
113 file << indent << "__attribute__((weak)) __attribute__((unused))\n"
114 << indent << "void *_marshall_inline(::System::RunTime::MarshCtx &ctx, ";
115 cpp_output_name(file, sym);
117 cpp_output_name(file, sym);
121 indent.indent_level++;
123 file << indent << "__attribute__((unused)) void *ptr;\n"
124 << indent << "__attribute__((unused)) size_t len;\n"
125 << indent << "__attribute__((unused)) size_t i = 0;\n";
127 marshall_members(sym);
128 indent.indent_level--;
130 file << indent << "\treturn 0;\n"
134 void CPPFile::output_marshall(Struct *sym, Datum *d)
136 bool array = d->is_array(), inl = d->is_inline();
137 const char *index = "";
142 file << indent << "for (size_t i = 0; i < ";
145 file << d->array->cons[0].con.ucon;
147 file << "data->" << **d->name << ".count";
149 file << "; i++) {\n";
151 indent.indent_level++;
156 file << indent << "if (data->" << **d->name << index << ")\n";
157 indent.indent_level++;
161 cpp_output_name(file, sym);
162 file << "_ns::_marshall";
165 file << "_inline(ctx, &";
169 file << "data->" << **d->name << index
170 << ", &sptr->" << **d->name << index << ");\n";
173 indent.indent_level--;
176 indent.indent_level--;
177 file << indent << "}\n";
181 void CPPFile::output_marshall(Interface *sym, Datum *d)
183 printf("marshall iface\n");
186 void CPPFile::output_marshall(Enum *sym, Datum *d)
188 if (!d->is_array() || d->is_inline())
191 output_marshall_array(d);
194 void CPPFile::output_marshall(BitField *sym, Datum *d)
196 if (!d->is_array() || d->is_inline())
199 output_marshall_array(d);
202 void CPPFile::output_marshall(BasicType *sym, Datum *d)
204 if (!d->is_array() || d->is_inline())
207 output_marshall_array(d);
210 void CPPFile::output_marshall(CompiledBasicType &cbt, Datum *d)
212 if (!d->is_array() || d->is_inline())
215 output_marshall_array(d);
218 void CPPFile::output_marshall_pass(Struct *sym, int pass)
224 file << indent << "void *_marshall(::System::RunTime::MarshCtx &ctx,\n"
226 cpp_output_name(file, sym);
228 cpp_output_name(file, sym);
229 file << " **link);\n";
231 file << indent << "void *_marshall_inline(::System::RunTime::MarshCtx &ctx,\n"
233 cpp_output_name(file, sym);
235 cpp_output_name(file, sym);
236 file << " *sptr);\n";
238 file << indent << "void _unmarshall(::System::RunTime::MarshCtx &ctx,\n"
240 cpp_output_name(file, sym);
241 file << " *data);\n";
245 output_marshall_method(sym);
246 output_marshall_inline_method(sym);
249 file << indent << "__attribute__((weak)) __attribute__((unused))\n"
250 << indent << "void _unmarshall(::System::RunTime::Array<uint8_t, ::System::RunTime::ORBMM> buf,\n"
251 << indent << " ::System::RunTime::Array< ::System::_i_Object *, ::System::RunTime::ORBMM> objlist,\n"
252 << indent << " ::System::RunTime::ParamInfoBlock::Segment *segs,\n"
253 << indent << " int nsegs)\n"