public ILabel AllocateStruct(Function.Function function, StructType structType, ILocation target, ILabel after) { if (structType.Fields.Count == 0) { return(after); } var allocateFunctionName = NameMangler.GetMangledName("allocate", new List <AST.DataType>() { IntType.Instance }, null); var allocateFunc = new Function.Function( null, allocateFunctionName, new List <AST.VariableDeclaration>() { new AST.VariableDeclaration(null, IntType.Instance, "size", null) }, isEntryPoint: false, isForeign: true); var sizeRegister = new VirtualRegister(); var call = this.callGenerator.GenerateCall(target, new List <VirtualRegister>() { sizeRegister }, after, callerFunction: function, function: allocateFunc); var writeSize = new RegisterWrite(sizeRegister, new IntegerImmediateValue(structType.Fields.Count * 8)); var startLabel = this.labelFactory.GetLabel(new Tree(writeSize, new UnconditionalJump(call))); return(startLabel); }
public void Test() { // tested with c++filt FunctionDeclaration function1 = new FunctionDeclaration( new Range(new StringLocation(0), new StringLocation(1)), identifier: "foo", returnType: null, parameters: new List <VariableDeclaration>() { new VariableDeclaration( new Range(new StringLocation(0), new StringLocation(1)), IntType.Instance, null, null), new VariableDeclaration( new Range(new StringLocation(0), new StringLocation(1)), IntType.Instance, null, null), new VariableDeclaration( new Range(new StringLocation(0), new StringLocation(1)), BoolType.Instance, null, null), }, body: null, false); Assert.AreEqual( actual: NameMangler.GetMangledName(function1, null), expected: "_ZN3KJU3fooExxb"); Assert.AreEqual( actual: NameMangler.GetMangledName(function1, "_ZN3KJU3barEv"), expected: "_ZZN3KJU3barEvEN3fooExxb"); Assert.AreEqual( actual: NameMangler.GetMangledName(function1, "_ZZN3KJU3fooEvEN3fooExxb"), expected: "_ZZZN3KJU3fooEvEN3fooExxbEN3fooExxb"); FunctionDeclaration function2 = new FunctionDeclaration( new Range(new StringLocation(0), new StringLocation(1)), identifier: "bar", returnType: null, parameters: new List <VariableDeclaration>() { }, body: null, false); Assert.AreEqual( actual: NameMangler.GetMangledName(function2, null), expected: "_ZN3KJU3barEv"); }
public static Function CreateFunction(FunctionDeclaration functionDeclaration, Function parentFunction) { var mangledName = NameMangler.GetMangledName(functionDeclaration, parentFunction?.MangledName); var parameters = functionDeclaration.Parameters; var isEntryPoint = functionDeclaration.IsEntryPoint; var isForeign = functionDeclaration.IsForeign; return(new Function( parentFunction, mangledName, parameters, isEntryPoint, isForeign, hasChildFunctions: HasChildFunctions(functionDeclaration))); }