Skip to content

Commit

Permalink
Генерация неиспользуемого двоичного RASL’а (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazdaywik committed Mar 9, 2018
1 parent aa670b9 commit ae7a846
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 25 deletions.
5 changes: 5 additions & 0 deletions Sources/Compiler/.Config/config-work.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
-exec:-e
)

-tune-be:CppSR-RASL
(
-dir:~Cpp-01-RASL
)

-tune-be:CppSR
(
-dir:~Cpp-01
Expand Down
2 changes: 1 addition & 1 deletion Sources/Compiler/BE-CppSR/MCompiler.mref
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $IMPORT MProfiler;
$ENTRY Generate
t.hIModule e.OutName '.cpp' =
<Generate-Aux
<BE-CppSR::MRASL::Generate
<BE-CppSR::MRASL::Generate-Src
t.hIModule e.OutName '.rasl.cpp'
>
e.OutName
Expand Down
23 changes: 21 additions & 2 deletions Sources/Compiler/BE-CppSR/MInit.mref
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@ $MODULE BE-CppSR::MInit;
$IMPORT Config::MConfig;
$IMPORT BE-CppSR::MCompiler;
$IMPORT BE-CppSR::MLinker;
$IMPORT BE-CppSR::MRASL;

$IMPORT MHelpers = Config::MHelpers;
$IMPORT MLambda;

$ENTRY Register
$ENTRY Register-RASL
t.Config (e.Directory) (e.Ext) e.Tunings =
<Config::MConfig::RegisterBackEnd
t.Config
BE-CppSR-RASL
& BE-CppSR.MRASL.Generate
& Fake-RASL-Link
(e.Directory) (e.Ext)
>;

Fake-RASL-Link {
(e.PtProgName) e.Modules =
<MInOut::WriteLine 'fake link ' e.PtProgName>
Success;
}

$IMPORT MInOut;

$ENTRY Register-Native
t.Config (e.Directory) (e.Ext) e.Tunings =
<Config::MConfig::RegisterBackEnd
t.Config
Expand All @@ -20,7 +39,7 @@ $ENTRY Register
(e.Directory) (e.Ext)
>;

$ENTRY Extent = <MHelpers::GenExtent <Tunings>>;
$ENTRY Extent-Native = <MHelpers::GenExtent <Tunings>>;

Tunings =
(Single CCompiler ('compiler') 'call call-C++.bat')
Expand Down
67 changes: 48 additions & 19 deletions Sources/Compiler/BE-CppSR/MRASL.mref
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,38 @@ $IMPORT MMath;
$IMPORT MQualifiedName;
$IMPORT MStrings;


/**
<Generate t.hIModule e.OutName>
== t.hIModule
*/
$ENTRY Generate {
t.hIModule e.OutName =
t.hIModule e.OutName = <Generate-Aux t.hIModule &CreateBinary e.OutName>;
}

CreateBinary {
(e.OutName) e.RaslCode =
<MFileIO::Close
<MFileIO::Write
<MFileIO::Open 'bw' e.OutName>
<MStrings::Chr e.RaslCode>
>
>;
}


/**
<Generate-Src t.hIModule e.OutName>
== t.hIModule
*/
$ENTRY Generate-Src {
t.hIModule e.OutName = <Generate-Aux t.hIModule &CreateCpp e.OutName>;
}

Generate-Aux {
t.hIModule s.FnCreateFile e.OutName =
<CreateFile
(e.OutName)
(e.OutName) s.FnCreateFile
<MLambda::MapReduce
& GenerateEntity
<MIModule::GetEntityList t.hIModule>
Expand All @@ -24,36 +48,41 @@ $ENTRY Generate {
}

CreateFile {
(e.OutName) t.hIModule e.RaslCode =
(e.OutName) s.FnCreateFile t.hIModule e.RaslCode =
<CreateFile-EntryPoint
(e.OutName)
(e.OutName) s.FnCreateFile
<GenerateEntryCode <MIModule::GetEntryPoint t.hIModule>>
e.RaslCode
>;
}

CreateFile-EntryPoint {
(e.OutName) t.hIModule e.RaslCode =
(e.OutName) s.FnCreateFile t.hIModule e.RaslCode =
t.hIModule
<s.FnCreateFile
(e.OutName)
<GenBlock Start 'RASLCODE'>
<GenBlock
ConstTable
// cookies
<DWord 0> <DWord 0>
// external count, ident count, number count, string count
<DWord 0> <DWord 0> <DWord 0> <DWord 0>
// RASL length, external size, ident size, string size
<DWord 0> <DWord 0> <DWord 0> <DWord 0>
>
e.RaslCode
>;
}

CreateCpp {
(e.OutName) e.RaslCode =
<MFileIO::Save
(e.OutName)
('#include "refalrts.h"')
()
('static unsigned char bytes[] = {')
<MLambda::Map
&FormatByte
<GenBlock Start 'RASLCODE'>
<GenBlock
ConstTable
// cookies
<DWord 0> <DWord 0>
// external count, ident count, number count, string count
<DWord 0> <DWord 0> <DWord 0> <DWord 0>
// RASL length, external size, ident size, string size
<DWord 0> <DWord 0> <DWord 0> <DWord 0>
>
e.RaslCode
>
<MLambda::Map &FormatByte e.RaslCode>
(' 0')
('};')
()
Expand Down
13 changes: 10 additions & 3 deletions Sources/Compiler/Config/MLoad.mref
Original file line number Diff line number Diff line change
Expand Up @@ -873,12 +873,19 @@ SwTuneFEHandler {
//------------------------------------------------------------------------------

BackEndsTable =
(BE-CppSR-RASL
('CppSR-RASL')
((Relative) ('~CppSR-RASL'))
('rasl')
& BE-CppSR.MInit.Register-RASL
& ExtentNone
)
(BE-CppSR
('CppSR')
((Relative) ('~CppSR'))
('cpp')
& BE-CppSR.MInit.Register
& BE-CppSR.MInit.Extent
& BE-CppSR.MInit.Register-Native
& BE-CppSR.MInit.Extent-Native
)
(BE-ModuleIF
('ModuleIF')
Expand Down Expand Up @@ -921,7 +928,7 @@ ExtentNone = <MHelpers::GenExtent /* пусто */>;
ProfileBackEnd =
(Pr-Refal5 (BE-Refal5 BE-ModuleIF) ('Refal5') ('R5'))
(Pr-SimRef (BE-SimRef BE-ModuleIF) ('SimRef') ('SRefal') ('SR'))
(Pr-CppSR (BE-CppSR BE-ModuleIF) ('CPPSR') ('C++/SR'));
(Pr-CppSR (BE-CppSR BE-CppSR-RASL BE-ModuleIF) ('CPPSR') ('C++/SR'));

LookupDefault-BE-Ext
s.BackEndId =
Expand Down

0 comments on commit ae7a846

Please sign in to comment.