Skip to content

Commit 45f3f53

Browse files
committed
Automatic declaration of User defined functions
WIP, does not even compile
1 parent 00d4ac2 commit 45f3f53

File tree

8 files changed

+38
-7
lines changed

8 files changed

+38
-7
lines changed

BackendAst/DAstACN.fs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ let private createAcnIntegerFunctionInternal (r:Asn1AcnAst.AstRoot)
438438
acnMinSizeInBits
439439
acnMaxSizeInBits
440440
unitsOfMeasure
441+
(typeName:string)
441442
(soMF:string option, soMFM:string option): AcnIntegerFuncBody =
442443
let PositiveInteger_ConstSize_8 = lm.acn.PositiveInteger_ConstSize_8
443444
let PositiveInteger_ConstSize_big_endian_16 = lm.acn.PositiveInteger_ConstSize_big_endian_16
@@ -462,6 +463,7 @@ let private createAcnIntegerFunctionInternal (r:Asn1AcnAst.AstRoot)
462463
let ASCII_UINT_VarSize_NullTerminated = lm.acn.ASCII_UINT_VarSize_NullTerminated
463464
let BCD_ConstSize = lm.acn.BCD_ConstSize
464465
let BCD_VarSize_NullTerminated = lm.acn.BCD_VarSize_NullTerminated
466+
let mappingFunctionDeclaration = lm.acn.MappingFunctionDeclaration
465467

466468
let nUperMin, nUperMax =
467469
match uperRange with
@@ -470,6 +472,12 @@ let private createAcnIntegerFunctionInternal (r:Asn1AcnAst.AstRoot)
470472
| PosInf(a) -> a, r.args.IntMax (a>=0I)
471473
| Full -> r.args.SIntMin, r.args.SIntMax
472474

475+
let userDefinedFunctions =
476+
match soMF with
477+
| None -> []
478+
| Some s ->
479+
[UserMappingFunction (mappingFunctionDeclaration typeName s)]
480+
473481
let funcBody (errCode:ErrorCode)
474482
(acnArgs: (AcnGenericTypes.RelativePath*AcnGenericTypes.AcnParameter) list)
475483
(nestingScope: NestingScope)
@@ -544,7 +552,7 @@ let private createAcnIntegerFunctionInternal (r:Asn1AcnAst.AstRoot)
544552
let icdFnc fieldName sPresent comments =
545553
[{IcdRow.fieldName = fieldName; comments = comments; sPresent=sPresent;sType=(IcdPlainType "INTEGER"); sConstraint=sAsn1Constraints; minLengthInBits = acnMinSizeInBits ;maxLengthInBits=acnMaxSizeInBits;sUnits=unitsOfMeasure; rowType = IcdRowType.FieldRow; idxOffset = None}], []
546554
let icd = {IcdArgAux.canBeEmbedded = true; baseAsn1Kind = "INTEGER"; rowsFunc = icdFnc; commentsForTas=[]; scope="type"; name= None}
547-
Some ({AcnFuncBodyResult.funcBody = funcBodyContent; errCodes = errCodes; localVariables = []; bValIsUnReferenced= bValIsUnReferenced; bBsIsUnReferenced=bBsIsUnReferenced; resultExpr = resultExpr; auxiliaries = []; icdResult=Some icd})
555+
Some ({AcnFuncBodyResult.funcBody = funcBodyContent; errCodes = errCodes; localVariables = []; bValIsUnReferenced= bValIsUnReferenced; bBsIsUnReferenced=bBsIsUnReferenced; resultExpr = resultExpr; auxiliaries = []; userDefinedFunctions=userDefinedFunctions; icdResult=Some icd})
548556
funcBody
549557

550558
let getMappingFunctionModule (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (soMapFuncName:string option) =
@@ -559,9 +567,10 @@ let getMappingFunctionModule (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (soMapFu
559567
| true -> Some (acn_a.rtlModuleName() )
560568
| false -> r.args.mappingFunctionsModule
561569

562-
let createAcnIntegerFunction (r:Asn1AcnAst.AstRoot) (deps: Asn1AcnAst.AcnInsertedFieldDependencies) (lm:LanguageMacros) (codec:CommonTypes.Codec) (typeId : ReferenceToType) (t:Asn1AcnAst.AcnInteger) (us:State) =
570+
let createAcnIntegerFunction (r:Asn1AcnAst.AstRoot) (deps: Asn1AcnAst.AcnInsertedFieldDependencies) (lm:LanguageMacros) (codec:CommonTypes.Codec) (typeId : ReferenceToType) (t:Asn1AcnAst.AcnInteger) (typeName:string) (us:State) =
563571
let errCodeName = ToC ("ERR_ACN" + (codec.suffix.ToUpper()) + "_" + ((typeId.AcnAbsPath |> Seq.skip 1 |> Seq.StrJoin("-")).Replace("#","elm")))
564572
let errCode, ns = getNextValidErrorCode us errCodeName None
573+
565574

566575
let uperFuncBody (errCode) (nestingScope: NestingScope) (p:CodegenScope) (fromACN: bool) =
567576
DAstUPer.getIntfuncBodyByCons r lm codec t.uperRange t.Location (getAcnIntegerClass r.args t) (t.cons) (t.cons@t.withcons) typeId errCode nestingScope p
@@ -577,7 +586,7 @@ let createAcnIntegerFunction (r:Asn1AcnAst.AstRoot) (deps: Asn1AcnAst.AcnInserte
577586
let sAsn1Constraints = None
578587
let unitsOfMeasure = None
579588

580-
let funcBody = createAcnIntegerFunctionInternal r lm codec t.uperRange t.intClass t.acnEncodingClass uperFuncBody sAsn1Constraints t.acnMinSizeInBits t.acnMaxSizeInBits unitsOfMeasure (soMapFunc, soMapFunMod)
589+
let funcBody = createAcnIntegerFunctionInternal r lm codec t.uperRange t.intClass t.acnEncodingClass uperFuncBody sAsn1Constraints t.acnMinSizeInBits t.acnMaxSizeInBits unitsOfMeasure typeName (soMapFunc, soMapFunMod)
581590
(funcBody errCode), ns
582591

583592

@@ -588,6 +597,7 @@ let createIntegerFunction (r:Asn1AcnAst.AstRoot) (deps: Asn1AcnAst.AcnInsertedFi
588597
| "" -> None
589598
| _ -> Some sTmpCons
590599

600+
let typeName = typeDefinition.longTypedefName2 lm.lg.hasModules
591601
let soMapFunMod, soMapFunc =
592602
match o.acnProperties.mappingFunction with
593603
| Some (MappingFunction (soMapFunMod, mapFncName)) ->
@@ -596,7 +606,7 @@ let createIntegerFunction (r:Asn1AcnAst.AstRoot) (deps: Asn1AcnAst.AcnInsertedFi
596606
| None -> getMappingFunctionModule r lm soMapFunc, soMapFunc
597607
| Some soMapFunMod -> Some soMapFunMod.Value, soMapFunc
598608
| None -> None, None
599-
let funcBodyOrig = createAcnIntegerFunctionInternal r lm codec o.uperRange o.intClass o.acnEncodingClass uperFunc.funcBody_e sAsn1Constraints t.acnMinSizeInBits t.acnMaxSizeInBits t.unitsOfMeasure (soMapFunc, soMapFunMod)
609+
let funcBodyOrig = createAcnIntegerFunctionInternal r lm codec o.uperRange o.intClass o.acnEncodingClass uperFunc.funcBody_e sAsn1Constraints t.acnMinSizeInBits t.acnMaxSizeInBits t.unitsOfMeasure typeName (soMapFunc, soMapFunMod)
600610
let funcBody (errCode: ErrorCode)
601611
(acnArgs: (AcnGenericTypes.RelativePath*AcnGenericTypes.AcnParameter) list)
602612
(nestingScope: NestingScope)

BackendAst/DAstConstruction.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ let private mapAcnParameter (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedF
3535
}, ns1
3636

3737
let private createAcnChild (r:Asn1AcnAst.AstRoot) (icdStgFileName:string) (deps:Asn1AcnAst.AcnInsertedFieldDependencies) (lm:LanguageMacros) (m:Asn1AcnAst.Asn1Module) (ch:Asn1AcnAst.AcnChild) (us:State) =
38-
38+
39+
let tdBodyWithinSeq = DAstACN.getDeterminantTypeDefinitionBodyWithinSeq r lm (Asn1AcnAst.AcnChildDeterminant ch)
3940
let acnAlignment =
4041
match ch.Type with
4142
| Asn1AcnAst.AcnInteger a -> a.acnAlignment
@@ -46,7 +47,7 @@ let private createAcnChild (r:Asn1AcnAst.AstRoot) (icdStgFileName:string) (deps:
4647

4748
let funcBodyEncode, ns1=
4849
match ch.Type with
49-
| Asn1AcnAst.AcnInteger a -> DAstACN.createAcnIntegerFunction r deps lm Codec.Encode ch.id a us
50+
| Asn1AcnAst.AcnInteger a -> DAstACN.createAcnIntegerFunction r deps lm Codec.Encode ch.id a tdBodyWithinSeq us
5051
| Asn1AcnAst.AcnBoolean a -> DAstACN.createAcnBooleanFunction r deps lm Codec.Encode ch.id a us
5152
| Asn1AcnAst.AcnNullType a -> DAstACN.createAcnNullTypeFunction r deps lm Codec.Encode ch.id a us
5253
| Asn1AcnAst.AcnReferenceToEnumerated a -> DAstACN.createAcnEnumeratedFunction r deps icdStgFileName lm Codec.Encode ch.id a (defOrRef r m a) us
@@ -70,7 +71,6 @@ let private createAcnChild (r:Asn1AcnAst.AstRoot) (icdStgFileName:string) (deps:
7071
let retFunc = DAstACN.handleSavePosition funBodyWithState ch.Type.savePosition (ToC ch.Name.Value) lvName ch.id lm codec
7172
retFunc emptyState {ErrorCode.errCodeName = ""; ErrorCode.errCodeValue=0; comment=None} prms nestingScope p |> fst
7273

73-
let tdBodyWithinSeq = DAstACN.getDeterminantTypeDefinitionBodyWithinSeq r lm (Asn1AcnAst.AcnChildDeterminant ch)
7474
let initExpression =
7575
match ch.Type with
7676
| Asn1AcnAst.AcnInteger _ -> "0"

CommonTypes/AbstractMacros.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ Generated by the C stg macros with the following command
369369
abstract member EmitEncodingSizeConstants : sTypeDefName:string -> nMaxBytesInACN:BigInteger -> nMaxBitsInACN:BigInteger -> string;
370370
abstract member EmitTypeAssignment_primitive_def : sVarName:string -> sStar:string -> sFuncName:string -> sTypeDefName:string -> arrsErrcodes:seq<string> -> bEmptyEncodingSpace:bool -> nMaxBytesInACN:BigInteger -> nMaxBitsInACN:BigInteger -> arrsAcnPrms:seq<string> -> soSparkAnnotations:string option -> codec:Codec -> string;
371371
abstract member EmitTypeAssignment_primitive : sVarName:string -> sStar:string -> sFuncName:string -> soIValidFuncName:string option -> sTypeDefName:string -> arrsLocalVariables:seq<string> -> sContent:string -> soSparkAnnotations:string option -> sInitialExp:string -> arrsAcnPrms:seq<string> -> arrsAcnParamNames:seq<string> -> bEmptyEncodingSpace:bool -> bBsIsUnreferenced:bool -> bVarNameIsUnreferenced:bool -> soInitFuncName:string option -> arrsAnnots:seq<string> -> arrsPrecond:seq<string> -> soPostcond:string option -> codec:Codec -> string;
372+
abstract member MappingFunctionDeclaration : sTypeName:string -> sMF:string -> string;
372373
abstract member alignToNext : sMainBody:string -> sAlignmentValue:string -> nAlignmentValue:BigInteger -> nAbsOffset:BigInteger -> nRemainingMinBits:BigInteger -> nLevel:BigInteger -> nIx:BigInteger -> nOffset:BigInteger -> codec:Codec -> string;
373374
abstract member PositiveInteger_ConstSize : p:string -> sSsuffix:string -> sErrCode:string -> nFixedSize:BigInteger -> soMF:string option -> soMFM:string option -> nUperMin:BigInteger -> nUperMax:BigInteger -> codec:Codec -> string;
374375
abstract member PositiveInteger_ConstSize_8 : p:string -> sSsuffix:string -> sErrCode:string -> soMF:string option -> soMFM:string option -> nUperMin:BigInteger -> nUperMax:BigInteger -> codec:Codec -> string;

CommonTypes/AcnGenericTypes.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ type PostEncodingFunction =
311311
type PreDecodingFunction =
312312
| PreDecodingFunction of (StringLoc option)*StringLoc
313313

314+
type UserDefinedFunction =
315+
| UserMappingFunction of string
316+
| UserPostEncodingFunction of string
317+
| UserPreDecodingFunction of string
314318

315319
type IntegerAcnProperties = {
316320
encodingProp : AcnIntEncoding option

FrontEndAst/DAst.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ type AcnFuncBodyResult = {
485485
resultExpr : string option
486486
auxiliaries : string list
487487
icdResult : IcdArgAux option
488+
userDefinedFunctions : UserDefinedFunction list
488489
}
489490

490491
type XERFuncBodyResult = {

StgAda/acn_a.stg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ end if;
157157
MFen(soMF, soMFM, p) /*nogen*/ ::= "<if(soMF)><soMFM>.<soMF>_encode(<p>)<else><p><endif>"
158158

159159

160+
MappingFunctionDeclaration(sTypeName, sMF) ::= <<
161+
>>
162+
163+
160164
alignToNext_encode(sMainBody, sAlignmentValue, nAlignmentValue, nAbsOffset, nRemainingMinBits, nLevel, nIx, nOffset) ::= <<
161165
--align to next <sAlignmentValue>
162166
if (bs.Current_Bit_Pos mod <nAlignmentValue>) /= 0 then

StgC/acn_c.stg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ flag <sFuncName>(<sTypeDefName><sStar> <sVarName>, BitStream* pBitStrm, int* pEr
9898

9999

100100

101+
102+
103+
101104
A(sErrCode) /*nogen*/ ::= "*pErrCode = ret ? 0 : <sErrCode>;"
102105

103106
MF(soMF) ::= /*nogen*/ <<
@@ -109,6 +112,9 @@ if (ret) {
109112
<endif>
110113
>>
111114

115+
MappingFunctionDeclaration(sTypeName, sMF) ::= <<
116+
extern <sTypeName> <sMF>_decode(<sTypeName>);
117+
>>
112118

113119

114120

StgScala/acn_scala.stg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
group scala_acn;
22

3+
4+
35
getStringSize(p) ::= "ULong.fromRaw(<p>.indexOfOrLength(0x00.toRawUByte))"
46

57
getSizeableSize(p, sAcc, bIsUnsigned) ::= <<
@@ -89,6 +91,9 @@ MF(soMF) ::= /*nogen*/ <<
8991
<endif>
9092
>>
9193

94+
MappingFunctionDeclaration(sTypeName, sMF) ::= <<
95+
>>
96+
9297
loopFixedItem (i, fixedSize, sInternalItem)::= /*nogen*/ <<
9398
<i> = 0
9499
(while (<i> \< <fixedSize>.toInt) {

0 commit comments

Comments
 (0)