本文整理汇总了C#中CodeGeneration.CGenState类的典型用法代码示例。如果您正苦于以下问题:C# CGenState类的具体用法?C# CGenState怎么用?C# CGenState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CGenState类属于CodeGeneration命名空间,在下文中一共展示了CGenState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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);
}
}
示例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();
}
示例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);
示例10: CGenAddress
public override void CGenAddress(CGenState state) {
throw new InvalidOperationException("Cannot get the address of a cast expression.");
}
示例11: CalcAndSaveByte
public override void CalcAndSaveByte(CGenState state) {
state.SUBL(1, Reg.EAX);
state.MOVB(Reg.AL, 0, Reg.ECX);
}
示例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
//.........这里部分代码省略.........
示例13: CodeGenerate
public void CodeGenerate(CGenState state) {
foreach (Tuple<Env, ExternDecln> decln in this.declns) {
decln.Item2.CGenDecln(decln.Item1, state);
}
}
示例14: CalcAndSaveWord
public override void CalcAndSaveWord(CGenState state) {
state.SUBL(1, Reg.EAX);
state.MOVW(Reg.AX, 0, Reg.ECX);
}
示例15: CalcAndSavePtr
public abstract void CalcAndSavePtr(CGenState state);