本文整理汇总了C#中CodeGeneration.CGenState类的典型用法代码示例。如果您正苦于以下问题:C# CGenState类的具体用法?C# CGenState怎么用?C# CGenState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CGenState类属于CodeGeneration命名空间,在下文中一共展示了CGenState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CGenStmt
public override void CGenStmt(Env env, CGenState state) {
if (this.ExprOpt.IsSome) {
Int32 stack_size = state.StackSize;
this.ExprOpt.Value.CGenValue(state);
state.CGenForceStackSizeTo(stack_size);
}
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:7,代码来源:Statements.cs
示例2: CGenValue
/// <summary>
/// flds addr
/// </summary>
public override Reg CGenValue(CGenState state) {
byte[] bytes = BitConverter.GetBytes(this.Value);
Int32 intval = BitConverter.ToInt32(bytes, 0);
String name = state.CGenLongConst(intval);
state.FLDS(name);
return Reg.ST0;
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:10,代码来源:ConstExpressions.cs
示例3: CGenPrepareIntegralOperands
// %eax = left, %ebx = right, stack unchanged
private void CGenPrepareIntegralOperands(CGenState state) {
// 1. Load Left to EAX.
//
// regs:
// %eax = Left
//
// stack:
// +-----+
// | ... | <- %esp
// +-----+
//
if (this.Left.CGenValue(state) != Reg.EAX) {
throw new InvalidOperationException();
}
// 2. Push Left to stack.
//
// regs:
// %eax = Left
//
// stack:
// +-----+
// | ... |
// +-----+
// | Left | <- %esp has decreased by 4
// +-----+
//
Int32 stack_size = state.CGenPushLong(Reg.EAX);
// 3. Load Right to EAX.
//
// regs:
// %eax = Right
//
// stack:
// +-----+
// | ... |
// +-----+
// | Left | <- %esp
// +-----+
//
if (this.Right.CGenValue(state) != Reg.EAX) {
throw new InvalidOperationException();
}
// 4. Move Right into EBX. Pop Left from stack, into EAX.
//
// regs:
// %eax = Left
// %ebx = Right
//
// stack:
// +-----+
// | ... | <- %esp has moved back.
// +-----+
//
state.MOVL(Reg.EAX, Reg.EBX);
state.CGenPopLong(stack_size, Reg.EAX);
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:60,代码来源:BinaryOperators.cs
示例4: CGenTest
public void CGenTest(Reg ret, CGenState state) {
// test Cond
switch (ret) {
case Reg.EAX:
state.TESTL(Reg.EAX, Reg.EAX);
break;
case Reg.ST0:
/// Compare Expr with 0.0
/// < see cref = "BinaryComparisonOp.OperateFloat(CGenState)" />
state.FLDZ();
state.FUCOMIP();
state.FSTP(Reg.ST0);
break;
default:
throw new InvalidProgramException();
}
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:19,代码来源:Statements.cs
示例5: CGenDecln
public void CGenDecln(Env env, CGenState state) {
// .text
// [.globl <func>]
// <func>:
// pushl %ebp
// movl %esp, %ebp
//
state.TEXT();
Env.Entry entry = env.Find(this.name).Value;
state.COMMENT(ToString());
switch (entry.Kind) {
case Env.EntryKind.GLOBAL:
switch (this.scs) {
case StorageClass.AUTO:
case StorageClass.EXTERN:
state.GLOBL(this.name);
break;
case StorageClass.STATIC:
// static definition
break;
default:
throw new InvalidOperationException();
}
break;
default:
throw new InvalidOperationException();
}
state.CGenFuncStart(this.name);
state.InFunction(GotoLabelsGrabber.GrabLabels(this.stmt));
this.stmt.CGenStmt(env, state);
state.CGenLabel(state.ReturnLabel);
state.OutFunction();
// leave
// ret
state.LEAVE();
state.RET();
state.NEWLINE();
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:42,代码来源:ExternalDefinitions.cs
示例6: CGenValue
public override Reg CGenValue(CGenState state) {
Reg ret = this.Expr.CGenValue(state);
switch (this.Kind) {
case TypeCastType.DOUBLE_TO_FLOAT:
case TypeCastType.FLOAT_TO_DOUBLE:
case TypeCastType.PRESERVE_INT16:
case TypeCastType.PRESERVE_INT8:
case TypeCastType.NOP:
return ret;
case TypeCastType.DOUBLE_TO_INT32:
case TypeCastType.FLOAT_TO_INT32:
state.CGenConvertFloatToLong();
return Reg.EAX;
case TypeCastType.INT32_TO_DOUBLE:
case TypeCastType.INT32_TO_FLOAT:
state.CGenConvertLongToFloat();
return Reg.ST0;
case TypeCastType.INT16_TO_INT32:
state.MOVSWL(Reg.AX, Reg.EAX);
return ret;
case TypeCastType.INT8_TO_INT16:
case TypeCastType.INT8_TO_INT32:
state.MOVSBL(Reg.AL, Reg.EAX);
return ret;
case TypeCastType.UINT16_TO_UINT32:
state.MOVZWL(Reg.AX, Reg.EAX);
return ret;
case TypeCastType.UINT8_TO_UINT16:
case TypeCastType.UINT8_TO_UINT32:
state.MOVZBL(Reg.AL, Reg.EAX);
return ret;
default:
throw new InvalidProgramException();
}
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:42,代码来源:TypeCast.cs
示例7: CGenAddress
public override void CGenAddress(CGenState state) {
Env.Entry entry = this.Env.Find(this.Name).Value;
Int32 offset = entry.Offset;
switch (entry.Kind) {
case Env.EntryKind.FRAME:
case Env.EntryKind.STACK:
state.LEA(offset, Reg.EBP, Reg.EAX);
return;
case Env.EntryKind.GLOBAL:
state.LEA(this.Name, Reg.EAX);
return;
case Env.EntryKind.ENUM:
case Env.EntryKind.TYPEDEF:
default:
throw new InvalidProgramException("cannot get the address of " + entry.Kind);
}
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:20,代码来源:Expressions.cs
示例8: Compiler
private Compiler(String source) {
this.Source = source;
// Lexical analysis
Scanner scanner = new Scanner(source);
this.Tokens = scanner.Tokens.ToImmutableList();
// Parse
var parserResult = CParsers.Parse(this.Tokens);
if (parserResult.Source.Count() != 1) {
throw new InvalidOperationException("Error: not finished parsing");
}
this.SyntaxTree = parserResult.Result;
// Semantic analysis
var semantReturn = this.SyntaxTree.GetTranslnUnit();
this.AbstractSyntaxTree = semantReturn.Value;
this.Environment = semantReturn.Env;
// Code generation
var state = new CGenState();
this.AbstractSyntaxTree.CodeGenerate(state);
this.Assembly = state.ToString();
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:24,代码来源:Compiler.cs
示例9: CalcAndSaveFloat
// Float
// Before the actual calculation, the state is set to this.
//
// regs:
// %ecx = &expr
//
// stack:
// +-------+
// | ..... | <- %esp
// +-------+
//
// float stack:
// +-------+
// | expr | <- %st(1)
// +-------+
// | 1.0 | <- %st(0)
// +-------+
//
// After the calculation, the result should be in %st(0),
// and memory should be updated.
//
public abstract void CalcAndSaveFloat(CGenState state);
开发者ID:phisiart,项目名称:C-Compiler,代码行数:22,代码来源:UnaryOperators.cs
示例10: CGenAddress
public override void CGenAddress(CGenState state) {
throw new InvalidOperationException("Cannot get the address of a cast expression.");
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:3,代码来源:TypeCast.cs
示例11: CalcAndSaveByte
public override void CalcAndSaveByte(CGenState state) {
state.SUBL(1, Reg.EAX);
state.MOVB(Reg.AL, 0, Reg.ECX);
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:4,代码来源:UnaryOperators.cs
示例12: CGenValue
public override sealed Reg CGenValue(CGenState state) {
// 1. Get the address of expr.
//
// regs:
// %eax = &expr
//
// stack:
// +-------+
// | ..... | <- %esp
// +-------+
//
this.Expr.CGenAddress(state);
// 2. Push address.
//
// regs:
// %eax = &expr
//
// stack:
// +-------+
// | ..... |
// +-------+
// | &expr | <- %esp
// +-------+
//
Int32 stack_size = state.CGenPushLong(Reg.EAX);
// 3. Get current Value of expr.
//
// 1) If expr is an integral or pointer:
//
// regs:
// %eax = expr
//
// stack:
// +-------+
// | ..... |
// +-------+
// | &expr | <- %esp
// +-------+
//
//
// 2) If expr is a float:
//
// regs:
// %eax = &expr
//
// stack:
// +-------+
// | ..... |
// +-------+
// | &expr | <- %esp
// +-------+
//
// float stack:
// +-------+
// | expr | <- %st(0)
// +-------+
//
Reg ret = this.Expr.CGenValue(state);
switch (ret) {
case Reg.EAX:
// expr is an integral or pointer.
// 4. Pop address to %ecx.
//
// regs:
// %eax = expr
// %ecx = &expr
//
// stack:
// +-------+
// | ..... | <- %esp
// +-------+
//
state.CGenPopLong(stack_size, Reg.ECX);
// 5. Cache current Value of Expr in %ebx.
//
// regs:
// %eax = expr
// %ebx = expr
// %ecx = &expr
//
// stack:
// +-------+
// | ..... | <- %esp
// +-------+
//
state.MOVL(Reg.EAX, Reg.EBX);
// 6. Calculate the new value in %ebx or %eax and save.
// Set %eax to be the return Value.
//
// regs:
// %eax = expr or (expr +- 1)
// %ebx = (expr +- 1) or expr
// %ecx = &expr
//.........这里部分代码省略.........
开发者ID:phisiart,项目名称:C-Compiler,代码行数:101,代码来源:UnaryOperators.cs
示例13: CodeGenerate
public void CodeGenerate(CGenState state) {
foreach (Tuple<Env, ExternDecln> decln in this.declns) {
decln.Item2.CGenDecln(decln.Item1, state);
}
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:6,代码来源:ExternalDefinitions.cs
示例14: CalcAndSaveWord
public override void CalcAndSaveWord(CGenState state) {
state.SUBL(1, Reg.EAX);
state.MOVW(Reg.AX, 0, Reg.ECX);
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:4,代码来源:UnaryOperators.cs
示例15: CalcAndSavePtr
public abstract void CalcAndSavePtr(CGenState state);
开发者ID:phisiart,项目名称:C-Compiler,代码行数:1,代码来源:UnaryOperators.cs
示例16: CGenDecln
// * function;
// * extern function;
// * static function;
// * obj;
// * obj = Init;
// * static obj;
// * static obj = Init;
// * extern obj;
// * extern obj = Init;
public void CGenDecln(Env env, CGenState state) {
if (env.IsGlobal()) {
if (this.initr.IsSome) {
Initr initr = this.initr.Value;
switch (this.scs) {
case StorageClass.AUTO:
state.GLOBL(this.name);
break;
case StorageClass.EXTERN:
throw new InvalidProgramException();
case StorageClass.STATIC:
break;
case StorageClass.TYPEDEF:
// Ignore.
return;
default:
throw new InvalidProgramException();
}
state.DATA();
state.ALIGN(ExprType.ALIGN_LONG);
state.CGenLabel(this.name);
Int32 last = 0;
initr.Iterate(this.type, (Int32 offset, Expr expr) => {
if (offset > last) {
state.ZERO(offset - last);
}
if (!expr.IsConstExpr) {
throw new InvalidOperationException("Cannot initialize with non-const expression.");
}
switch (expr.Type.Kind) {
// TODO: without const char/short, how do I initialize?
case ExprTypeKind.CHAR:
case ExprTypeKind.UCHAR:
case ExprTypeKind.SHORT:
case ExprTypeKind.USHORT:
throw new NotImplementedException();
case ExprTypeKind.LONG:
state.LONG(((ConstLong)expr).Value);
break;
case ExprTypeKind.ULONG:
state.LONG((Int32)((ConstULong)expr).Value);
break;
case ExprTypeKind.POINTER:
state.LONG((Int32)((ConstPtr)expr).Value);
break;
case ExprTypeKind.FLOAT:
byte[] float_bytes = BitConverter.GetBytes(((ConstFloat)expr).Value);
Int32 intval = BitConverter.ToInt32(float_bytes, 0);
state.LONG(intval);
break;
case ExprTypeKind.DOUBLE:
byte[] double_bytes = BitConverter.GetBytes(((ConstDouble)expr).Value);
Int32 first_int = BitConverter.ToInt32(double_bytes, 0);
Int32 second_int = BitConverter.ToInt32(double_bytes, 4);
state.LONG(first_int);
state.LONG(second_int);
break;
default:
throw new InvalidProgramException();
}
last = offset + expr.Type.SizeOf;
});
} else {
// Global without initialization.
switch (this.scs) {
case StorageClass.AUTO:
// .comm name,size,align
break;
case StorageClass.EXTERN:
//.........这里部分代码省略.........
开发者ID:phisiart,项目名称:C-Compiler,代码行数:101,代码来源:Declarations.cs
示例17: CGenAddress
public override sealed void CGenAddress(CGenState state) {
throw new InvalidOperationException(
"Cannot get the address of an unary arithmetic operator."
);
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:5,代码来源:UnaryOperators.cs
示例18: CalcAndSaveDouble
public override void CalcAndSaveDouble(CGenState state) {
state.FSUB(1, 0);
state.FSTL(0, Reg.ECX);
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:4,代码来源:UnaryOperators.cs
示例19: CGenAddress
public override sealed void CGenAddress(CGenState state) {
throw new InvalidOperationException("Cannot get the address of a constant");
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:3,代码来源:ConstExpressions.cs
示例20: CalcAndSaveLong
public override void CalcAndSaveLong(CGenState state) {
state.SUBL(1, Reg.EAX);
state.MOVL(Reg.EAX, 0, Reg.ECX);
}
开发者ID:phisiart,项目名称:C-Compiler,代码行数:4,代码来源:UnaryOperators.cs
注:本文中的CodeGeneration.CGenState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论