Changeset 6 for trunk/Compiler/Produce/UProducerDynamicC.pas
- Timestamp:
- Nov 5, 2010, 11:31:04 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Produce/UProducerDynamicC.pas
r5 r6 27 27 procedure GenerateProgram(ProgramBlock: TProgram); 28 28 procedure GenerateFunctions(Functions: TFunctionList; 29 Prefix: string = '' );29 Prefix: string = ''; HeaderOnly: Boolean = False); 30 30 procedure GenerateBeginEnd(BeginEnd: TBeginEnd); 31 31 procedure GenerateVariableList(VariableList: TVariableList); … … 36 36 procedure GenerateIfThenElse(IfThenElse: TIfThenElse); 37 37 procedure GenerateAssignment(Assignment: TAssignment); 38 procedure GenerateFunctionCall(FunctionCall: TFunctionCall);38 function GenerateFunctionCall(FunctionCall: TFunctionCall): string; 39 39 function GenerateExpression(Expression: TExpression): string; 40 40 public … … 55 55 begin 56 56 TextSource := TStringList.Create; 57 FileExtension := '.c';58 57 IndentationLength := 2; 59 58 end; … … 119 118 procedure TProducerDynamicC.GenerateModule(Module: TModule); 120 119 begin 121 EmitLn('#use "platform.lib"');122 EmitLn;123 120 if Module is TModuleProgram then begin 121 Module.TargetFile := Module.Name + '.c'; 122 EmitLn('#use "platform.lib"'); 123 EmitLn; 124 124 TModuleProgram(Module).Body.Name := 'main'; 125 125 GenerateUses(TModuleProgram(Module).UsedModules); … … 127 127 end else 128 128 if Module is TModuleUnit then begin 129 Module.TargetFile := 'Lib\' + Module.Name + '.lib'; 130 EmitLn('/*** BeginHeader */'); 131 EmitLn('#ifndef ' + UpperCase(Module.Name) + '_H'); 132 EmitLn('#define ' + UpperCase(Module.Name) + '_H'); 133 EmitLn; 134 EmitLn('#use "platform.lib"'); 129 135 GenerateUses(TModuleProgram(Module).UsedModules); 136 GenerateTypes(TModuleUnit(Module).Body.Types); 137 EmitLn('/*** EndHeader */'); 138 EmitLn; 139 EmitLn('/*** BeginHeader */'); 140 GenerateFunctions(TModuleUnit(Module).Body.Functions, '', True); 141 EmitLn('/*** EndHeader */'); 142 EmitLn; 143 144 GenerateFunctions(TModuleUnit(Module).Body.Functions); 145 130 146 GenerateCommonBlock(TModuleUnit(Module).Body, ''); 147 148 EmitLn; 149 EmitLn('/*** BeginHeader */'); 150 EmitLn('#endif'); 151 EmitLn('/*** EndHeader */'); 131 152 end; 132 153 end; … … 150 171 151 172 procedure TProducerDynamicC.GenerateFunctions(Functions: TFunctionList; 152 Prefix: string = '' );173 Prefix: string = ''; HeaderOnly: Boolean = False); 153 174 var 154 175 I: Integer; … … 171 192 Line := Line + ')'; 172 193 EmitLn(Line); 173 GenerateBeginEnd(Code);194 if not HeaderOnly then GenerateBeginEnd(Code); 174 195 EmitLn; 175 196 end; … … 218 239 else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command)) 219 240 else if Command is TAssignment then GenerateAssignment(TAssignment(Command)) 220 else if Command is TFunctionCall then GenerateFunctionCall(TFunctionCall(Command));241 else if Command is TFunctionCall then EmitLn(GenerateFunctionCall(TFunctionCall(Command)) + ';'); 221 242 end; 222 243 … … 254 275 end; 255 276 256 procedure TProducerDynamicC.GenerateFunctionCall(FunctionCall: TFunctionCall);277 function TProducerDynamicC.GenerateFunctionCall(FunctionCall: TFunctionCall): string; 257 278 var 258 279 Line: string; … … 267 288 end; 268 289 end; 269 Line := Line + ') ;';270 EmitLn(Line);271 end;290 Line := Line + ')'; 291 end; 292 Result := Line; 272 293 end; 273 294 … … 285 306 end; 286 307 ntVariable: Result := Expression.Variable.Name; 287 ntFunction: Result := Expression.FunctionCall.Name;308 ntFunction: Result := GenerateFunctionCall(Expression.FunctionCall); 288 309 ntOperator: begin 289 310 Result := GenerateExpression(TExpression(Expression.SubItems.First)) … … 308 329 begin 309 330 with CommonBlock do begin 310 GenerateTypes(Types);311 GenerateFunctions(Functions);312 331 EmitLn('void ' + Name + '()'); 313 332 GenerateBeginEnd(Code);
Note:
See TracChangeset
for help on using the changeset viewer.