Skip to content

Commit 4512fc4

Browse files
Changes for faster generation of files (#20)
* Fix some generation issues * generate InterfaceDispatcherData in TraditionalBridgeGenerator * performance changes for codegen * do not generate the same thing multiple times
1 parent 0c62f8c commit 4512fc4

4 files changed

Lines changed: 36 additions & 27 deletions

File tree

CodeGenEngine/LoopExpander.dbl

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,17 +1274,18 @@ namespace CodeGen.Engine
12741274
data taskset = context.Taskset
12751275
data task = context.CurrentTask
12761276
data currentInterface, @SmcInterface
1277-
try
1277+
1278+
data result = loops.FirstOrDefault(lambda (loopnode) {loopnode .is. InterfaceLoopNode})
1279+
if (result != ^null) then
12781280
begin
1279-
data outerLoop = ^as(loops.First(lambda (loopnode) {loopnode .is. InterfaceLoopNode}), InterfaceLoopNode)
1281+
data outerLoop = ^as(result, InterfaceLoopNode)
12801282
currentInterface = outerLoop.CurrentInterface
12811283
end
1282-
catch (e, @InvalidOperationException)
1284+
else
12831285
begin
12841286
;;We're not using an <INTERFACE_LOOP> so there is no "outer" loop
12851287
currentInterface = taskset.MethodCatalog.Interfaces.FirstOrDefault(lambda(iface) {iface.Name.Equals(task.Interface)})
12861288
end
1287-
endtry
12881289

12891290
;;Make sure we have SMC data
12901291
if (taskSet.MethodCatalog == ^null)
@@ -1328,17 +1329,20 @@ namespace CodeGen.Engine
13281329
;;Get a handle on the current SMC Interface. This is either the current interface being processed in
13291330
;;an outer interface loop, or the interface specified via the -interface command line option if no
13301331
;;interface loop is being used.
1331-
try
1332+
13321333
begin
1333-
data outerOuterLoop = ^as(loops.First(lambda (loopnode) {loopnode .is. InterfaceLoopNode}), InterfaceLoopNode)
1334-
currentInterface = outerOuterLoop.CurrentInterface
1335-
end
1336-
catch (e, @InvalidOperationException)
1337-
begin
1338-
;;We're not using an <INTERFACE_LOOP> so there is no "outer outer" loop
1339-
currentInterface = taskset.MethodCatalog.Interfaces.FirstOrDefault(lambda(iface) {iface.Name.Equals(task.Interface)})
1334+
data result = loops.FirstOrDefault(lambda (loopnode) {loopnode .is. InterfaceLoopNode})
1335+
if (result != ^null) then
1336+
begin
1337+
data outerOuterLoop = ^as(result, InterfaceLoopNode)
1338+
currentInterface = outerOuterLoop.CurrentInterface
1339+
end
1340+
else
1341+
begin
1342+
;;We're not using an <INTERFACE_LOOP> so there is no "outer outer" loop
1343+
currentInterface = taskset.MethodCatalog.Interfaces.FirstOrDefault(lambda(iface) {iface.Name.Equals(task.Interface)})
1344+
end
13401345
end
1341-
endtry
13421346

13431347
;;Make sure we have SMC data
13441348
if (taskSet.MethodCatalog == ^null)

CodeGenEngine/TokenExpanders/TokenExpanderInterfaceLoop.dbl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ namespace CodeGen.Engine
8484
data task = template.Context.CurrentTask
8585
data loop, @InterfaceLoopNode
8686
data currentInterface, @SmcInterface
87-
try
87+
88+
data result = loops.FirstOrDefault(lambda (loopnode) {loopnode .is. InterfaceLoopNode})
89+
if (result != ^null) then
8890
begin
89-
lambda isInterfaceLoop(node) node .is. InterfaceLoopNode
90-
loop = ^as(loops.First(isInterfaceLoop), InterfaceLoopNode)
91+
loop = ^as(result, InterfaceLoopNode)
9192
currentInterface = loop.CurrentInterface
9293
end
93-
catch (e, @InvalidOperationException)
94+
else
9495
begin
9596
currentInterface = taskSet.MethodCatalog.Interfaces.FirstOrDefault(lambda(iface) {iface.Name.Equals(task.Interface)})
9697
end
97-
endtry
9898
mreturn specific(taskset.MethodCatalog,currentInterface)
9999
endmethod
100100

HarmonyCoreCodeGen.Core/Generator/GeneratorBase.dbl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ namespace HarmonyCoreGenerator.Generator
235235
targetTemplates, [#]@string
236236
userTokens, [#]@UserToken
237237
default templateFolder, @string, ^null
238+
default useStructures, boolean, true
238239
proc
239-
data targetStructures = GetTargetStructures(generatorNameForStructures, targetSolution)
240+
data targetStructures = new List<StructureEx>()
241+
if (useStructures)
242+
targetStructures = GetTargetStructures(generatorNameForStructures, targetSolution)
240243
data task = new CodeGen.Engine.CodeGenTask()
241244
task.Description = taskDescription
242245
task.Templates.AddRange<String>(targetTemplates)
@@ -253,7 +256,8 @@ namespace HarmonyCoreGenerator.Generator
253256
task.ReplaceFiles = true
254257
task.MultipleStructures = multiStructure
255258
task.UserTokens.AddRange<UserToken>(MergeTokens(targetSolution.GetUserDefinedTokens(), userTokens))
256-
task.Structures.AddRange<String>(targetStructures.Select(lambda(struct) { struct.Name }))
259+
if (useStructures)
260+
task.Structures.AddRange<String>(targetStructures.Select(lambda(struct) { struct.Name }))
257261
mreturn task
258262
endmethod
259263

@@ -267,8 +271,9 @@ namespace HarmonyCoreGenerator.Generator
267271
targetTemplates, [#]@string
268272
userTokens, [#]@UserToken
269273
default templateFolder, @string, ^null
274+
default useStructures, boolean, true
270275
proc
271-
data task = StructureTaskHelper(targetSolution, taskDescription, taskNamespace, taskOutput, false, generatorName, targetTemplates, userTokens, templateFolder)
276+
data task = StructureTaskHelper(targetSolution, taskDescription, taskNamespace, taskOutput, false, generatorName, targetTemplates, userTokens, templateFolder, useStructures)
272277
task.Interface = targetInterface.Name
273278

274279
mreturn task

HarmonyCoreCodeGen.Core/Generator/TraditionalBridgeGenerator.dbl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,32 @@ namespace HarmonyCoreGenerator.Generator
3939
begin
4040

4141
result.Add(GeneratorBase.InterfaceTaskHelper(targetSolution, "Generate a dispatcher class for each method", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Dispatchers"), Path.Combine(targetSolution.TraditionalBridgeFolder,"Dispatchers"), iface, ^nameof(TraditionalBridgeGenerator),
42-
& new string[#] { "InterfaceMethodDispatchers" }, new UserToken[#] { modelsNamespace }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge")))
42+
& new string[#] { "InterfaceMethodDispatchers" }, new UserToken[#] { modelsNamespace }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge"), false))
4343

4444
;; Main dispatcher class (Traditional Side)
4545
result.Add(GeneratorBase.InterfaceTaskHelper(targetSolution, "Generate main dispatcher class", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Dispatchers"), Path.Combine(targetSolution.TraditionalBridgeFolder,"Dispatchers"), iface, ^nameof(TraditionalBridgeGenerator),
46-
& new string[#] { "InterfaceDispatcher" }, new UserToken[#] { modelsNamespace }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge")))
46+
& new string[#] { "InterfaceDispatcher" }, new UserToken[#] { modelsNamespace }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge"), false))
4747

4848
;; Sample data generator class (Traditional Side)
4949
result.Add(GeneratorBase.InterfaceTaskHelper(targetSolution, "Generate a class to generate sample response data", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Methods"), Path.Combine(targetSolution.TraditionalBridgeFolder,"Methods"), iface, ^nameof(TraditionalBridgeGenerator),
50-
& new string[#] { "InterfaceTestResponses" }, new UserToken[#] { modelsNamespace }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge")))
50+
& new string[#] { "InterfaceTestResponses" }, new UserToken[#] { modelsNamespace }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge"), false))
5151

5252
if(targetInterfaces.Count > 1) then
5353
begin
5454
;; Request and response models for the service class methods (.NET side)
5555
result.Add(GeneratorBase.InterfaceTaskHelper(targetSolution, "Generate request and response models for the service class methods", targetSolution.ModelsNamespace, targetSolution.ModelsFolder, iface, ^nameof(TraditionalBridgeGenerator),
56-
& new string[#] { "MultiInterfaceServiceModels" }, new UserToken[#] { modelsNamespace, new UserToken("DTOS_NAMESPACE", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Models"))}, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge")))
56+
& new string[#] { "MultiInterfaceServiceModels" }, new UserToken[#] { modelsNamespace, new UserToken("DTOS_NAMESPACE", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Models"))}, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge"), false))
5757
end
5858
else
5959
begin
6060
;; Request and response models for the service class methods (.NET side)
6161
result.Add(GeneratorBase.InterfaceTaskHelper(targetSolution, "Generate request and response models for the service class methods", targetSolution.ModelsNamespace, targetSolution.ModelsFolder, iface, ^nameof(TraditionalBridgeGenerator),
62-
& new string[#] { "InterfaceServiceModels" }, new UserToken[#] { modelsNamespace, new UserToken("DTOS_NAMESPACE", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Models")) }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge")))
62+
& new string[#] { "InterfaceServiceModels" }, new UserToken[#] { modelsNamespace, new UserToken("DTOS_NAMESPACE", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Models")) }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge"), false))
6363
end
6464

6565
;; Service class (.NET side)
6666
result.Add(GeneratorBase.InterfaceTaskHelper(targetSolution, "Generate the service class (.NET side)", targetSolution.ControllersNamespace, targetSolution.ControllersFolder, iface, ^nameof(TraditionalBridgeGenerator),
67-
& new string[#] { "InterfaceService" }, new UserToken[#] { modelsNamespace, new UserToken("DTOS_NAMESPACE", String.Format("{0}.{1}", targetSolution.TraditionalBridgeFolder, iface.Name)) }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge")))
67+
& new string[#] { "InterfaceService" }, new UserToken[#] { modelsNamespace, new UserToken("DTOS_NAMESPACE", String.Format("{0}.{1}", targetSolution.TraditionalBridgeFolder, iface.Name)) }, Path.Combine(targetSolution.TemplatesFolder,"TraditionalBridge"), false))
6868

6969
;; Parameter model classes (Traditional Side)
7070
result.Add(GeneratorBase.InterfaceTaskHelper(targetSolution, "Generate data models for structure parameters", String.Format("{0}.{1}",targetSolution.TraditionalBridgeFolder,"Models"), Path.Combine(targetSolution.TraditionalBridgeFolder,"Models"), iface, ^nameof(TraditionalBridgeGenerator),

0 commit comments

Comments
 (0)