Skip to content

Commit

Permalink
Add starg and star.s IL codes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyborgyn committed Oct 12, 2021
1 parent 19c92d9 commit f6bb406
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions IL2C.Core/ILConveters/StargConverters .cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// IL2C - A translator for ECMA-335 CIL/MSIL to C language.
// Copyright (c) 2016-2019 Kouji Matsui (@kozy_kekyo, @kekyo2)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

using System;

using Mono.Cecil.Cil;

using IL2C.Translators;
using IL2C.Metadata;

namespace IL2C.ILConverters
{
internal static class StargConverterUtilities
{
public static ExpressionEmitter Prepare(
int parameterIndex, DecodeContext decodeContext, bool isReference)
{
var parameter = decodeContext.Method.Parameters[parameterIndex];
var targetType = isReference ? parameter.TargetType.MakeByReference() : parameter.TargetType;
var symbol = decodeContext.PushStack(targetType);

return (extractContext, _) => new[] { string.Format(
"{0} = {1}{2}",
parameter.ParameterName,
// NOTE: Don't check "targetType.IsByReference" instead "isReference."
// Because it's maybe double encoded byref type.
isReference ? "&" : string.Empty,
extractContext.GetSymbolName(symbol)) };
}
}

internal sealed class StargSConverter : ShortInlineParamConverter
{
public override OpCode OpCode => OpCodes.Starg_S;

public override ExpressionEmitter Prepare(VariableInformation operand, DecodeContext decodeContext)
{
return StargConverterUtilities.Prepare(operand.Index, decodeContext, false);
}
}

internal sealed class StargConverter : InlineParamConverter
{
public override OpCode OpCode => OpCodes.Starg;

public override ExpressionEmitter Prepare(VariableInformation operand, DecodeContext decodeContext)
{
return StargConverterUtilities.Prepare(operand.Index, decodeContext, false);
}
}
}

0 comments on commit f6bb406

Please sign in to comment.