5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
7
7
* You may obtain a copy of the License at
8
- *
8
+ *
9
9
* http://www.apache.org/licenses/LICENSE-2.0
10
- *
10
+ *
11
11
* Unless required by applicable law or agreed to in writing, software
12
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -83,6 +83,7 @@ package ghidra.app.util.cparser.C;
83
83
84
84
import ghidra.program.model.data.*;
85
85
import ghidra.program.model.data.Enum;
86
+ import ghidra.program.model.lang.CompilerSpec;
86
87
import ghidra.util.Msg;
87
88
import ghidra.util.task.TaskMonitor;
88
89
import ghidra.util.InvalidNameException;
@@ -656,24 +657,42 @@ public class CParser {
656
657
* @param funcDT function data type to qualify
657
658
*/
658
659
private void applyFunctionQualifiers(Declaration dec, FunctionDefinition funcDT) {
659
- List<Integer> qualifierList = dec.getQualifiers();
660
- if (qualifierList.contains(NORETURN) ) {
661
- funcDT.setNoReturn(true);
662
- }
663
- // TODO: switch to setting calling convention by string identifier
664
- for (Integer qualifier : qualifierList) {
665
- switch (qualifier) {
666
- case CDECL:
667
- funcDT.setGenericCallingConvention(GenericCallingConvention.cdecl);
668
- break;
669
- case STDCALL:
670
- funcDT.setGenericCallingConvention(GenericCallingConvention.stdcall);
671
- break;
672
- case FASTCALL:
673
- funcDT.setGenericCallingConvention(GenericCallingConvention.fastcall);
674
- break;
675
- }
676
- }
660
+ List<Integer> qualifierList = dec.getQualifiers();
661
+ if (qualifierList.contains(NORETURN)) {
662
+ funcDT.setNoReturn(true);
663
+ }
664
+
665
+ String convention = null;
666
+ for (Integer qualifier : qualifierList) {
667
+ switch (qualifier) {
668
+ case CDECL:
669
+ convention = CompilerSpec.CALLING_CONVENTION_cdecl;
670
+ break;
671
+ case STDCALL:
672
+ convention = CompilerSpec.CALLING_CONVENTION_stdcall;
673
+ break;
674
+ case FASTCALL:
675
+ convention = CompilerSpec.CALLING_CONVENTION_fastcall;
676
+ break;
677
+ case VECTORCALL:
678
+ convention = CompilerSpec.CALLING_CONVENTION_vectorcall;
679
+ break;
680
+ case RUSTCALL:
681
+ convention = CompilerSpec.CALLING_CONVENTION_rustcall;
682
+ break;
683
+ case PASCALCALL:
684
+ convention = CompilerSpec.CALLING_CONVENTION_pascal;
685
+ break;
686
+ }
687
+ }
688
+ if (convention != null) {
689
+ try {
690
+ funcDT.setCallingConvention(convention);
691
+ }
692
+ catch (InvalidInputException e) {
693
+ // should not happen
694
+ }
695
+ }
677
696
}
678
697
679
698
private Integer getConstantValue (Object obj, int defaultValue) {
@@ -1164,8 +1183,6 @@ TOKEN :
1164
1183
|
1165
1184
<CONST : ( [ "_" ] )* "const">
1166
1185
|
1167
- <CDECL : ( [ "_" ] )+ "cdecl">
1168
- |
1169
1186
<DECLSPEC : "__declspec">
1170
1187
|
1171
1188
<PRAGMA : "#" "pragma"> {parenNesting=-1; SwitchTo(PRAGMALINE); }
@@ -1174,10 +1191,18 @@ TOKEN :
1174
1191
|
1175
1192
<READABLETO : "__readableTo">
1176
1193
|
1194
+ <CDECL : ( [ "_" ] )+ "cdecl">
1195
+ |
1177
1196
<STDCALL : ( [ "_" ] )+ "stdcall">
1178
1197
|
1179
1198
<FASTCALL : ( [ "_" ] )+ "fastcall">
1180
1199
|
1200
+ <VECTORCALL : ( [ "_" ] )+ "vectorcall">
1201
+ |
1202
+ <RUSTCALL : ( [ "_" ] )+ "rustcall">
1203
+ |
1204
+ <PASCALCALL : ( [ "_" ] )+ "pascal">
1205
+ |
1181
1206
<NORETURN : "_Noreturn" >
1182
1207
|
1183
1208
<ALIGNAS : "_Alignas" >
@@ -1799,6 +1824,9 @@ Declaration TypeQualifier(Declaration dec) : {}
1799
1824
<FAR> |
1800
1825
<STDCALL> { dec.addQualifier(STDCALL); } |
1801
1826
<FASTCALL> { dec.addQualifier(FASTCALL); } |
1827
+ <VECTORCALL> { dec.addQualifier(VECTORCALL); } |
1828
+ <RUSTCALL> { dec.addQualifier(RUSTCALL); } |
1829
+ <PASCALCALL> { dec.addQualifier(PASCALCALL); } |
1802
1830
<NORETURN> { dec.addQualifier(NORETURN); } |
1803
1831
<W64> |
1804
1832
<PTR64> |
0 commit comments