本文整理汇总了C#中System.IO.StringWriter.EmitTypeSpec方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.EmitTypeSpec方法的具体用法?C# StringWriter.EmitTypeSpec怎么用?C# StringWriter.EmitTypeSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringWriter
的用法示例。
在下文中一共展示了StringWriter.EmitTypeSpec方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoGenerate
public static void DoGenerate()
{
var edsl_base = @"..\..\..\..\Libptx.Edsl\Libptx.Edsl\";
var dir_sregs = edsl_base + @"Expressions\Sregs\";
Func<String, String> dir2ns = dir => dir.Replace(@"..\..\..\..\Libptx.Edsl\", String.Empty).Replace(@"\", ".").Slice(0, -1);
foreach (var t in Sregs.All)
{
var buf = new StringBuilder();
var w = new StringWriter(buf).Indented();
w.WriteLine("using Libptx.Edsl.Common.Types.Scalar;");
w.WriteLine("using Libptx.Edsl.Common.Types.Vector;");
w.WriteLineNoTabs(String.Empty);
w.WriteLine("namespace {0}", dir2ns(dir_sregs));
w.WriteLine("{");
w.Indent++;
w.WriteLine("public class {0} : {1}, sreg", t.Name, t.FullName);
w.WriteLine("{");
w.Indent++;
var xid = t.Name == "tid" || t.Name == "ntid" || t.Name == "ctaid" || t.Name == "nctaid";
if (xid)
{
var post_20 = Context.Current.Version >= SoftwareIsa.PTX_20;
if (post_20)
{
w.EmitTypeSpec(t.Name, new Type { Name = TypeName.U16, Mod = TypeMod.V4 }, Space.Other);
w.EmitTypeSpec(t.Name, new Type { Name = TypeName.U32, Mod = TypeMod.V4 }, Space.Other);
}
else
{
w.EmitTypeSpec(t.Name, new Type { Name = TypeName.U16, Mod = TypeMod.V4 }, Space.Other);
}
}
else
{
var type = t.Attr<SregAttribute>().Type;
w.EmitTypeSpec(t.Name, type, Space.Other);
}
// todo. also emit same stuff as gets emitted for non-reg vars of appropriate type
// e.g. .x, .y, .z accessors for grid-related special registers
w.Indent--;
w.WriteLine("}");
w.Indent--;
w.WriteLine("}");
var fname = dir_sregs + t.Name + ".cs";
File.WriteAllText(fname, buf.ToString());
}
}
示例2: DoGenerate
public static void DoGenerate()
{
var edsl_base = @"..\..\..\..\Libptx.Edsl\Libptx.Edsl\";
var dir_vector = edsl_base + @"Expressions\Immediate\";
var dir_vectors = edsl_base + @"Expressions\Immediate\Vectors\";
Func<String, String> dir2ns = dir =>
{
var rel = dir.Replace(@"..\..\..\..\Libptx.Edsl\", String.Empty);
rel = (rel + @"\").Unfold(s => s.Slice(0, -1), s => s.EndsWith(@"\")).Last();
return rel.Replace(@"\", ".").Slice(0, -1);
};
var shortcuts = new Dictionary<int, List<String>>();
new []{1, 2, 4}.ForEach(i => shortcuts.Add(i, new List<String>()));
Types.Vector.ForEach(t =>
{
t.is_vec().AssertTrue();
var name = String.Format("v{0}_{1}", t.vec_rank(), t.vec_el().Name.Signature());
var buf_vec = new StringBuilder();
var w_vec = new StringWriter(buf_vec).Indented();
w_vec.WriteLine("using {0};", typeof(AssertionHelper).Namespace);
w_vec.WriteLine("using {0};", typeof(Libptx.Edsl.Expressions.Slots.var).Namespace);
w_vec.WriteLine("using Libptx.Edsl.Common.Types.Scalar;");
w_vec.WriteLineNoTabs(String.Empty);
w_vec.WriteLine("namespace {0}", dir2ns(dir_vectors));
w_vec.WriteLine("{");
w_vec.Indent++;
w_vec.WriteLine("public class {0} : vector", name);
w_vec.WriteLine("{");
w_vec.Indent++;
Func<int, String> arg_name = i => i == 1 ? "x" : i == 2 ? "y" : i == 3 ? "z" : i == 4 ? "w" :
((Func<String>)(() => { throw AssertionHelper.Fail(); }))();
var args = 1.UpTo(t.vec_rank()).Select(i => String.Format("reg_{0} {1}", t.vec_el().Name.Signature(), arg_name(i))).StringJoin(", ");
w_vec.WriteLine("public {0}({1})", name, args);
var arg_names = 1.UpTo(t.vec_rank()).Select(arg_name).StringJoin(", ");
shortcuts[t.vec_rank()].Add(String.Format("public static {0} v{1}({2}) {{ return new {0}({3}); }}", name, t.vec_rank(), args, arg_names));
w_vec.WriteLine("{");
w_vec.Indent++;
w_vec.WriteLine("ElementType = {0};", t.vec_el().Name.Signature());
1.UpTo(t.vec_rank()).ForEach(i => w_vec.WriteLine("Elements.Add({0}.AssertCast<var>());", arg_name(i)));
w_vec.Indent--;
w_vec.WriteLine("}");
w_vec.WriteLineNoTabs(String.Empty);
w_vec.EmitTypeSpec(name, t, Space.Reg, true);
w_vec.Indent--;
w_vec.WriteLine("}");
w_vec.Indent--;
w_vec.WriteLine("}");
var fname_reg = dir_vectors + name + ".cs";
if (!Directory.Exists(dir_vectors)) Directory.CreateDirectory(dir_vectors);
File.WriteAllText(fname_reg, buf_vec.ToString());
});
var buf = new StringBuilder();
var w = new StringWriter(buf).Indented();
w.WriteLine("using {0};", typeof(Vector).Namespace);
w.WriteLine("using Libptx.Edsl.Common.Types.Scalar;");
w.WriteLine("using {0};", dir2ns(dir_vectors));
w.WriteLineNoTabs(String.Empty);
w.WriteLine("namespace {0}", dir2ns(dir_vector));
w.WriteLine("{");
w.Indent++;
w.WriteLine("public class vector : Vector");
w.WriteLine("{");
w.Indent++;
var write_shortcuts = shortcuts.Keys.Select<int, Action>(i => () => shortcuts[i].ForEach(w.WriteLine));
var write_empty_lines = Seq.Nats.Select<int, Action>(_ => () => w.WriteLineNoTabs(String.Empty));
write_shortcuts.Intersperse(write_empty_lines).SkipLast(1).RunEach();
w.Indent--;
w.WriteLine("}");
w.Indent--;
w.WriteLine("}");
var fname = dir_vector + "vector.cs";
if (!Directory.Exists(dir_vector)) Directory.CreateDirectory(dir_vector);
File.WriteAllText(fname, buf.ToString());
}