Skip to content

Commit 432b8a3

Browse files
committed
feat: Scaffolding of the generator
1 parent 50f8c47 commit 432b8a3

File tree

4 files changed

+266
-0
lines changed

4 files changed

+266
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
unit Generate.Common;
2+
3+
{$mode ObjFPC}{$H+}
4+
5+
interface
6+
7+
uses
8+
Classes, SysUtils;
9+
10+
implementation
11+
12+
end.
13+

generator/Common/version.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'0.1'
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CONFIG>
3+
<ProjectOptions>
4+
<Version Value="12"/>
5+
<General>
6+
<Flags>
7+
<MainUnitHasCreateFormStatements Value="False"/>
8+
<MainUnitHasTitleStatement Value="False"/>
9+
<MainUnitHasScaledStatement Value="False"/>
10+
<CompatibilityMode Value="True"/>
11+
</Flags>
12+
<SessionStorage Value="InProjectDir"/>
13+
<Title Value="One Billion Row Challenge Generator"/>
14+
<UseAppBundle Value="False"/>
15+
<ResourceType Value="res"/>
16+
</General>
17+
<BuildModes Count="3">
18+
<Item1 Name="Default" Default="True"/>
19+
<Item2 Name="Debug">
20+
<CompilerOptions>
21+
<Version Value="11"/>
22+
<Target>
23+
<Filename Value="../../../bin/generator"/>
24+
</Target>
25+
<SearchPaths>
26+
<IncludeFiles Value="$(ProjOutDir);../../Common"/>
27+
<OtherUnitFiles Value="../../Common"/>
28+
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
29+
</SearchPaths>
30+
<Parsing>
31+
<SyntaxOptions>
32+
<IncludeAssertionCode Value="True"/>
33+
</SyntaxOptions>
34+
</Parsing>
35+
<CodeGeneration>
36+
<Checks>
37+
<IOChecks Value="True"/>
38+
<RangeChecks Value="True"/>
39+
<OverflowChecks Value="True"/>
40+
<StackChecks Value="True"/>
41+
</Checks>
42+
<VerifyObjMethodCallValidity Value="True"/>
43+
</CodeGeneration>
44+
<Linking>
45+
<Debugging>
46+
<DebugInfoType Value="dsDwarf3"/>
47+
<UseHeaptrc Value="True"/>
48+
<TrashVariables Value="True"/>
49+
<UseExternalDbgSyms Value="True"/>
50+
</Debugging>
51+
</Linking>
52+
</CompilerOptions>
53+
</Item2>
54+
<Item3 Name="Release">
55+
<CompilerOptions>
56+
<Version Value="11"/>
57+
<Target>
58+
<Filename Value="../../../bin/generator"/>
59+
</Target>
60+
<SearchPaths>
61+
<IncludeFiles Value="$(ProjOutDir);../../Common"/>
62+
<OtherUnitFiles Value="../../Common"/>
63+
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
64+
</SearchPaths>
65+
<CodeGeneration>
66+
<SmartLinkUnit Value="True"/>
67+
<Optimizations>
68+
<OptimizationLevel Value="3"/>
69+
</Optimizations>
70+
</CodeGeneration>
71+
<Linking>
72+
<Debugging>
73+
<GenerateDebugInfo Value="False"/>
74+
<RunWithoutDebug Value="True"/>
75+
</Debugging>
76+
<LinkSmart Value="True"/>
77+
</Linking>
78+
</CompilerOptions>
79+
</Item3>
80+
</BuildModes>
81+
<PublishOptions>
82+
<Version Value="2"/>
83+
<UseFileFilters Value="True"/>
84+
</PublishOptions>
85+
<RunParams>
86+
<FormatVersion Value="2"/>
87+
</RunParams>
88+
<Units Count="2">
89+
<Unit0>
90+
<Filename Value="generator.lpr"/>
91+
<IsPartOfProject Value="True"/>
92+
</Unit0>
93+
<Unit1>
94+
<Filename Value="../../Common/generate.common.pas"/>
95+
<IsPartOfProject Value="True"/>
96+
<UnitName Value="Generate.Common"/>
97+
</Unit1>
98+
</Units>
99+
</ProjectOptions>
100+
<CompilerOptions>
101+
<Version Value="11"/>
102+
<Target>
103+
<Filename Value="../../../bin/generator"/>
104+
</Target>
105+
<SearchPaths>
106+
<IncludeFiles Value="$(ProjOutDir);../../Common"/>
107+
<OtherUnitFiles Value="../../Common"/>
108+
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
109+
</SearchPaths>
110+
</CompilerOptions>
111+
<Debugging>
112+
<Exceptions Count="3">
113+
<Item1>
114+
<Name Value="EAbort"/>
115+
</Item1>
116+
<Item2>
117+
<Name Value="ECodetoolError"/>
118+
</Item2>
119+
<Item3>
120+
<Name Value="EFOpenError"/>
121+
</Item3>
122+
</Exceptions>
123+
</Debugging>
124+
</CONFIG>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
program generator;
2+
3+
{$mode objfpc}{$H+}
4+
5+
uses
6+
{$IFDEF UNIX}
7+
cthreads,
8+
{$ENDIF}
9+
Classes
10+
, SysUtils
11+
, CustApp
12+
, Generate.Common
13+
;
14+
15+
const
16+
cVersion = {$I version.inc};
17+
cSeed: LongInt = 46668267; // '1BRC' in ASCII
18+
19+
cShortOptHelp = 'h';
20+
cLongOptHelp = 'help';
21+
cShortOptVersion = 'v';
22+
cLongOptVersion = 'version';
23+
cShortOptInput = 'i:';
24+
cLongOptInput = 'input-file:';
25+
cShortOptOutput = 'o:';
26+
cLongOptOutput = 'output-file:';
27+
cShortOptNumner = 'n:';
28+
cLongOptNumber = 'line-count:';
29+
30+
type
31+
32+
{ TOneBRCGenerator }
33+
34+
TOneBRCGenerator = class(TCustomApplication)
35+
private
36+
protected
37+
procedure DoRun; override;
38+
public
39+
constructor Create(TheOwner: TComponent); override;
40+
destructor Destroy; override;
41+
procedure WriteHelp; virtual;
42+
published
43+
end;
44+
45+
{ TOneBRCGenerator }
46+
47+
procedure TOneBRCGenerator.DoRun;
48+
var
49+
ErrorMsg: String;
50+
begin
51+
// quick check parameters
52+
ErrorMsg:= CheckOptions(Format('%s%s%s%s%s',[
53+
cShortOptHelp,
54+
cShortOptVersion,
55+
cShortOptInput,
56+
cShortOptOutput,
57+
cShortOptNumner
58+
]),
59+
[
60+
cLongOptHelp,
61+
cLongOptVersion,
62+
cLongOptInput,
63+
cLongOptOutput,
64+
cLongOptNumber
65+
]
66+
);
67+
if ErrorMsg<>'' then begin
68+
//ShowException(Exception.Create(ErrorMsg));
69+
WriteLn(ErrorMsg);
70+
Terminate;
71+
Exit;
72+
end;
73+
74+
// parse parameters
75+
if HasOption(cShortOptHelp, cLongOptHelp) then begin
76+
WriteHelp;
77+
Terminate;
78+
Exit;
79+
end;
80+
81+
if HasOption(cShortOptVersion, cLongOptVersion) then begin
82+
WriteLn('generator v', cVersion);
83+
Terminate;
84+
Exit;
85+
end;
86+
87+
{ add your program here }
88+
89+
// stop program loop
90+
Terminate;
91+
end;
92+
93+
constructor TOneBRCGenerator.Create(TheOwner: TComponent);
94+
begin
95+
inherited Create(TheOwner);
96+
StopOnException:=True;
97+
end;
98+
99+
destructor TOneBRCGenerator.Destroy;
100+
begin
101+
inherited Destroy;
102+
end;
103+
104+
procedure TOneBRCGenerator.WriteHelp;
105+
begin
106+
{ add your help code here }
107+
WriteLn('Generates the measurement file with the specified number of lines');
108+
WriteLn;
109+
WriteLn('USAGE');
110+
WriteLn(' generator <flags>');
111+
WriteLn;
112+
WriteLn('FLAGS');
113+
WriteLn(' -h|--help Writes this help message and exits');
114+
WriteLn(' -v|--version Writes the version and exits');
115+
WriteLn(' -i|--input-file <filename> The file containing the Weather Stations');
116+
WriteLn(' -o|--output-file <filename> The file that will contain the generated lines');
117+
WriteLn(' -n|--line-count <number> The amount of lines to be generated');
118+
end;
119+
120+
var
121+
Application: TOneBRCGenerator;
122+
begin
123+
Application:=TOneBRCGenerator.Create(nil);
124+
Application.Title:='One Billion Row Challenge Generator';
125+
Application.Run;
126+
Application.Free;
127+
end.
128+

0 commit comments

Comments
 (0)