├── .gitignore
├── LICENSE
├── README.md
├── build.xml
├── demo
├── .gitignore
├── ex.lc
├── fib.lc
├── funlib.lc
├── funlibtest.c
├── hello.lc
├── hello
│ ├── Makefile
│ ├── README.txt
│ ├── boot.s
│ ├── grub.cfg
│ ├── hello.c
│ ├── hello.ld
│ ├── hello.llc
│ ├── lib.llc
│ ├── screenshot.png
│ ├── string.lc
│ ├── string.mil
│ └── vram.llc
├── needinit.lc
├── printfibs.c
├── priodemo.c
├── prioset.lc
├── program.lc
└── runtime.c
├── doc
└── syntax.md
├── lib
├── alloc.c
├── basic.mil
├── bit.llc
├── core.llc
├── core.mil
├── io.mil
├── ix.llc
├── noinline.mil
├── nonzero.llc
├── prelude.lc
├── prelude.mil
├── put.llc
├── selectionsort.llc
└── string.llc
├── milc
├── milc.bat
└── src
├── compiler
├── BuiltinPosition.java
├── CacheSource.java
├── Diagnostic.java
├── Failure.java
├── Handler.java
├── JavaSource.java
├── Lexer.java
├── LiterateSource.java
├── Phase.java
├── Position.java
├── SimpleHandler.java
├── Source.java
├── SourceLexer.java
├── SourcePosition.java
├── StdinSource.java
└── Warning.java
├── core
├── ApTypeExp.java
├── AtomImpId.java
├── BitSizeNotDeterminedFailure.java
├── BitdataConDefn.java
├── BitdataDefn.java
├── BitdataFieldExp.java
├── BitdataFieldsExp.java
├── BitdataRegionExp.java
├── BitdataTagbitsExp.java
├── ByteSizeNotDeterminedFailure.java
├── CfunConfusionFailure.java
├── ConidTypeExp.java
├── CoreDefn.java
├── CoreDefnSCC.java
├── CoreDefnSCCs.java
├── CoreDefns.java
├── CoreLexer.java
├── CoreParser.java
├── CoreProgram.java
├── CoreTokens.java
├── DataConDefn.java
├── DataDefn.java
├── ExtImpId.java
├── ExternalDecl.java
├── FieldSizeNotDeterminedFailure.java
├── GenImpId.java
├── InvalidWidthFailure.java
├── KFunExp.java
├── KPrimExp.java
├── KindAnnTypeExp.java
├── KindExp.java
├── KindMismatchFailure.java
├── KindSyntaxFailure.java
├── KindTest.java
├── LabTypeExp.java
├── LayoutLexer.java
├── LiteralOutOfRangeFailure.java
├── Loader.java
├── MissingFailure.java
├── MissingKindExp.java
├── MissingTypeExp.java
├── MultipleKindsSpecifiedFailure.java
├── NatArithOp.java
├── NatArithTypeExp.java
├── NatDivOp.java
├── NatLshlOp.java
├── NatMinusOp.java
├── NatMultOp.java
├── NatPlusOp.java
├── NatPowOp.java
├── NatShrOp.java
├── NatTypeExp.java
├── NoBitLevelRepresentationFailure.java
├── NoByteLevelRepresentationFailure.java
├── NoMaskTestPredicateFailure.java
├── NotInScopeTyconFailure.java
├── NotInScopeTyvarFailure.java
├── PosKindExp.java
├── PosTypeExp.java
├── PrimTyconDefn.java
├── ProgramTest.java
├── SelTypeExp.java
├── StaticAnalysis.java
├── StructDefn.java
├── StructFieldExp.java
├── StructRegionExp.java
├── SynonymDefn.java
├── SyntaxAnalysis.java
├── TooManyTyconArgsFailure.java
├── TopImpId.java
├── TupleTypeExp.java
├── TyconDefn.java
├── TyconTypeExp.java
├── TypeExp.java
├── TypeParamSyntaxFailure.java
├── TypeSyntaxFailure.java
├── TypeTest.java
├── UndeterminedBitPatternFailure.java
└── VaridTypeExp.java
├── debug
├── Internal.java
├── Log.java
└── Screen.java
├── driver
├── Main.java
└── OptionSource.java
├── lc
├── AreaDefn.java
├── AreaVar.java
├── AtomCont.java
├── Binding.java
├── BindingSCC.java
├── BindingSCCs.java
├── Bindings.java
├── BindingsEnv.java
├── BitdataRequiredFailure.java
├── CGEnv.java
├── CGEnvVar.java
├── CGEnvVars.java
├── ConstructorArgsFailure.java
├── DecVar.java
├── DefVar.java
├── DefVars.java
├── EAlt.java
├── EAp.java
├── ECase.java
├── EConstruct.java
├── EDo.java
├── EFatbar.java
├── EField.java
├── EFrom.java
├── EId.java
├── ELam.java
├── ELet.java
├── ELit.java
├── EPatAlt.java
├── ESelect.java
├── EType.java
├── EUpdate.java
├── EVar.java
├── EVarAlt.java
├── Entrypoint.java
├── Env.java
├── EqField.java
├── Equation.java
├── Export.java
├── Expr.java
├── FreshVar.java
├── FromField.java
├── IndentOutput.java
├── InitBitdataFieldExp.java
├── InitStructFieldExp.java
├── InvalidRecursiveDefinition.java
├── LCBlock.java
├── LCClosureDefn.java
├── LCDefn.java
├── LCDefns.java
├── LCLexer.java
├── LCLoader.java
├── LCParser.java
├── LCProgram.java
├── LCProgramSCC.java
├── LCProgramSCCs.java
├── LCPrograms.java
├── LCTokens.java
├── LamVar.java
├── LiftEnv.java
├── Lifting.java
├── MultipleBindingDefnsFailure.java
├── MultipleSignaturesFailure.java
├── NotInScopeFailure.java
├── ParseFailure.java
├── PosExpr.java
├── PunField.java
├── SignatureWithoutBindingFailure.java
├── TVISBSCC.java
├── TVISVar.java
├── TVISVars.java
├── TVarsInScope.java
├── TailCont.java
├── TopBinding.java
├── TopBindings.java
├── TopDefn.java
├── TopDefns.java
├── TypeAnn.java
├── UnknownConstructorFailure.java
├── Var.java
├── VarEnv.java
├── VarsEnv.java
└── VisDecl.java
├── llvm
├── Alias.java
├── ArrayType.java
├── BinOp.java
├── Bitcast.java
├── Bool.java
├── Call.java
├── CallVoid.java
├── Cast.java
├── Code.java
├── CodeComment.java
├── Cond.java
├── Constant.java
├── DefinedType.java
├── Defn.java
├── DefnComment.java
├── Defns.java
├── Eval.java
├── Expr.java
├── ExtractValue.java
├── FuncDecl.java
├── FuncDefn.java
├── FunctionType.java
├── Getelementptr.java
├── Global.java
├── GlobalVarDecl.java
├── GlobalVarDefn.java
├── Goto.java
├── ICmp.java
├── IOp.java
├── Index.java
├── InsertValue.java
├── IntToPtr.java
├── Load.java
├── Local.java
├── Location.java
├── Mods.java
├── Null.java
├── Op.java
├── Phi.java
├── Program.java
├── PtrToInt.java
├── Ret.java
├── RetVoid.java
├── Rhs.java
├── Store.java
├── StringInitializer.java
├── Struct.java
├── StructType.java
├── Switch.java
├── Trunc.java
├── Type.java
├── Typedef.java
├── Undef.java
├── Value.java
├── Word.java
├── ZeroInitializer.java
└── Zext.java
├── mil
├── AddrMap.java
├── AllocType.java
├── Allocator.java
├── AltExp.java
├── Alts.java
├── Annotation.java
├── Any.java
├── Area.java
├── AreaDefnExp.java
├── Assert.java
├── AssertExp.java
├── Atom.java
├── AtomExp.java
├── AtomImp.java
├── Bind.java
├── BindExp.java
├── BitdataField.java
├── BitdataLayout.java
├── BitdataMap.java
├── BitdataRep.java
├── BitdataType.java
├── Bits.java
├── Block.java
├── BlockCFG.java
├── BlockCall.java
├── BlockCallExp.java
├── BlockCalls.java
├── BlockDefnExp.java
├── BlockType.java
├── BlockTypeAnn.java
├── BlockWithCont.java
├── BlockWithDuplicateArgs.java
├── BlockWithEnter.java
├── BlockWithKnownCons.java
├── Blocks.java
├── BoolValue.java
├── Builtin.java
├── CFG.java
├── CFGs.java
├── Call.java
├── CallExp.java
├── CallLabel.java
├── CannotSatisfyFailure.java
├── Case.java
├── CaseExp.java
├── Cfun.java
├── CfunAlt.java
├── ClosAlloc.java
├── ClosAllocExp.java
├── ClosAllocs.java
├── ClosureDefn.java
├── ClosureDefnCFG.java
├── ClosureDefnExp.java
├── ClosureDefnWithKnownCons.java
├── ClosureDefns.java
├── ClosureTypeAnn.java
├── Code.java
├── CodeExp.java
├── CodeLabel.java
├── Const.java
├── DataAlloc.java
├── DataAllocExp.java
├── DataName.java
├── DataType.java
├── DataTypes.java
├── DataValue.java
├── DebugTypeWriter.java
├── DefAlt.java
├── Defn.java
├── DefnExp.java
├── DefnExps.java
├── DefnSCC.java
├── DefnSCCs.java
├── DefnVarMap.java
├── Defns.java
├── DerivedBlock.java
├── Done.java
├── DoneExp.java
├── Enter.java
├── EnterExp.java
├── Entrypoint.java
├── Export.java
├── ExtImp.java
├── External.java
├── Facts.java
├── FailAlt.java
├── Flag.java
├── Forall.java
├── GenImp.java
├── GeneratorException.java
├── GotoLabel.java
├── HashAddrMap.java
├── If.java
├── IfExp.java
├── InitCFG.java
├── InitVarMap.java
├── Join.java
├── KAtom.java
├── KFun.java
├── KVar.java
├── Kind.java
├── KindMismatchException.java
├── LLVMMap.java
├── Label.java
├── Labels.java
├── LinearEqn.java
├── LinearEqnTest.java
├── LinearEqns.java
├── LitExp.java
├── MILAST.java
├── MILASTSCC.java
├── MILASTSCCs.java
├── MILASTs.java
├── MILEnv.java
├── MILEnvChain.java
├── MILEnvHash.java
├── MILLexer.java
├── MILLoader.java
├── MILParser.java
├── MILProgram.java
├── MILSpec.java
├── MILTokens.java
├── Machine.java
├── MachineBuilder.java
├── MemArea.java
├── MergeMap.java
├── MultipleSolutionsFailure.java
├── MultipleTyconDefnsFailure.java
├── MultipleTyvarDefnsFailure.java
├── Name.java
├── NewtypeTypeSet.java
├── Node.java
├── OccursCheckException.java
├── PolyAllocType.java
├── PolyBlockType.java
├── PolymorphicEntrypointFailure.java
├── PredNodes.java
├── Prefix.java
├── PrefixTypeWriter.java
├── PrevTyconDefnFailure.java
├── Prim.java
├── PrimBinFOp.java
├── PrimBinOp.java
├── PrimCall.java
├── PrimCallExp.java
├── PrimCmpOp.java
├── PrimDefnExp.java
├── PrimFtoW.java
├── PrimNop.java
├── PrimRelOp.java
├── PrimSCmpOp.java
├── PrimSing.java
├── PrimTycon.java
├── PrimUCmpOp.java
├── PrimUnFOp.java
├── PrimUnOp.java
├── PrimWtoF.java
├── Prims.java
├── Proxy.java
├── ProxyLab.java
├── ProxyNat.java
├── Ptr.java
├── RepEnv.java
├── RepTypeSet.java
├── Return.java
├── ReturnExp.java
├── Scheme.java
├── Sel.java
├── SelExp.java
├── SpecBlock.java
├── SpecClosureDefn.java
├── SpecEnv.java
├── SpecExternal.java
├── SpecMemArea.java
├── SpecReq.java
├── SpecReqs.java
├── SpecTopLevel.java
├── Src.java
├── StringArea.java
├── StringAreaDefnExp.java
├── StringTypeWriter.java
├── StructField.java
├── StructType.java
├── Synonym.java
├── TAp.java
├── TConst.java
├── TGen.java
├── TGenCorresp.java
├── TInd.java
├── TIndAllocType.java
├── TIndBlockType.java
├── TLab.java
├── TLit.java
├── TNat.java
├── TTycon.java
├── TVar.java
├── TVarSubst.java
├── TVars.java
├── Tail.java
├── TailExp.java
├── Tails.java
├── Temp.java
├── TempEnv.java
├── TempSubst.java
├── Temps.java
├── Terms.java
├── Top.java
├── TopArea.java
├── TopDef.java
├── TopDefn.java
├── TopExt.java
├── TopLevel.java
├── TopLevelExp.java
├── TopLevels.java
├── TopLhs.java
├── TopTypeAnn.java
├── TupleCon.java
├── Tycon.java
├── TyconEnv.java
├── Tycons.java
├── Type.java
├── TypeAnn.java
├── TypeMismatchException.java
├── TypeSet.java
├── TypeSpecs.java
├── TypeWriter.java
├── Types.java
├── Tyvar.java
├── TyvarEnv.java
├── Tyvars.java
├── UnifyException.java
├── Value.java
├── VarExp.java
├── VarMap.java
├── WidthsDifferFailure.java
├── Word.java
└── WordValue.java
└── obdd
├── ConstOBDD.java
├── ITE.java
├── MaskTestPat.java
├── OBDD.java
└── Pat.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | *.o
3 | *.swp
4 | bin/
5 | tmp/
6 | local/
7 | mil-tools.jar
8 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | fib.ll
2 | fib.s
3 | fib
4 |
--------------------------------------------------------------------------------
/demo/ex.lc:
--------------------------------------------------------------------------------
1 | require "prelude.lc"
2 | data Dup a = Dup a a
3 | entrypoint swap7 :: Dup (Bit 7) -> Dup (Bit 7)
4 | entrypoint swap8 :: Dup (Bit 8) -> Dup (Bit 8)
5 | swap7 = swap
6 | swap8 = swap
7 |
8 | swap d = case d of Dup x y -> Dup y x
9 |
10 | entrypoint d1
11 | d1 = Dup B001 B110
12 |
--------------------------------------------------------------------------------
/demo/fib.lc:
--------------------------------------------------------------------------------
1 | require "prelude.lc"
2 | require "io.mil"
3 |
4 | ------
5 |
6 | fib1 :: Word -> Word
7 | fib1 n = case eq n 0 of
8 | True -> 0
9 | False -> case eq n 1 of
10 | True -> 1
11 | False -> add (fib (sub n 1)) (fib (sub n 2))
12 |
13 | fib :: Word -> Word
14 | fib n = if eq n 0 then 0
15 | else if eq n 1 then 1
16 | else add (fib (sub n 1)) (fib (sub n 2))
17 |
18 | export main :: Proc Unit
19 | main = do printWord 91
20 | printWord (fib 12)
21 | printWord (fib1 12)
22 | printWord 17
23 |
24 | ------
25 |
--------------------------------------------------------------------------------
/demo/funlib.lc:
--------------------------------------------------------------------------------
1 | require "prelude.lc"
2 |
3 | -- A standard recursive version of the Fibonnaci function:
4 | entrypoint fib :: Word -> Word
5 | fib n = if eq n 0 then 0
6 | else if eq n 1 then 1
7 | else add (fib (sub n 1)) (fib (sub n 2))
8 |
9 | -- An iterative version of the Fibonnaci function:
10 | entrypoint itfib :: Word -> Word
11 | itfib = let loop a b n = if eq n 0 then a else loop b (add a b) (sub n 1)
12 | in loop 0 1
13 |
14 | -- A traditional recursive implementation of the factorial function:
15 | entrypoint recfac :: Word -> Word
16 | recfac n = if eq n 0 then 1 else mul n (recfac (sub n 1))
17 |
18 | -- An iterative version of the factorial function:
19 | entrypoint itfac :: Word -> Word
20 | itfac = let loop a n = if eq n 0 then a else loop (mul a n) (sub n 1)
21 | in loop 1
22 |
23 |
--------------------------------------------------------------------------------
/demo/funlibtest.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int fib(int);
4 | extern int itfib(int);
5 | extern int recfac(int);
6 | extern int itfac(int);
7 |
8 | int main(int argc, char** argv) {
9 | for (int i=0; i<10; i++) {
10 | printf("%d\t%d\t%d\t%d\t%d\n",
11 | i, fib(i), itfib(i), recfac(i), itfac(i));
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/demo/hello.lc:
--------------------------------------------------------------------------------
1 | require "io.mil"
2 |
3 | export main
4 | main = printString "hello, world\n"
5 |
--------------------------------------------------------------------------------
/demo/hello/grub.cfg:
--------------------------------------------------------------------------------
1 | set timeout=15
2 | #set default=0
3 |
4 | menuentry "Hello, kernel world" {
5 | multiboot /hello
6 | }
7 |
--------------------------------------------------------------------------------
/demo/hello/hello.ld:
--------------------------------------------------------------------------------
1 | OUTPUT_FORMAT(elf32-i386)
2 | ENTRY(entry)
3 |
4 | SECTIONS {
5 | . = 0x100000; /* Load hello at 1MB */
6 | .text : {
7 | _text_start = .; *(.multiboot) *(.text) _text_end = .;
8 | _data_start = .; *(.rodata) *(.data) _data_end = .;
9 | _bss_start = .; *(COMMON) *(.bss) _bss_end = .;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/demo/hello/hello.llc:
--------------------------------------------------------------------------------
1 | This file contains a recreation of the LLP "hello" demo in Habit/LC.
2 | It is a (very) simple client of the vram library for video RAM output
3 | on a PC:
4 |
5 | > require "vram.llc"
6 |
7 | The demo program just clears the screen and then displays two copies
8 | of a text greeting:
9 |
10 | > export hello
11 | > hello :: Proc Unit
12 | > hello = do clearScreen
13 | > greet
14 | > greet
15 |
16 | The greeting itself is produced by writing a sequence of strings on
17 | the screen:
18 |
19 | > greet = do puts "\nhhhh hhhh\n"
20 | > puts " hh hhh lll lll\n"
21 | > puts " hh hh eeee ll ll oooo\n"
22 | > puts " hhhhhhhh ee ee ll ll oo oo\n"
23 | > puts " hh hh eeeeeee ll ll oo oo\n"
24 | > puts " hh hh ee ll ll oo oo\n"
25 | > puts "hhh hhhh eeee ll ll oooo\n"
26 | > puts "\n"
27 | > puts " K e r n e l W o r l d\n"
28 | > puts "\n from LC and MIL\n"
29 |
30 |
--------------------------------------------------------------------------------
/demo/hello/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/habit-lang/mil-tools/b4e2e0d7508a22553a09efdce7b06e5a8a02e01a/demo/hello/screenshot.png
--------------------------------------------------------------------------------
/demo/hello/string.lc:
--------------------------------------------------------------------------------
1 | require "prelude.lc"
2 | require "string.mil"
3 |
4 | -- LC implementation for nextChar cursor function:
5 | external nextChar = nextCharImp :: Ref String -> Proc (Maybe (Pair Word (Ref String)))
6 |
7 | nextCharImp :: Ref String -> Proc (Maybe (Pair Word Word))
8 | nextCharImp r = do c <- loadChar r
9 | if eq c 0
10 | then return Nothing
11 | else return (Just (Pair c (add 1 (refToWord r))))
12 |
13 |
--------------------------------------------------------------------------------
/demo/hello/string.mil:
--------------------------------------------------------------------------------
1 | require "prelude.mil"
2 |
3 | -- MIL implementations of loadChar and refToWord for use in the LC
4 | -- definition of nextChar. Defining nextChar in LC is generally
5 | -- preferable to doing it in MIL. However, loadCharImp, at least,
6 | -- must currently be written in MIL so that we can access the load8
7 | -- primitive.
8 |
9 | export loadChar, refToWord
10 | external loadChar = loadCharImp :: Ref String -> Proc Word
11 | external refToWord = refToWordImp :: Ref a -> Word
12 |
13 | loadCharImp :: Addr -> Proc (Bit 8)
14 | loadCharImp <- {s} c <- loadCharImp1{s}; Proc(c)
15 | loadCharImp1{s} [] = load8((s))
16 |
17 | refToWordImp :: Word -> Word
18 | refToWordImp <- {w} return w
19 |
20 |
--------------------------------------------------------------------------------
/demo/needinit.lc:
--------------------------------------------------------------------------------
1 | require "prelude.lc"
2 |
3 | entrypoint fib :: Word -> Word
4 | fib n = if eq n 0 then 0
5 | else if eq n 1 then 1
6 | else add (fib (sub n 1)) (fib (sub n 2))
7 |
8 | entrypoint fib12, fib15
9 | fib12 = fib 12
10 | fib15 = fib 15
11 |
12 |
--------------------------------------------------------------------------------
/demo/printfibs.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern void initialize();
4 | extern int fib12, fib15;
5 |
6 | int main(int argc, char** argv) {
7 | initialize();
8 | printf("fib(12)=%d, fib(15)=%d\n", fib12, fib15);
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/demo/priodemo.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #ifdef WORD32
4 | typedef int word;
5 | #define WORD "%d"
6 | #else
7 | #ifndef WORD64
8 | #error "Please specify either -DWORD32 or -DWORD64 as a command line option"
9 | #endif
10 | typedef long word;
11 | #define WORD "%ld"
12 | #endif
13 |
14 | extern void initPrioset();
15 | extern void clearPrioset();
16 | extern void insertPriority(word);
17 | extern void removePriority(word);
18 | extern word highestPriority1();
19 |
20 | void add(word val) {
21 | printf("Inserting " WORD "\n", val);
22 | insertPriority(val);
23 | }
24 |
25 | void rem(word val) {
26 | printf("Removing " WORD "\n", val);
27 | removePriority(val);
28 | }
29 |
30 | int main(int argc, char** argv) {
31 | printf("Priority set demo\n");
32 | initPrioset();
33 |
34 | printf("Inserting some numbers:\n");
35 | add(12);
36 | add(5);
37 | add(7);
38 | add(128);
39 | add(67);
40 |
41 | printf("Removing three numbers:\n");
42 | for (int i=0; i<3; i++) {
43 | rem(highestPriority1());
44 | }
45 |
46 | printf("Adding some more numbers:\n");
47 | add(3);
48 | add(32);
49 | add(10);
50 |
51 | printf("Draining the queue:\n");
52 | word p;
53 | while ((p=highestPriority1())>=0) {
54 | rem(p);
55 | }
56 | printf("Done!\n");
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/demo/program.lc:
--------------------------------------------------------------------------------
1 | require "prelude.lc"
2 | require "io.mil"
3 |
4 | itfib :: Word -> Word
5 | itfib = let loop a b n = if eq n 0 then a else loop b (add a b) (sub n 1)
6 | in loop 0 1
7 |
8 | -- A program to print the 12th Fibonnaci number:
9 | export main
10 | main = printWord (itfib 12)
11 |
--------------------------------------------------------------------------------
/demo/runtime.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // A trivial run time library
4 |
5 | /* Provide an implementation for the printWord primitive. */
6 | void printWord(int x) {
7 | printf("%d\n", x);
8 | }
9 |
10 | /* Provide an implementation for the printString primitive. */
11 | void printString(char* s) {
12 | puts(s);
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/lib/alloc.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #ifdef WORD32
5 | typedef int word;
6 | #define WORD "%d"
7 | #else
8 | #ifndef WORD64
9 | #error "Please specify either -DWORD32 or -DWORD64 as a command line option"
10 | #endif
11 | typedef long word;
12 | #define WORD "%ld"
13 | #endif
14 |
15 | void* alloc(word size) {
16 | //printf("Allocating object of size " WORD "\n", size);
17 | return calloc(size, sizeof(word));
18 | }
19 |
--------------------------------------------------------------------------------
/lib/bit.llc:
--------------------------------------------------------------------------------
1 | > require "core.llc"
2 |
3 | A (currently underdeveloped) library for working with Bit vectors.
4 |
5 | > external bitBit {primBitBit n} :: Ix n -> Bit n
6 | > external bitSet {primBitSetBit n},
7 | > bitClear {primBitClearBit n},
8 | > bitFlip {primBitFlipBit n} :: Bit n -> Ix n -> Bit n
9 | > external bitTest {primBitTestBit n} :: Bit n -> Ix n -> Bool
10 |
11 | > export min, max :: Bit n -> Bit n -> Bit n
12 | > x `min` y = if y < x then y else x
13 | > x `max` y = if x < y then y else x
14 |
15 | > external bitl {primBitFromLiteral v n} :: ProxyNat v -> Bit n
16 | > external nzbitl {primNZBitFromLiteral v n} :: ProxyNat v -> NZBit n
17 |
18 | > export bit0, bit1, bit2 :: Bit n
19 | > bit0 = bitl#0
20 | > bit1 = bitl#1
21 | > bit2 = bitl#2
22 |
23 | > export bitDec :: Bit n -> Bit n
24 | > bitDec n = n - bit1
25 |
26 | > external bitsHi {primBitsHi n m} :: Bit n -> Bit m -- requires n>=m
27 | > external bitsLo {primBitsLo n m} :: Bit n -> Bit m -- requires n>=m
28 |
29 | > external fromBits {primBitToBitdata n bt} :: Bit n -> bt -- requires bitdata type bt
30 | > external toBits {primBitdataToBit bt n} :: bt -> Bit n -- requires bitdata type bt
31 |
32 |
--------------------------------------------------------------------------------
/lib/core.mil:
--------------------------------------------------------------------------------
1 | bitdata Bool = False [B0] | True [B1]
2 |
3 | -- Monadic primitives:
4 | export primRet :: a -> Proc a
5 | primRet <- {x} c <- ret1{x}; Proc(c)
6 | ret1{x} [] = return x
7 |
8 | -- Pairs and other tuples:
9 | data Pair a b = Pair a b
10 | data Tuple3 a b c = Tuple3 a b c
11 | data Tuple4 a b c d = Tuple4 a b c d
12 |
13 | -- Maybe:
14 | data Maybe a = Nothing | Just a
15 |
16 | -- Lists:
17 | data List a = Nil | Cons a (List a)
18 |
19 | -- Arithmetic primitives:
20 | export / :: Word -> Word -> Word
21 | / <- {x,y} div((x,y)) -- TODO: unsafe
22 |
23 | -- Bitwise operators:
24 |
25 | export shl, lshr, ashr :: Word -> Word -> Word
26 | shl <- {x,y} shl((x,y))
27 | lshr <- {x,y} lshr((x,y))
28 | ashr <- {x,y} ashr((x,y))
29 |
30 | -- Pointers/References:
31 |
32 | export refToWord, ptrToWord, physToWord
33 | external refToWord = ptrToWordImp :: Ref a -> Word
34 | external ptrToWord = ptrToWordImp :: Ptr a -> Word
35 | external physToWord = ptrToWordImp :: Phys a -> Word
36 |
37 | ptrToWordImp :: Word -> Word
38 | ptrToWordImp <- {w} return w
39 |
40 | -- Strings:
41 |
42 | -- MIL implementation of loadChar primitive; must currently be
43 | -- written in MIL so that we can access the load8 primitive.
44 |
45 | export loadChar
46 | external loadChar = loadCharImp :: Ref String -> Proc Word
47 |
48 | loadCharImp :: Addr -> Proc (Bit 8)
49 | loadCharImp <- {s} c <- loadCharImp1{s}; Proc(c)
50 | loadCharImp1{s} [] = load8((s))
51 |
52 |
--------------------------------------------------------------------------------
/lib/io.mil:
--------------------------------------------------------------------------------
1 | require "basic.mil"
2 |
3 | -- An impure primitive that returns its input as a result, but also
4 | -- prints that value on the console:
5 | export traceWord :: Word -> Word
6 | traceWord <- {w} [] <- printWord((w)); return w
7 |
8 | -- Packages the printWord MIL primitive as a monadic operation that
9 | -- can be accessed from LC:
10 | export printWord :: Word -> Proc Unit
11 | printWord <- {w} c <- printWord1{w}; Proc(c)
12 | printWord1{w} [] = [] <- printWord((w)); Unit()
13 |
14 | export printString
15 | external printString :: Ref String -> Proc Unit
16 |
17 |
--------------------------------------------------------------------------------
/lib/noinline.mil:
--------------------------------------------------------------------------------
1 | export noinline
2 | noinline :: Proc r -> Proc r
3 | noinline <- b[]
4 | b[] = x <- k{}; Func(x)
5 | k{} [p] = b1[p]
6 | b1[p] = y <- k1{p}; Proc(y)
7 | k1{p} [] = [] <- noinline(()); x <- Proc 0 p; x @ []
8 |
9 |
--------------------------------------------------------------------------------
/lib/nonzero.llc:
--------------------------------------------------------------------------------
1 | > require "core.llc"
2 |
3 | A (currently underdeveloped) library for working with NonZero Bit vectors.
4 |
5 | NonZero Values, Division, and Remainder:
6 |
7 | > external nzdiv {primNZBitDiv n} :: Bit n -> NZBit n -> Bit n
8 | > external nzrem {primNZBitRem n} :: Bit n -> NZBit n -> Bit n
9 |
10 | > external nz2u {primNZBitFromLiteral 2 n} :: Unit -> NZBit n
11 | > external nz8u {primNZBitFromLiteral 8 n} :: Unit -> NZBit n
12 | > external nz10u {primNZBitFromLiteral 10 n} :: Unit -> NZBit n
13 | > external nz16u {primNZBitFromLiteral 16 n} :: Unit -> NZBit n
14 |
15 | > export nz2, nz8, nz10, nz16
16 | > nz2 = nz2u Unit
17 | > nz8 = nz8u Unit
18 | > nz10 = nz10u Unit
19 | > nz16 = nz16u Unit
20 |
21 | > external nzbitForget {primNZBitForget n} :: NZBit n -> Bit n
22 |
23 |
--------------------------------------------------------------------------------
/lib/prelude.lc:
--------------------------------------------------------------------------------
1 | require "prelude.mil"
2 |
3 | export return :: a -> Proc a
4 | return = primRet
5 |
6 |
--------------------------------------------------------------------------------
/lib/prelude.mil:
--------------------------------------------------------------------------------
1 | require "basic.mil"
2 |
3 | -- Basic Datatypes:
4 | data List a = Nil | Cons a (List a)
5 | data Pair a b = Pair a b
6 | data Maybe a = Nothing | Just a
7 |
8 |
--------------------------------------------------------------------------------
/lib/string.llc:
--------------------------------------------------------------------------------
1 | > require "core.llc"
2 |
3 | A cursor for iterating through the characters of a
4 | null-terminated string:
5 |
6 | > external nextChar = nextCharImp
7 | > :: Ref String -> Proc (Maybe (Pair Word (Ref String)))
8 |
9 | > nextCharImp :: Ref String -> Proc (Maybe (Pair Word Word))
10 | > nextCharImp r = do c <- loadChar r
11 | > if c == 0
12 | > then return Nothing
13 | > else return (Just (Pair c (1 + refToWord r)))
14 |
15 | Some sample applications (which may or may not belong in a
16 | library like this):
17 |
18 | > foldString :: a -> (a -> Word -> Proc a) -> Ref String -> Proc a
19 | > foldString init step s = loop s init
20 | > where loop s a = case<- nextChar s of
21 | > Nothing -> return a
22 | > Just p -> do w <- step a (fst p)
23 | > loop (snd p) w
24 |
25 | > export length :: Ref String -> Proc Word
26 | > length = foldString 0 (\len c -> return (len + 1))
27 |
28 |
--------------------------------------------------------------------------------
/milc:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | java -jar mil-tools.jar $*
3 | exit $?
4 |
--------------------------------------------------------------------------------
/milc.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | java -jar mil-tools.jar %*
3 | exit /b %ERRORLEVEL%
4 |
5 |
--------------------------------------------------------------------------------
/src/compiler/BuiltinPosition.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package compiler;
20 |
21 | /** Provides a representation for the position of builtin entities. */
22 | public class BuiltinPosition extends Position {
23 |
24 | private BuiltinPosition() {}
25 |
26 | public static final BuiltinPosition pos = new BuiltinPosition();
27 |
28 | public String describe() {
29 | return "builtin";
30 | }
31 |
32 | public Position copy() {
33 | return pos;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/compiler/Failure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package compiler;
20 |
21 | /**
22 | * Represents an error diagnostic. To avoid a clash with java.lang.Error, we resist the temptation
23 | * to use the name "Error".
24 | */
25 | public class Failure extends Diagnostic {
26 |
27 | /** Default constructor. */
28 | public Failure(Position pos, String text) {
29 | super(pos, text);
30 | }
31 |
32 | /** Construct a failure with no associated position. */
33 | public Failure(String text) {
34 | super(text);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/compiler/Phase.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package compiler;
20 |
21 | /**
22 | * Base class for compiler phases. Its only real purpose is to provide convenient access to a
23 | * diagnostic handler.
24 | */
25 | public abstract class Phase {
26 |
27 | protected Handler handler;
28 |
29 | /** Construct a new phase with a specified diagnostic handler. */
30 | protected Phase(Handler handler) {
31 | this.handler = handler;
32 | }
33 |
34 | /** Return the handler for this phase. */
35 | public Handler getHandler() {
36 | return handler;
37 | }
38 |
39 | /** Report a diagnostic detected in this phase. */
40 | public void report(Diagnostic d) {
41 | if (handler != null) {
42 | handler.report(d);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/compiler/Warning.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package compiler;
20 |
21 | /** Represents a warning diagnostic. */
22 | public class Warning extends Diagnostic {
23 |
24 | /** Default constructor. */
25 | public Warning(Position pos, String text) {
26 | super(pos, text);
27 | }
28 |
29 | /** Construct a warning with no associated position. */
30 | public Warning(String text) {
31 | super(text);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/core/AtomImpId.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class AtomImpId extends ExtImpId {
25 |
26 | private Atom a;
27 |
28 | /** Default constructor. */
29 | AtomImpId(Position pos, String id, Atom a) {
30 | super(pos, id);
31 | this.a = a;
32 | }
33 |
34 | /** Calculate a MIL External object corresponding to this ExtImpId. */
35 | External toExternal(Prefix prefix, CoreProgram prog, Scheme declared) throws Failure {
36 | return new External(pos, id, declared, new AtomImp(a));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/core/BitSizeNotDeterminedFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class BitSizeNotDeterminedFailure extends Failure {
25 |
26 | public BitSizeNotDeterminedFailure(Position pos, BitdataType bt) {
27 | super(pos, "Unable to determine a unique BitSize value for " + bt);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/BitdataFieldExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import lc.TopBindings;
23 | import mil.*;
24 |
25 | public class BitdataFieldExp extends Name {
26 |
27 | /** Default constructor. */
28 | public BitdataFieldExp(Position pos, String id) {
29 | super(pos, id);
30 | }
31 |
32 | public BitdataField makeField(Type type, int offset, int width) {
33 | return new BitdataField(pos, id, type, offset, width);
34 | }
35 |
36 | public TopBindings coreBindings(TopBindings tbs) {
37 | return tbs;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/core/ByteSizeNotDeterminedFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class ByteSizeNotDeterminedFailure extends Failure {
25 |
26 | public ByteSizeNotDeterminedFailure(Position pos, StructType st) {
27 | super(pos, "Unable to determine a unique ByteSize value for " + st);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/CfunConfusionFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class CfunConfusionFailure extends Failure {
25 |
26 | public CfunConfusionFailure(BitdataConDefn cf, BitdataConDefn df, obdd.Pat conf) {
27 | super(
28 | cf.getPos(),
29 | "Constructors " + cf.getId() + " and " + df.getId() + " both match " + conf.showBits()[0]);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/core/CoreDefnSCCs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class CoreDefnSCCs {
28 |
29 | public CoreDefnSCC head;
30 |
31 | public CoreDefnSCCs next;
32 |
33 | /** Default constructor. */
34 | public CoreDefnSCCs(CoreDefnSCC head, CoreDefnSCCs next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/core/ExtImpId.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class ExtImpId extends Name {
25 |
26 | /** Default constructor. */
27 | ExtImpId(Position pos, String id) {
28 | super(pos, id);
29 | }
30 |
31 | /** Check that all of the type arguments used in this external id, if any, are well-scoped. */
32 | void scopeExtImpId(TyvarEnv params, TyconEnv env) throws Failure {
33 | /* nothing to do */
34 | }
35 |
36 | /** Calculate a MIL External object corresponding to this ExtImpId. */
37 | External toExternal(Prefix prefix, CoreProgram prog, Scheme declared) throws Failure {
38 | return new External(pos, id, declared);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/core/FieldSizeNotDeterminedFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class FieldSizeNotDeterminedFailure extends Failure {
25 |
26 | public FieldSizeNotDeterminedFailure(Position pos, Type type) {
27 | super(pos, "Unable to determine a ByteSize for a field of type " + type);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/InvalidWidthFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class InvalidWidthFailure extends Failure {
25 |
26 | public InvalidWidthFailure(Position pos, BitdataType bt, java.math.BigInteger size) {
27 | super(
28 | pos,
29 | "BitSize(" + bt + ") = " + size + " is outside valid range 0 to " + Type.MAX_BIT_WIDTH);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/core/KFunExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public class KFunExp extends KindExp {
25 |
26 | private KindExp dom;
27 |
28 | private KindExp rng;
29 |
30 | /** Default constructor. */
31 | public KFunExp(KindExp dom, KindExp rng) {
32 | this.dom = dom;
33 | this.rng = rng;
34 | }
35 |
36 | public Kind toKind() throws Failure {
37 | return new KFun(dom.toKind(), rng.toKind());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/core/KPrimExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public class KPrimExp extends PosKindExp {
25 |
26 | String id;
27 |
28 | /** Default constructor. */
29 | public KPrimExp(Position pos, String id) {
30 | super(pos);
31 | this.id = id;
32 | }
33 |
34 | public Kind toKind() throws Failure {
35 | Kind k = KAtom.byName(id);
36 | if (k == null) {
37 | throw new KindSyntaxFailure(pos, id);
38 | }
39 | return k;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/core/KindExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public abstract class KindExp {
25 |
26 | public abstract Kind toKind() throws Failure;
27 | }
28 |
--------------------------------------------------------------------------------
/src/core/KindMismatchFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public class KindMismatchFailure extends Failure {
25 |
26 | public KindMismatchFailure(TypeExp t, Kind kind1, Kind kind2) {
27 | super(t.position(), "Cannot unify kinds \"" + kind1 + "\" and \"" + kind2 + "\"");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/KindSyntaxFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class KindSyntaxFailure extends Failure {
25 |
26 | public KindSyntaxFailure(Position pos, String id) {
27 | super(pos, "Unknown kind \"" + id + "\"");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/LiteralOutOfRangeFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class LiteralOutOfRangeFailure extends Failure {
25 |
26 | public LiteralOutOfRangeFailure(Position pos, java.math.BigInteger nat, Type t) {
27 | super(pos, "Literal " + nat + " cannot be represented as a value of type " + t.skeleton());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/MissingFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class MissingFailure extends Failure {
25 |
26 | public MissingFailure(Position pos, String what, String unexpected) {
27 | super(pos, "Missing " + what + " (unexpected " + unexpected + ")");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/MissingKindExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public class MissingKindExp extends PosKindExp {
25 |
26 | /** Default constructor. */
27 | public MissingKindExp(Position pos) {
28 | super(pos);
29 | }
30 |
31 | public Kind toKind() throws Failure {
32 | return KAtom.STAR;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/core/MultipleKindsSpecifiedFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class MultipleKindsSpecifiedFailure extends Failure {
25 |
26 | public MultipleKindsSpecifiedFailure(TypeExp t, Kind kind1, Kind kind2) {
27 | super(
28 | t.position(),
29 | "Multiple kinds ("
30 | + kind1
31 | + " and "
32 | + kind2
33 | + ") have been specified for this type parameter");
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/core/NatDivOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import java.math.BigInteger;
23 | import mil.*;
24 |
25 | class NatDivOp extends NatArithOp {
26 |
27 | public String toString() {
28 | return "/";
29 | }
30 |
31 | public BigInteger op(BigInteger m, BigInteger n) throws ArithmeticException {
32 | BigInteger[] qr = m.divideAndRemainder(n);
33 | if (qr[1].signum() != 0) {
34 | throw new ArithmeticException("Result of division leaves a remainder");
35 | }
36 | return qr[0];
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/core/NatLshlOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import java.math.BigInteger;
23 | import mil.*;
24 |
25 | class NatLshlOp extends NatArithOp {
26 |
27 | public String toString() {
28 | return "<<";
29 | }
30 |
31 | public BigInteger op(BigInteger m, BigInteger n) throws ArithmeticException {
32 | return m.shiftLeft(n.intValueExact());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/core/NatMinusOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import java.math.BigInteger;
23 | import mil.*;
24 |
25 | class NatMinusOp extends NatArithOp {
26 |
27 | public String toString() {
28 | return "-";
29 | }
30 |
31 | public BigInteger op(BigInteger m, BigInteger n) throws ArithmeticException {
32 | BigInteger r = m.subtract(n);
33 | if (r.compareTo(BigInteger.ZERO) < 0) {
34 | throw new ArithmeticException("Result of subtraction is negative");
35 | }
36 | return r;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/core/NatMultOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import java.math.BigInteger;
23 | import mil.*;
24 |
25 | class NatMultOp extends NatArithOp {
26 |
27 | public String toString() {
28 | return "*";
29 | }
30 |
31 | public BigInteger op(BigInteger m, BigInteger n) throws ArithmeticException {
32 | return m.multiply(n);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/core/NatPlusOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import java.math.BigInteger;
23 | import mil.*;
24 |
25 | class NatPlusOp extends NatArithOp {
26 |
27 | public String toString() {
28 | return "+";
29 | }
30 |
31 | public BigInteger op(BigInteger m, BigInteger n) throws ArithmeticException {
32 | return m.add(n);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/core/NatPowOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import java.math.BigInteger;
23 | import mil.*;
24 |
25 | class NatPowOp extends NatArithOp {
26 |
27 | public String toString() {
28 | return "^";
29 | }
30 |
31 | public BigInteger op(BigInteger m, BigInteger n) throws ArithmeticException {
32 | return m.pow(n.intValueExact());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/core/NatShrOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import java.math.BigInteger;
23 | import mil.*;
24 |
25 | class NatShrOp extends NatArithOp {
26 |
27 | public String toString() {
28 | return ">>";
29 | }
30 |
31 | public BigInteger op(BigInteger m, BigInteger n) throws ArithmeticException {
32 | return m.shiftRight(n.intValueExact());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/core/NoBitLevelRepresentationFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class NoBitLevelRepresentationFailure extends Failure {
25 |
26 | public NoBitLevelRepresentationFailure(Position pos, Type type) {
27 | super(pos, "Cannot determine bit level representation for values of type " + type);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/NoByteLevelRepresentationFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class NoByteLevelRepresentationFailure extends Failure {
25 |
26 | public NoByteLevelRepresentationFailure(Position pos, Type type) {
27 | super(pos, "Cannot determine byte level representation for values of type " + type);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/NotInScopeTyconFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class NotInScopeTyconFailure extends Failure {
25 |
26 | NotInScopeTyconFailure(Position pos, String id) {
27 | super(pos, "The type constructor \"" + id + "\" is not in scope");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/NotInScopeTyvarFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class NotInScopeTyvarFailure extends Failure {
25 |
26 | NotInScopeTyvarFailure(Position pos, String id) {
27 | super(pos, "The type variable \"" + id + "\" is not in scope");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/PosKindExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public abstract class PosKindExp extends KindExp {
25 |
26 | protected Position pos;
27 |
28 | /** Default constructor. */
29 | public PosKindExp(Position pos) {
30 | this.pos = pos;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/core/PosTypeExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public abstract class PosTypeExp extends TypeExp {
25 |
26 | protected Position pos;
27 |
28 | /** Default constructor. */
29 | public PosTypeExp(Position pos) {
30 | this.pos = pos;
31 | }
32 |
33 | /** Find a position for this type expression. */
34 | public Position position() {
35 | return pos;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/core/ProgramTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public class ProgramTest {
25 |
26 | public static void main(String[] args) {
27 | debug.Log.on();
28 | Handler handler = new SimpleHandler();
29 | try {
30 | Source source = new StdinSource(handler);
31 | CoreProgram program = new SyntaxAnalysis(handler).analyze(source);
32 | TyconEnv env = new StaticAnalysis(handler).analyze(program);
33 | System.out.println("done!");
34 | } catch (Failure f) {
35 | handler.report(f);
36 | } catch (Exception e) {
37 | handler.report(new Failure("Exception: " + e));
38 | // e.printStackTrace();
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/core/StaticAnalysis.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public class StaticAnalysis extends Phase {
25 |
26 | /** Default constructor. */
27 | public StaticAnalysis(Handler handler) {
28 | super(handler);
29 | }
30 |
31 | /** Run static analysis on the specified core program, returning the resulting environment. */
32 | public TyconEnv analyze(CoreProgram program) throws Failure {
33 | // TODO: do we really need this method/class?
34 | return program.typeEnv(handler, TyconEnv.builtin);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/core/StructFieldExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import lc.TopBindings;
23 | import mil.*;
24 |
25 | public class StructFieldExp extends Name {
26 |
27 | /** Default constructor. */
28 | public StructFieldExp(Position pos, String id) {
29 | super(pos, id);
30 | }
31 |
32 | public StructField makeField(Type type, int offset, int width) {
33 | return new StructField(pos, id, type, offset, width);
34 | }
35 |
36 | public TopBindings coreBindings(TopBindings tbs) {
37 | return tbs;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/core/TooManyTyconArgsFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class TooManyTyconArgsFailure extends Failure {
25 |
26 | public TooManyTyconArgsFailure(Position pos, Tycon name, int arity) {
27 | super(
28 | pos,
29 | "\""
30 | + name.getId()
31 | + "\" has "
32 | + arity
33 | + " arguments but cannot take more than "
34 | + name.getArity()
35 | + " arguments");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/core/TopImpId.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class TopImpId extends ExtImpId {
25 |
26 | private Position impPos;
27 |
28 | private String impId;
29 |
30 | /** Default constructor. */
31 | TopImpId(Position pos, String id, Position impPos, String impId) {
32 | super(pos, id);
33 | this.impPos = impPos;
34 | this.impId = impId;
35 | }
36 |
37 | /** Calculate a MIL External object corresponding to this ExtImpId. */
38 | External toExternal(Prefix prefix, CoreProgram prog, Scheme declared) throws Failure {
39 | External e = new External(pos, id, declared, null);
40 | prog.addTopImpFixup(impPos, e, impId);
41 | return e;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/core/TyconDefn.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | public abstract class TyconDefn extends CoreDefn {
25 |
26 | protected String id;
27 |
28 | /** Default constructor. */
29 | public TyconDefn(Position pos, String id) {
30 | super(pos);
31 | this.id = id;
32 | }
33 |
34 | public boolean answersTo(String id) {
35 | return id.equals(this.id);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/core/TypeParamSyntaxFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class TypeParamSyntaxFailure extends Failure {
25 |
26 | public TypeParamSyntaxFailure(TypeExp t) {
27 | super(t.position(), "Syntax error in type parameter");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/TypeSyntaxFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class TypeSyntaxFailure extends Failure {
25 |
26 | public TypeSyntaxFailure(TypeExp t) {
27 | super(t.position(), "Syntax error in type expression");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/core/UndeterminedBitPatternFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package core;
20 |
21 | import compiler.*;
22 | import mil.*;
23 |
24 | class UndeterminedBitPatternFailure extends Failure {
25 |
26 | public UndeterminedBitPatternFailure(Position pos, Type type) {
27 | super(pos, "Bit level representation for values of type " + type + " is undetermined");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/debug/Internal.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package debug;
20 |
21 | /** This class provides a mechanism for reporting internal errors. */
22 | public class Internal {
23 |
24 | public static void error(String msg) {
25 | System.out.println("INTERNAL ERROR: " + msg);
26 | new Exception().printStackTrace(System.out);
27 | System.exit(1);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/lc/AtomCont.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /**
26 | * Represents a continuation that takes an atom containing the result of a previous calculation and
27 | * returns a code sequence that uses that atom to complete a computation.
28 | */
29 | abstract class AtomCont {
30 |
31 | /** Invoke this AtomCont with the given Atom to be embedded in a complete code sequence. */
32 | abstract Code with(final Atom v);
33 | }
34 |
--------------------------------------------------------------------------------
/src/lc/BindingsEnv.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /** An environment that extends the enclosing environment with entries from a list of Bindings. */
26 | class BindingsEnv extends Env {
27 |
28 | private Bindings bindings;
29 |
30 | /** Default constructor. */
31 | BindingsEnv(Env enclosing, Bindings bindings) {
32 | super(enclosing);
33 | this.bindings = bindings;
34 | }
35 |
36 | /** Lookup the definition for an identifier in this environment node. */
37 | DefVar findInThis(String id) {
38 | return Bindings.find(id, bindings);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/lc/BitdataRequiredFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class BitdataRequiredFailure extends Failure {
26 |
27 | BitdataRequiredFailure(Position pos, Cfun cf) {
28 | super(pos, cf.getId() + " is not a bitdata constructor");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/lc/CGEnvVar.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class CGEnvVar extends CGEnv {
26 |
27 | private DefVar v;
28 |
29 | private Temp t;
30 |
31 | /** Default constructor. */
32 | CGEnvVar(CGEnv enclosing, DefVar v, Temp t) {
33 | super(enclosing);
34 | this.v = v;
35 | this.t = t;
36 | }
37 |
38 | /**
39 | * Search for an entry for the given DefVar in this CGEnv node (ignoring the enclosing
40 | * environment, if any).
41 | */
42 | Temp findInThis(DefVar v) {
43 | return (this.v == v) ? this.t : null;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/lc/CGEnvVars.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class CGEnvVars extends CGEnv {
26 |
27 | private DefVar[] vs;
28 |
29 | private Temp[] ts;
30 |
31 | /** Default constructor. */
32 | CGEnvVars(CGEnv enclosing, DefVar[] vs, Temp[] ts) {
33 | super(enclosing);
34 | this.vs = vs;
35 | this.ts = ts;
36 | }
37 |
38 | /**
39 | * Search for an entry for the given DefVar in this CGEnv node (ignoring the enclosing
40 | * environment, if any).
41 | */
42 | Temp findInThis(DefVar v) {
43 | for (int i = 0; i < vs.length; i++) {
44 | if (vs[i] == v) {
45 | return ts[i];
46 | }
47 | }
48 | return null;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/lc/ConstructorArgsFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class ConstructorArgsFailure extends Failure {
26 |
27 | ConstructorArgsFailure(Position pos, Cfun cf) {
28 | super(pos, "Constructor " + cf.getId() + " requires " + cf.getArity() + " arguments");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/lc/Entrypoint.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class Entrypoint extends VisDecl {
26 |
27 | /** Default constructor. */
28 | Entrypoint(Position pos, String[] ids) {
29 | super(pos, ids);
30 | }
31 |
32 | void addExports(MILProgram mil, MILEnv milenv) {
33 | for (int i = 0; i < tops.length; i++) {
34 | mil.addEntry(tops[i].getDefn());
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/lc/EqField.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class EqField extends EField {
26 |
27 | /** Default constructor. */
28 | EqField(Position pos, String id, Expr e) {
29 | super(pos, id, e);
30 | }
31 |
32 | int checkTypeStructInit(TVarsInScope tis, StructType st, StructField[] sfields) throws Failure {
33 | throw new Failure(pos, "Error in structure initializer syntax for field \"" + id + "\"");
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/lc/Export.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class Export extends VisDecl {
26 |
27 | /** Default constructor. */
28 | Export(Position pos, String[] ids) {
29 | super(pos, ids);
30 | }
31 |
32 | void addExports(MILProgram mil, MILEnv milenv) {
33 | for (int i = 0; i < tops.length; i++) {
34 | milenv.addTop(tops[i]);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/lc/FreshVar.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /** Represents a fresh variable (not named in the LC source). */
26 | class FreshVar extends DefVar {
27 |
28 | private static int count = 0;
29 |
30 | private String id;
31 |
32 | FreshVar() {
33 | this.id = "t" + count++;
34 | }
35 |
36 | /** Find an identifier associated with this variable. */
37 | String getId() {
38 | return id;
39 | }
40 |
41 | /** Determine whether this variable can be referenced by the specified identifier. */
42 | boolean answersTo(String id) {
43 | return false;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/lc/FromField.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class FromField extends EField {
26 |
27 | /** Default constructor. */
28 | FromField(Position pos, String id, Expr e) {
29 | super(pos, id, e);
30 | }
31 |
32 | int checkTypeConstruct(TVarsInScope tis, Cfun cf, BitdataField[] lfields) throws Failure {
33 | throw new Failure(pos, "Error in bitdata syntax for field \"" + id + "\"");
34 | }
35 |
36 | BitdataField checkTypeUpdate(TVarsInScope tis, Type et, BitdataField[] lfields) throws Failure {
37 | throw new Failure(pos, "Error in bitdata syntax for field \"" + id + "\"");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/lc/InvalidRecursiveDefinition.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class InvalidRecursiveDefinition extends Failure {
26 |
27 | InvalidRecursiveDefinition(Position pos, String id) {
28 | super(pos, "Recursive definition of " + id + " is not valid");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/lc/LCBlock.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | public class LCBlock extends Block {
26 |
27 | private Type result;
28 |
29 | public LCBlock(Position pos, Type result, Code code) {
30 | super(pos, (Temp[]) null, code);
31 | this.result = result;
32 | }
33 |
34 | public Temp[] addArgs() throws Failure {
35 | if (params == null) { // compute formal params and type on first visit
36 | params = Temps.toArray(code.addArgs());
37 | BlockType bt = new BlockType(Type.tuple(Temp.types(params)), Type.tuple(result));
38 | declared = bt.generalize();
39 | }
40 | return params;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/lc/LCClosureDefn.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class LCClosureDefn extends ClosureDefn {
26 |
27 | private Type result;
28 |
29 | LCClosureDefn(Position pos, Type result, Temp[] args, Tail tail) {
30 | super(pos, (Temp[]) null, args, tail);
31 | this.result = result;
32 | }
33 |
34 | public Temp[] addArgs() throws Failure {
35 | if (params == null) { // compute stored params on first visit
36 | params = Temps.toArray(Temps.remove(args, tail.addArgs(null)));
37 | AllocType at = new AllocType(Temp.types(params), result);
38 | declared = at.generalize();
39 | }
40 | return params;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/lc/LCProgramSCCs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /**
26 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
27 | */
28 | public class LCProgramSCCs {
29 |
30 | public LCProgramSCC head;
31 |
32 | public LCProgramSCCs next;
33 |
34 | /** Default constructor. */
35 | public LCProgramSCCs(LCProgramSCC head, LCProgramSCCs next) {
36 | this.head = head;
37 | this.next = next;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/lc/LCTokens.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | interface LCTokens extends CoreTokens {
26 |
27 | int DO = 51;
28 |
29 | int LAMBDA = 52;
30 |
31 | int AMPAMP = 53;
32 |
33 | int BARBAR = 54;
34 |
35 | int WHERE = 55;
36 | }
37 |
--------------------------------------------------------------------------------
/src/lc/MultipleBindingDefnsFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class MultipleBindingDefnsFailure extends Failure {
26 |
27 | MultipleBindingDefnsFailure(Bindings bs) {
28 | // TODO: do a better job with all of the names in the given list ...
29 | super(bs.head.getPos(), "Multiple definitions for \"" + bs.head.getId() + "\"");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/lc/MultipleSignaturesFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class MultipleSignaturesFailure extends Failure {
26 |
27 | MultipleSignaturesFailure(Position pos, String id) {
28 | super(pos, "Multiple type signature declarations for \"" + id + "\"");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/lc/NotInScopeFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class NotInScopeFailure extends Failure {
26 |
27 | NotInScopeFailure(Position pos, String id) {
28 | super(pos, "\"" + id + "\" is not in scope");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/lc/ParseFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class ParseFailure extends Failure {
26 |
27 | /** Default constructor. */
28 | ParseFailure(Position pos, String msg) {
29 | super(pos, msg);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/lc/PosExpr.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | abstract class PosExpr extends Expr {
26 |
27 | protected Position pos;
28 |
29 | /** Default constructor. */
30 | PosExpr(Position pos) {
31 | this.pos = pos;
32 | }
33 |
34 | /** Return a source code position for this expression. */
35 | Position getPos() {
36 | return pos;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/lc/PunField.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class PunField extends EField {
26 |
27 | /** Default constructor. */
28 | PunField(Position pos, String id, Expr e) {
29 | super(pos, id, e);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/lc/SignatureWithoutBindingFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class SignatureWithoutBindingFailure extends Failure {
26 |
27 | SignatureWithoutBindingFailure(Position pos, String id) {
28 | super(pos, "Type signature for \"" + id + "\" does not have a corresponding binding");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/lc/TailCont.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /**
26 | * Represents a continuation that takes a Tail that will produce the final result of a previous
27 | * calculation and returns a code sequence that uses the Tail to complete a computation.
28 | */
29 | abstract class TailCont {
30 |
31 | /** Invoke this TailCont with the given Tail to be embedded in a complete code sequence. */
32 | abstract Code with(final Tail t);
33 |
34 | /** A TailCont that wraps the incoming Tail in a simple Done. */
35 | static final TailCont done =
36 | new TailCont() {
37 | Code with(final Tail t) {
38 | return new Done(t);
39 | }
40 | };
41 | }
42 |
--------------------------------------------------------------------------------
/src/lc/TopBindings.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /**
26 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
27 | */
28 | public class TopBindings {
29 |
30 | public TopBinding head;
31 |
32 | public TopBindings next;
33 |
34 | /** Default constructor. */
35 | public TopBindings(TopBinding head, TopBindings next) {
36 | this.head = head;
37 | this.next = next;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/lc/TopDefns.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /**
26 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
27 | */
28 | public class TopDefns {
29 |
30 | public TopDefn head;
31 |
32 | public TopDefns next;
33 |
34 | /** Default constructor. */
35 | public TopDefns(TopDefn head, TopDefns next) {
36 | this.head = head;
37 | this.next = next;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/lc/UnknownConstructorFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | class UnknownConstructorFailure extends Failure {
26 |
27 | UnknownConstructorFailure(Position pos, String id) {
28 | super(pos, "Unknown constructor function " + id);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/lc/VarEnv.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /** An environment that extends the enclosing environment with a binding for a single identifier. */
26 | class VarEnv extends Env {
27 |
28 | private DefVar v;
29 |
30 | /** Default constructor. */
31 | VarEnv(Env enclosing, DefVar v) {
32 | super(enclosing);
33 | this.v = v;
34 | }
35 |
36 | /** Lookup the definition for an identifier in this environment node. */
37 | DefVar findInThis(String id) {
38 | return v.answersTo(id) ? v : null;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/lc/VarsEnv.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package lc;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import mil.*;
24 |
25 | /**
26 | * An environment that extends the enclosing environment with bindings for an array of identifiers.
27 | */
28 | class VarsEnv extends Env {
29 |
30 | private DefVar[] vs;
31 |
32 | /** Default constructor. */
33 | VarsEnv(Env enclosing, DefVar[] vs) {
34 | super(enclosing);
35 | this.vs = vs;
36 | }
37 |
38 | /** Lookup the definition for an identifier in this environment node. */
39 | DefVar findInThis(String id) {
40 | for (int i = 0; i < vs.length; i++) {
41 | if (vs[i].answersTo(id)) {
42 | return vs[i];
43 | }
44 | }
45 | return null;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/llvm/Bitcast.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Bitcast operators. */
23 | public class Bitcast extends Cast {
24 |
25 | /** Default constructor. */
26 | public Bitcast(Value v, Type ty) {
27 | super(v, ty);
28 | }
29 |
30 | /** Return the LLVM opcode for this cast operation. */
31 | String castString() {
32 | return "bitcast";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/llvm/Defn.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 | import java.io.PrintWriter;
22 |
23 | /** Represents a definition in an LLVM program. */
24 | public abstract class Defn {
25 |
26 | /** Print full text for this definition on the specified PrintWriter. */
27 | abstract void print(PrintWriter out);
28 |
29 | /**
30 | * Return a boolean to indicate whether there should be any output from this definition in an LLVM
31 | * interface description.
32 | */
33 | abstract boolean includeInInterface();
34 |
35 | /**
36 | * Print interface text for this definition on the specified PrintWriter, assuming that
37 | * this.includeInInterface() == true.
38 | */
39 | abstract void printInterface(PrintWriter out);
40 | }
41 |
--------------------------------------------------------------------------------
/src/llvm/Defns.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /**
23 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
24 | */
25 | public class Defns {
26 |
27 | public Defn head;
28 |
29 | public Defns next;
30 |
31 | /** Default constructor. */
32 | public Defns(Defn head, Defns next) {
33 | this.head = head;
34 | this.next = next;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/llvm/Eval.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Evaluate an Expr. */
23 | public class Eval extends Rhs {
24 |
25 | private Expr expr;
26 |
27 | /** Default constructor. */
28 | public Eval(Expr expr) {
29 | this.expr = expr;
30 | }
31 |
32 | /** Append a printable string for this instruction to the specified buffer. */
33 | public void append(StringBuilder buf) {
34 | expr.appendEval(buf);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/llvm/Expr.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Used to represent constant expressions/operations that can be executed using Eval. */
23 | public abstract class Expr extends Value {
24 |
25 | /** Generate a string for executing this expression as a right hand side. */
26 | abstract void appendEval(StringBuilder buf);
27 | }
28 |
--------------------------------------------------------------------------------
/src/llvm/Global.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /**
23 | * Represents a reference to a global variable. Note that this is actually a pointer to the global
24 | * variable, so if the variable itself has type T, then this variable will have type T*.
25 | */
26 | public class Global extends Location {
27 |
28 | /** The name of this global variable. */
29 | private String name;
30 |
31 | /** Default constructor. */
32 | public Global(Type ty, String name) {
33 | super(ty);
34 | this.name = name;
35 | }
36 |
37 | /** Append the name for this value to the specified buffer. */
38 | public void appendName(StringBuilder buf) {
39 | buf.append("@");
40 | buf.append(name);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/llvm/Goto.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 | import java.io.PrintWriter;
22 |
23 | /** Branch to the start of another basic block, ending the current block. */
24 | public class Goto extends Code {
25 |
26 | /** The the label of the block that we should branch to. */
27 | private String b;
28 |
29 | /** Default constructor. */
30 | public Goto(String b) {
31 | this.b = b;
32 | }
33 |
34 | /** Print out this code sequence to the specified PrintWriter. */
35 | public void print(PrintWriter out) {
36 | out.println(" br label %" + b);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/llvm/IOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /**
23 | * Integer binary operations return an integer result by combining two arguments of the same
24 | * (integer) type.
25 | */
26 | public class IOp extends BinOp {
27 |
28 | private String opcode;
29 |
30 | /** Default constructor. */
31 | public IOp(Type ty, Value l, Value r, String opcode) {
32 | super(ty, l, r);
33 | this.opcode = opcode;
34 | }
35 |
36 | /** Return the LLVM opcode for this binary operation. */
37 | public String binOpString() {
38 | return opcode;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/llvm/Index.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Represents an index into a structure as required for getelementptr. */
23 | public class Index extends Value {
24 |
25 | /** The numeric value of the index. */
26 | private int num;
27 |
28 | /** Default constructor. */
29 | public Index(int num) {
30 | this.num = num;
31 | }
32 |
33 | /** The index constant with all bits zero. */
34 | public static final Index ZERO = new Index(0);
35 |
36 | /** Return the LLVM type of this value. */
37 | public Type getType() {
38 | return Type.i32;
39 | }
40 |
41 | /** Append the name for this value to the specified buffer. */
42 | public void appendName(StringBuilder buf) {
43 | buf.append(num);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/llvm/IntToPtr.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Integer to pointer casts. */
23 | public class IntToPtr extends Cast {
24 |
25 | /** Default constructor. */
26 | public IntToPtr(Value v, Type ty) {
27 | super(v, ty);
28 | }
29 |
30 | /** Return the LLVM opcode for this cast operation. */
31 | String castString() {
32 | return "inttoptr";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/llvm/Load.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Load a value from memory. */
23 | public class Load extends Rhs {
24 |
25 | /** A location from which a value will be loaded. */
26 | private Value v;
27 |
28 | /** Default constructor. */
29 | public Load(Value v) {
30 | this.v = v;
31 | }
32 |
33 | /** Append a printable string for this instruction to the specified buffer. */
34 | public void append(StringBuilder buf) {
35 | buf.append("load ");
36 | v.getType().ptsTo().append(buf);
37 | buf.append(", ");
38 | v.append(buf);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/llvm/Location.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Represents an LLVM value that specifies a location in memory or in a register/temporary. */
23 | public abstract class Location extends Value {
24 |
25 | /** The type of value stored in this location. */
26 | protected Type ty;
27 |
28 | /** Default constructor. */
29 | public Location(Type ty) {
30 | this.ty = ty;
31 | }
32 |
33 | /** Return the LLVM type of this value. */
34 | public Type getType() {
35 | return ty;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/llvm/PtrToInt.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Pointer to integer casts. */
23 | public class PtrToInt extends Cast {
24 |
25 | /** Default constructor. */
26 | public PtrToInt(Value v, Type ty) {
27 | super(v, ty);
28 | }
29 |
30 | /** Return the LLVM opcode for this cast operation. */
31 | String castString() {
32 | return "ptrtoint";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/llvm/Ret.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 | import java.io.PrintWriter;
22 |
23 | /**
24 | * Return from the current function with a specified return value, ending the current basic block.
25 | */
26 | public class Ret extends Code {
27 |
28 | /** The value to be returned. */
29 | private Value v;
30 |
31 | /** Default constructor. */
32 | public Ret(Value v) {
33 | this.v = v;
34 | }
35 |
36 | /** Print out this code sequence to the specified PrintWriter. */
37 | public void print(PrintWriter out) {
38 | out.println(" ret " + v);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/llvm/RetVoid.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 | import java.io.PrintWriter;
22 |
23 | /** Return from the current function without a return value, ending the current basic block. */
24 | public class RetVoid extends Code {
25 |
26 | /** Print out this code sequence to the specified PrintWriter. */
27 | public void print(PrintWriter out) {
28 | out.println(" ret void");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/llvm/Rhs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** A base class for representing right hand sides of LLVM operations, lhs = rhs. */
23 | public abstract class Rhs {
24 |
25 | /** Append a printable string for this instruction to the specified buffer. */
26 | public String toString() {
27 | StringBuilder buf = new StringBuilder();
28 | append(buf);
29 | return buf.toString();
30 | }
31 |
32 | /** Append a printable string for this instruction to the specified buffer. */
33 | public abstract void append(StringBuilder buf);
34 | }
35 |
--------------------------------------------------------------------------------
/src/llvm/Trunc.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Truncate operators. */
23 | public class Trunc extends Cast {
24 |
25 | /** Default constructor. */
26 | public Trunc(Value v, Type ty) {
27 | super(v, ty);
28 | }
29 |
30 | /** Return the LLVM opcode for this cast operation. */
31 | String castString() {
32 | return "trunc";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/llvm/ZeroInitializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Represents a zero initializer for an array. */
23 | public class ZeroInitializer extends Value {
24 |
25 | /** The associated array type. */
26 | private ArrayType arrayType;
27 |
28 | /** Default constructor. */
29 | public ZeroInitializer(ArrayType arrayType) {
30 | this.arrayType = arrayType;
31 | }
32 |
33 | /** Return the LLVM type of this value. */
34 | public Type getType() {
35 | return arrayType;
36 | }
37 |
38 | /** Append the name for this value to the specified buffer. */
39 | public void appendName(StringBuilder buf) {
40 | buf.append("zeroinitializer");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/llvm/Zext.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package llvm;
20 |
21 |
22 | /** Zero extension to a larger bitsize. */
23 | public class Zext extends Cast {
24 |
25 | /** Default constructor. */
26 | public Zext(Value v, Type ty) {
27 | super(v, ty);
28 | }
29 |
30 | /** Return the LLVM opcode for this cast operation. */
31 | String castString() {
32 | return "zext";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/mil/AddrMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import java.io.PrintWriter;
24 |
25 | /**
26 | * An AddrMap provides a way to generate printable text for the global and code labels in a bytecode
27 | * program. This base class provides a simple default implementation.
28 | */
29 | public class AddrMap {
30 |
31 | String globalLabel(int addr) {
32 | return "g" + addr;
33 | }
34 |
35 | String codeLabel(int addr) {
36 | return Integer.toString(addr);
37 | }
38 |
39 | void dump(PrintWriter out) {
40 | /* do nothing */
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/mil/Annotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | abstract class Annotation extends DefnExp {
25 |
26 | protected String[] ids;
27 |
28 | /** Default constructor. */
29 | Annotation(Position pos, String[] ids) {
30 | super(pos);
31 | this.ids = ids;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/mil/BlockCalls.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class BlockCalls {
28 |
29 | public BlockCall head;
30 |
31 | public BlockCalls next;
32 |
33 | /** Default constructor. */
34 | public BlockCalls(BlockCall head, BlockCalls next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/BlockWithCont.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * Represents a block that was derived by adding a trailing invocation of a new continuation
26 | * argument to its code sequence.
27 | */
28 | class BlockWithCont extends DerivedBlock {
29 |
30 | /** Default constructor. */
31 | BlockWithCont(Position pos, Temp[] params, Code code) {
32 | super(pos, params, code);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/mil/BlockWithEnter.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /** Represents a block that was derived by adding a trailing enter to its code sequence. */
25 | class BlockWithEnter extends DerivedBlock {
26 |
27 | /** Default constructor. */
28 | BlockWithEnter(Position pos, Temp[] params, Code code) {
29 | super(pos, params, code);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/mil/BlockWithKnownCons.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class BlockWithKnownCons extends DerivedBlock {
25 |
26 | private Call[] calls;
27 |
28 | /** Default constructor. */
29 | BlockWithKnownCons(Position pos, Temp[] params, Code code, Call[] calls) {
30 | super(pos, params, code);
31 | this.calls = calls;
32 | }
33 |
34 | boolean hasKnownCons(Call[] calls) {
35 | return Call.sameCallForms(calls, this.calls);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/mil/BoolValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class BoolValue extends Value {
25 |
26 | private boolean bool;
27 |
28 | /** Default constructor. */
29 | BoolValue(boolean bool) {
30 | this.bool = bool;
31 | }
32 |
33 | public static BoolValue make(boolean b) {
34 | return b ? True : False;
35 | }
36 |
37 | public String toString() {
38 | return bool ? "true" : "false";
39 | }
40 |
41 | boolean getBool() throws Failure {
42 | return bool;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/mil/CannotSatisfyFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class CannotSatisfyFailure extends Failure {
25 |
26 | public CannotSatisfyFailure(LinearEqn eqn) {
27 | super(eqn.getPos(), "Cannot satisfy constraint " + eqn);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/mil/ClosAllocs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class ClosAllocs {
28 |
29 | public ClosAlloc head;
30 |
31 | public ClosAllocs next;
32 |
33 | /** Default constructor. */
34 | public ClosAllocs(ClosAlloc head, ClosAllocs next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/ClosureDefnWithKnownCons.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public class ClosureDefnWithKnownCons extends ClosureDefn {
25 |
26 | private Call[] calls;
27 |
28 | /** Default constructor. */
29 | public ClosureDefnWithKnownCons(
30 | Position pos, Temp[] params, Temp[] args, Tail tail, Call[] calls) {
31 | super(pos, params, args, tail);
32 | this.calls = calls;
33 | }
34 |
35 | boolean hasKnownCons(Call[] calls) {
36 | return Call.sameCallForms(calls, this.calls);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/ClosureDefns.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class ClosureDefns {
28 |
29 | public ClosureDefn head;
30 |
31 | public ClosureDefns next;
32 |
33 | /** Default constructor. */
34 | public ClosureDefns(ClosureDefn head, ClosureDefns next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/DataValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class DataValue extends Value {
25 |
26 | private int tag;
27 |
28 | private Value[] fields;
29 |
30 | /** Default constructor. */
31 | DataValue(int tag, Value[] fields) {
32 | this.tag = tag;
33 | this.fields = fields;
34 | }
35 |
36 | public String toString() {
37 | return "tag: " + tag + ", " + fields.length + " fields";
38 | }
39 |
40 | int getTag() throws Failure {
41 | return tag;
42 | }
43 |
44 | Value getComponent(int i) throws Failure {
45 | return fields[i];
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/mil/DebugTypeWriter.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public class DebugTypeWriter extends TypeWriter {
25 |
26 | public void write(String s) {
27 | debug.Log.print(s);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/mil/DefnExps.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class DefnExps {
28 |
29 | public DefnExp head;
30 |
31 | public DefnExps next;
32 |
33 | /** Default constructor. */
34 | public DefnExps(DefnExp head, DefnExps next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/DefnSCCs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class DefnSCCs {
28 |
29 | public DefnSCC head;
30 |
31 | public DefnSCCs next;
32 |
33 | /** Default constructor. */
34 | public DefnSCCs(DefnSCC head, DefnSCCs next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/EnterExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class EnterExp extends TailExp {
25 |
26 | private VarExp fun;
27 |
28 | private AtomExp[] args;
29 |
30 | /** Default constructor. */
31 | EnterExp(VarExp fun, AtomExp[] args) {
32 | this.fun = fun;
33 | this.args = args;
34 | }
35 |
36 | /**
37 | * Perform scope analysis on this TailExp, checking that all of the referenced identifiers are in
38 | * scope and returning a corresponding mil Tail.
39 | */
40 | Tail inScopeOf(Handler handler, MILEnv milenv, TempEnv tenv) {
41 | return new Enter(
42 | fun.inScopeOf(handler, milenv, tenv), AtomExp.inScopeOf(handler, milenv, tenv, args));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/mil/Entrypoint.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class Entrypoint extends Export {
25 |
26 | /** Default constructor. */
27 | Entrypoint(Position pos, String[] ids) {
28 | super(pos, ids);
29 | }
30 |
31 | /** Add items in export lists to the specified MIL environment. */
32 | void addExports(MILEnv exports, MILProgram program) {
33 | super.addExports(exports, program);
34 | for (int i = 0; i < defns.length; i++) {
35 | program.addEntry(defns[i]);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/GeneratorException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /** Captures the reason why a generator failed. */
25 | class GeneratorException extends Exception {
26 |
27 | private String reason;
28 |
29 | /** Default constructor. */
30 | GeneratorException(String reason) {
31 | this.reason = reason;
32 | }
33 |
34 | String getReason() {
35 | return reason;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/mil/KindMismatchException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public class KindMismatchException extends UnifyException {
25 |
26 | Kind k;
27 |
28 | Type t;
29 |
30 | Type[] tenv;
31 |
32 | /** Default constructor. */
33 | public KindMismatchException(Kind k, Type t, Type[] tenv) {
34 | this.k = k;
35 | this.t = t;
36 | this.tenv = tenv;
37 | }
38 |
39 | public String describe() {
40 | return "Type \""
41 | + t.skeleton(tenv)
42 | + "\" has kind \""
43 | + t.calcKind(tenv)
44 | + "\" where a type of kind \""
45 | + k
46 | + "\" is required";
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/mil/Labels.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class Labels {
28 |
29 | public Label head;
30 |
31 | public Labels next;
32 |
33 | /** Default constructor. */
34 | public Labels(Label head, Labels next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 |
39 | /** Return the length of a linked list of elements. */
40 | public static int length(Labels list) {
41 | int len = 0;
42 | for (; list != null; list = list.next) {
43 | len++;
44 | }
45 | return len;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/mil/LitExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class LitExp extends AtomExp {
25 |
26 | private Atom a;
27 |
28 | /** Default constructor. */
29 | LitExp(Atom a) {
30 | this.a = a;
31 | }
32 |
33 | /**
34 | * Perform scope analysis on this AtomExp, checking that any referenced identifier is in scope,
35 | * and returning a corresponding MIL Atom.
36 | */
37 | Atom inScopeOf(Handler handler, MILEnv milenv, TempEnv tenv) {
38 | return a;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/mil/MILASTSCCs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class MILASTSCCs {
28 |
29 | public MILASTSCC head;
30 |
31 | public MILASTSCCs next;
32 |
33 | /** Default constructor. */
34 | public MILASTSCCs(MILASTSCC head, MILASTSCCs next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/MILTokens.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | interface MILTokens extends CoreTokens {
25 |
26 | int PRIMITIVE = 1;
27 |
28 | int APPLY = 2;
29 |
30 | int RETURN = 3;
31 |
32 | int ASSERT = 4;
33 |
34 | int TBIND = 5;
35 |
36 | int MILTO = 6;
37 | }
38 |
--------------------------------------------------------------------------------
/src/mil/MultipleSolutionsFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class MultipleSolutionsFailure extends Failure {
25 |
26 | public MultipleSolutionsFailure(LinearEqn eqn) {
27 | super(eqn.getPos(), "Constraint " + eqn + " does not have a unique solution");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/mil/MultipleTyconDefnsFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class MultipleTyconDefnsFailure extends Failure {
25 |
26 | public MultipleTyconDefnsFailure(Tycons ns) {
27 | // TODO: do a better job with all of the names in the given list ...
28 | super(ns.head.getPos(), "Multiple definitions for \"" + ns.head.getId() + "\"");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/mil/MultipleTyvarDefnsFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class MultipleTyvarDefnsFailure extends Failure {
25 |
26 | public MultipleTyvarDefnsFailure(Tyvars ns) {
27 | // TODO: do a better job with all of the names in the given list ...
28 | super(ns.head.getPos(), "Type parameter \"" + ns.head.getId() + "\" is used multiple times");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/mil/NewtypeTypeSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public class NewtypeTypeSet extends TypeSet {
25 |
26 | /**
27 | * Override the TypeSet method for calculating canonical versions of a type with a Tycon at its
28 | * head. By overriding this method, we are able to check for situations where the head is a
29 | * newtype constructor and, in those cases, replace the type with its expansion instead.
30 | */
31 | protected Type canon(Tycon h, int args) {
32 | Type t = h.translate(this, args); // Look for a translation of this type
33 | return (t == null) ? super.canon(h, args) : t; // Or fall back to the canonical representation
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/mil/OccursCheckException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public class OccursCheckException extends UnifyException {
25 |
26 | TVar v;
27 |
28 | Type t;
29 |
30 | Type[] tenv;
31 |
32 | /** Default constructor. */
33 | public OccursCheckException(TVar v, Type t, Type[] tenv) {
34 | this.v = v;
35 | this.t = t;
36 | this.tenv = tenv;
37 | }
38 |
39 | public String describe() {
40 | return "Occurs check error: Type variable \""
41 | + v
42 | + "\" occurs in \""
43 | + t.skeleton(tenv)
44 | + "\"\n";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/mil/PolymorphicEntrypointFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class PolymorphicEntrypointFailure extends Failure {
25 |
26 | PolymorphicEntrypointFailure(String what, Defn d) {
27 | super(
28 | d.getPos(),
29 | what
30 | + " \""
31 | + d
32 | + "\" has a polymorphic type so it "
33 | + "cannot be used as an entrypoint in a specialized program");
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/mil/PredNodes.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * Captures information about predecessors, including the predecessor node and the list of (non
26 | * unit) arguments from that node. The latter can be used to determine where phi nodes are needed
27 | * (or to determine renamings that are needed for blocks with a single entry).
28 | */
29 | class PredNodes {
30 |
31 | Node head;
32 |
33 | Atom[] args;
34 |
35 | PredNodes next;
36 |
37 | /** Default constructor. */
38 | PredNodes(Node head, Atom[] args, PredNodes next) {
39 | this.head = head;
40 | this.args = args;
41 | this.next = next;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/PrevTyconDefnFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class PrevTyconDefnFailure extends Failure {
25 |
26 | public PrevTyconDefnFailure(Position pos, Tycon newt, Tycon prevt) {
27 | // TODO: Use information about prevt in the error message
28 | super(pos, "Definition of \"" + newt.getId() + "\" conflicts with previous definition");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/mil/PrimCallExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class PrimCallExp extends CallExp {
25 |
26 | /** Default constructor. */
27 | PrimCallExp(Position pos, String id, AtomExp[] as) {
28 | super(pos, id, as);
29 | }
30 |
31 | /**
32 | * Perform scope analysis on the callee in this CallExp, checking to ensure that it has been
33 | * defined elsewhere in the program. The resulting Call object can then be extended with the
34 | * appropriate list of arguments in the implementation of inScopeOf() for CallExp objects.
35 | */
36 | Call calleeInScopeOf(Handler handler, MILEnv milenv) {
37 | return new PrimCall(milenv.mustFindPrim(handler, pos, id));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/mil/PrimCmpOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /** A base class for comparison operators on Words. */
25 | public abstract class PrimCmpOp extends PrimRelOp {
26 |
27 | /** Default constructor. */
28 | public PrimCmpOp(String id, int purity, BlockType blockType) {
29 | super(id, purity, blockType);
30 | }
31 |
32 | /** Return the upper (or lower) bound for this comparison type. */
33 | public abstract long bound(boolean upper);
34 | }
35 |
--------------------------------------------------------------------------------
/src/mil/PrimFtoW.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 | import java.io.PrintWriter;
24 |
25 | /** A base class for primitives that convert a Flag to a Word. */
26 | public abstract class PrimFtoW extends PrimSing {
27 |
28 | /** Default constructor. */
29 | public PrimFtoW(String id, int purity, BlockType blockType) {
30 | super(id, purity, blockType);
31 | }
32 |
33 | abstract long op(boolean b);
34 |
35 | void exec(PrintWriter out, int fp, Value[] stack) throws Failure {
36 | stack[fp] = new WordValue(op(stack[fp].getBool()));
37 | }
38 |
39 | Code fold(boolean n) {
40 | MILProgram.report("constant folding for " + getId());
41 | return PrimCall.done(op(n));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/PrimSCmpOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /** A base class for signed comparison operators on Words. */
25 | public abstract class PrimSCmpOp extends PrimCmpOp {
26 |
27 | /** Default constructor. */
28 | public PrimSCmpOp(String id, int purity, BlockType blockType) {
29 | super(id, purity, blockType);
30 | }
31 |
32 | /** Return the upper (or lower) bound for this comparison type. */
33 | public long bound(boolean upper) {
34 | long max = Word.maxSigned().longValue();
35 | return upper ? max : (-max - 1);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/mil/PrimSing.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public abstract class PrimSing extends Prim {
25 |
26 | /** Default constructor. */
27 | public PrimSing(String id, int purity, BlockType blockType) {
28 | super(id, purity, blockType);
29 | }
30 |
31 | /**
32 | * Test whether this primitive is the same as a given primitive. For PrimSing, this requires a
33 | * class equality; for other primitives, we can use a pointer equality test.
34 | */
35 | public boolean samePrim(Prim p) {
36 | return this.getClass() == p.getClass();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/PrimUCmpOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /** A base class for unsigned comparison operators on Words. */
25 | public abstract class PrimUCmpOp extends PrimCmpOp {
26 |
27 | /** Default constructor. */
28 | public PrimUCmpOp(String id, int purity, BlockType blockType) {
29 | super(id, purity, blockType);
30 | }
31 |
32 | /** Return the upper (or lower) bound for this comparison type. */
33 | public long bound(boolean upper) {
34 | return Word.fromLong(upper ? (~0L) : 0L);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/mil/Prims.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class Prims {
28 |
29 | public Prim head;
30 |
31 | public Prims next;
32 |
33 | /** Default constructor. */
34 | public Prims(Prim head, Prims next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/Proxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /** Represents a proxy/singleton value. */
25 | public abstract class Proxy extends Const {
26 |
27 | /** Find the Value for a given mil constant. */
28 | Value constValue() {
29 | return new WordValue(0);
30 | }
31 |
32 | Atom[] repArg(RepTypeSet set, RepEnv env) {
33 | return Const.unit;
34 | }
35 |
36 | /** Calculate an LLVM Value corresponding to a given MIL argument. */
37 | llvm.Value toLLVMAtom(LLVMMap lm, VarMap vm) {
38 | return new llvm.Word(0);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/mil/ReturnExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class ReturnExp extends TailExp {
25 |
26 | private AtomExp[] as;
27 |
28 | /** Default constructor. */
29 | ReturnExp(AtomExp[] as) {
30 | this.as = as;
31 | }
32 |
33 | /**
34 | * Perform scope analysis on this TailExp, checking that all of the referenced identifiers are in
35 | * scope and returning a corresponding mil Tail.
36 | */
37 | Tail inScopeOf(Handler handler, MILEnv milenv, TempEnv tenv) {
38 | return new Return(AtomExp.inScopeOf(handler, milenv, tenv, as));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/mil/SpecBlock.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class SpecBlock extends SpecReq {
25 |
26 | private Block borig;
27 |
28 | private Block bspec;
29 |
30 | /** Default constructor. */
31 | SpecBlock(Block borig, Block bspec) {
32 | this.borig = borig;
33 | this.bspec = bspec;
34 | }
35 |
36 | /**
37 | * Complete the construction of a specialized version of a definition in the original program as
38 | * specified by a specialization request.
39 | */
40 | void specialize(MILSpec spec) {
41 | bspec.specialize(spec, borig);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/SpecClosureDefn.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class SpecClosureDefn extends SpecReq {
25 |
26 | private ClosureDefn korig;
27 |
28 | private ClosureDefn kspec;
29 |
30 | /** Default constructor. */
31 | SpecClosureDefn(ClosureDefn korig, ClosureDefn kspec) {
32 | this.korig = korig;
33 | this.kspec = kspec;
34 | }
35 |
36 | /**
37 | * Complete the construction of a specialized version of a definition in the original program as
38 | * specified by a specialization request.
39 | */
40 | void specialize(MILSpec spec) {
41 | kspec.specialize(spec, korig);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/SpecExternal.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class SpecExternal extends SpecReq {
25 |
26 | private External eorig;
27 |
28 | private External espec;
29 |
30 | /** Default constructor. */
31 | SpecExternal(External eorig, External espec) {
32 | this.eorig = eorig;
33 | this.espec = espec;
34 | }
35 |
36 | /**
37 | * Complete the construction of a specialized version of a definition in the original program as
38 | * specified by a specialization request.
39 | */
40 | void specialize(MILSpec spec) {
41 | espec.specialize(spec, eorig);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/SpecMemArea.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class SpecMemArea extends SpecReq {
25 |
26 | private MemArea aorig;
27 |
28 | private MemArea aspec;
29 |
30 | /** Default constructor. */
31 | SpecMemArea(MemArea aorig, MemArea aspec) {
32 | this.aorig = aorig;
33 | this.aspec = aspec;
34 | }
35 |
36 | /**
37 | * Complete the construction of a specialized version of a definition in the original program as
38 | * specified by a specialization request.
39 | */
40 | void specialize(MILSpec spec) {
41 | aspec.specialize(spec, aorig);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/SpecReqs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class SpecReqs {
28 |
29 | public SpecReq head;
30 |
31 | public SpecReqs next;
32 |
33 | /** Default constructor. */
34 | public SpecReqs(SpecReq head, SpecReqs next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/SpecTopLevel.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class SpecTopLevel extends SpecReq {
25 |
26 | private TopLevel torig;
27 |
28 | private TopLevel tspec;
29 |
30 | /** Default constructor. */
31 | SpecTopLevel(TopLevel torig, TopLevel tspec) {
32 | this.torig = torig;
33 | this.tspec = tspec;
34 | }
35 |
36 | /**
37 | * Complete the construction of a specialized version of a definition in the original program as
38 | * specified by a specialization request.
39 | */
40 | void specialize(MILSpec spec) {
41 | tspec.specialize(spec, torig);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/StringTypeWriter.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /** A simple class for writing type and scheme values into a String. */
25 | public class StringTypeWriter extends PrefixTypeWriter {
26 |
27 | /** Default constructor. */
28 | public StringTypeWriter(Prefix prefix) {
29 | super(prefix);
30 | }
31 |
32 | StringBuilder buf = new StringBuilder();
33 |
34 | public void write(String s) {
35 | buf.append(s);
36 | }
37 |
38 | public String toString() {
39 | return buf.toString();
40 | }
41 |
42 | public void reset() {
43 | buf.setLength(0);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/mil/TailExp.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | abstract class TailExp {
25 |
26 | /**
27 | * Perform scope analysis on this TailExp, checking that all of the referenced identifiers are in
28 | * scope and returning a corresponding mil Tail.
29 | */
30 | abstract Tail inScopeOf(Handler handler, MILEnv milenv, TempEnv tenv);
31 | }
32 |
--------------------------------------------------------------------------------
/src/mil/Tails.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class Tails {
28 |
29 | public Tail head;
30 |
31 | public Tails next;
32 |
33 | /** Default constructor. */
34 | public Tails(Tail head, Tails next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/TopLevels.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class TopLevels {
28 |
29 | public TopLevel head;
30 |
31 | public TopLevels next;
32 |
33 | /** Default constructor. */
34 | public TopLevels(TopLevel head, TopLevels next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/TypeAnn.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | abstract class TypeAnn extends Annotation {
25 |
26 | /** Default constructor. */
27 | TypeAnn(Position pos, String[] ids) {
28 | super(pos, ids);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/mil/TypeMismatchException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public class TypeMismatchException extends UnifyException {
25 |
26 | Type t1;
27 |
28 | Type[] tenv1;
29 |
30 | Type t2;
31 |
32 | Type[] tenv2;
33 |
34 | /** Default constructor. */
35 | public TypeMismatchException(Type t1, Type[] tenv1, Type t2, Type[] tenv2) {
36 | this.t1 = t1;
37 | this.tenv1 = tenv1;
38 | this.t2 = t2;
39 | this.tenv2 = tenv2;
40 | }
41 |
42 | public String describe() {
43 | return "Type mismatch: cannot unify \""
44 | + t1.skeleton(tenv1)
45 | + "\" with \""
46 | + t2.skeleton(tenv2)
47 | + "\"";
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/mil/TypeSpecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * Represents mappings (implemented as linked lists) that associate individual monomorphic
26 | * instances, inst, of a known parameterized DataType with a corresponding specialized
27 | * (non-parameterized) DataType.
28 | */
29 | class TypeSpecs {
30 |
31 | Type inst;
32 |
33 | DataType dt;
34 |
35 | TypeSpecs next;
36 |
37 | /** Default constructor. */
38 | TypeSpecs(Type inst, DataType dt, TypeSpecs next) {
39 | this.inst = inst;
40 | this.dt = dt;
41 | this.next = next;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/mil/Types.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | /**
25 | * A null-terminated linked list of items that can be accessed using (public) head and next fields.
26 | */
27 | public class Types {
28 |
29 | public Type head;
30 |
31 | public Types next;
32 |
33 | /** Default constructor. */
34 | public Types(Type head, Types next) {
35 | this.head = head;
36 | this.next = next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mil/UnifyException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | public abstract class UnifyException extends Exception {
25 |
26 | public abstract String describe();
27 | }
28 |
--------------------------------------------------------------------------------
/src/mil/Value.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | abstract class Value {
25 |
26 | static final BoolValue True = new BoolValue(true);
27 |
28 | static final BoolValue False = new BoolValue(false);
29 |
30 | public abstract String toString();
31 |
32 | long getInt() throws Failure {
33 | throw new Failure("value is not an integer");
34 | }
35 |
36 | boolean getBool() throws Failure {
37 | throw new Failure("value is not Boolean");
38 | }
39 |
40 | int getTag() throws Failure {
41 | throw new Failure("value is not tagged");
42 | }
43 |
44 | Value getComponent(int i) throws Failure {
45 | throw new Failure("value does not have components");
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/mil/WidthsDifferFailure.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class WidthsDifferFailure extends Failure {
25 |
26 | public WidthsDifferFailure(Position pos, java.math.BigInteger diff) {
27 | super(
28 | pos,
29 | (diff.signum() < 0)
30 | ? ("Sum of component widths is " + diff.negate() + " more than expected total")
31 | : ("Sum of component widths is " + diff + " less than expected total"));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/mil/WordValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018-19 Mark P Jones, Portland State University
3 |
4 | This file is part of mil-tools.
5 |
6 | mil-tools is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | mil-tools is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with mil-tools. If not, see .
18 | */
19 | package mil;
20 |
21 | import compiler.*;
22 | import core.*;
23 |
24 | class WordValue extends Value {
25 |
26 | private long num;
27 |
28 | /** Default constructor. */
29 | WordValue(long num) {
30 | this.num = num;
31 | }
32 |
33 | public String toString() {
34 | return Long.toString(num);
35 | }
36 |
37 | long getInt() throws Failure {
38 | return num;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------