forked from kekyo/IL2C
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |